using ll=longlong; using ull=unsignedlonglong; using pii=pair<int,int>; #define begend(x) x.begin(),x.end() #define mem0(x) memset(x,0,sizeof(x)) #define YES puts("YES") #define NO puts("NO")
intread(){ int f=1,x=0;char c=getchar(); while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } constint N = 105; char s[N]; voidsolve(){ int n=read(); scanf("%s",s); char now = s[0]; for(int i=1;i<n;i++){ if(s[i]==now){ putchar(now); now='?'; } elseif(now=='?')now=s[i]; } puts(""); }
intmain(){ int T=read(); while(T--){ solve(); } return0; }
B. Binary Cafe
题意
有 k 个物品,编号为 0∼k−1,编号为 i 的物品价值 2i 元。
你有 n 元,请问由几种购买方案?(包括全部都没有买的方案)
using ll=longlong; using ull=unsignedlonglong; using pii=pair<int,int>; #define begend(x) x.begin(),x.end() #define mem0(x) memset(x,0,sizeof(x)) #define YES puts("YES") #define NO puts("NO") #define LOCAL
intread(){ int f=1,x=0;char c=getchar(); while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } voidsolve(){ int n=read(),k=read(); // 防止溢出 if(k<=30 && n>=pow(2,k)-1) printf("%d\n",(int)pow(2,k)); elseprintf("%d\n",n+1); }
intmain(){ int T=read(); while(T--){ solve(); } return0; }
C. Ski Resort
题意
给定一个序列 a1,a2,a3,…,an,求出每个数都小于等于 q,且长度大于等于 k 的连续区间数。
using ll=longlong; using ull=unsignedlonglong; using pii=pair<int,int>; #define begend(x) x.begin(),x.end() #define mem0(x) memset(x,0,sizeof(x)) #define YES puts("YES") #define NO puts("NO") #define LOCAL
intread(){ int f=1,x=0;char c=getchar(); while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } voidsolve(){ int n=read(),k=read(),q=read();
ll ans = 0; int len = 0; for(int i=1;i<=n;i++){ if(read()<=q)len++; else{ if(len>=k){ int a = 1; int b = len-k+1; ans += (ll)(a+b)*(b)/2; } len=0; } } if(len>=k){ int a = 1; int b = len-k+1; ans += (ll)(a+b)*(b)/2; } printf("%lld\n",ans); }
intmain(){ int T=read(); while(T--){ solve(); } return0; }
using ll=longlong; using ull=unsignedlonglong; using pii=pair<int,int>; #define begend(x) x.begin(),x.end() #define mem0(x) memset(x,0,sizeof(x)) #define YES puts("YES") #define NO puts("NO") #define LOCAL
intread(){ int f=1,x=0;char c=getchar(); while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } constint N=2e5+5; int n; int a[N];
using ll=longlong; using ull=unsignedlonglong; using pii=pair<int,int>; #define begend(x) x.begin(),x.end() #define mem0(x) memset(x,0,sizeof(x)) #define YES puts("YES") #define NO puts("NO") #define LOCAL
intread(){ int f=1,x=0;char c=getchar(); while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; } constint N = 2e5+5;
char s1[N],s2[N];
voidsolve(){ scanf("%s%s",s1,s2);
int cnt = 0; int l = strlen(s1); for(int i=0;i<l;i++){ if(s1[i]!=s2[i])cnt++; }
using ll=longlong; using ull=unsignedlonglong; using pii=pair<int,int>; #define begend(x) x.begin(),x.end() #define mem0(x) memset(x,0,sizeof(x)) #define YES puts("YES") #define NO puts("NO")
intread(){ int f=1,x=0;char c=getchar(); while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; }
constint N=1e5+5; int n,m,r;
structNode{ int x,y; int t; };
structRay{ int t,d,coord; booloperator<(const Ray& rhs)const{ return t<rhs.t; } }ray[105];
using ll=longlong; using ull=unsignedlonglong; using pii=pair<int,int>; #define begend(x) x.begin(),x.end() #define mem0(x) memset(x,0,sizeof(x)) #define YES puts("YES") #define NO puts("NO")
intread(){ int f=1,x=0;char c=getchar(); while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c)){x=x*10+c-'0';c=getchar();} return x*f; }
map<int,int> mp;
voidsolve(){ int x=read(); mp[x]=1; for(int i=2;i<=1000;i++){ puts("+ 1");fflush(stdout); int x=read(); if(mp.count(x)){ printf("! %d\n",i-mp[x]); return; } mp[x]=i; }