用了两场比赛上Div 1感觉自己好腊鸡的说。。。以下是这两场比赛的部分题解(不得不说有个黄学长来抱大腿还是非常爽的)
Round #372 :
Div 2 A:Crazy Computer
题意:给定N个输入和一个时间长度M,每次输入屏幕上增加一个字符,若两个输入间隔大于M则屏幕上的字符会被清空,问结束时屏幕上还有多少个字符
直接模拟没有什么好说的
代码:
1 #include<cstdio>
2 #include<iostream>
3 #include<cstring>
4 #include<algorithm>
5 using namespace std;
6 int main(){
7 int n,c;
8 scanf("%d%d",&n,&c);
9 int last=0,cnt=0;
10 for (int i=1;i<=n;i++) {
11 int x;
12 scanf("%d",&x);
13 if (x-last>c) cnt=0;
14 last=x;cnt++;
15 }
16 printf("%d\n",cnt);
17 return 0;
18 }
Div 2 B:Complete the Word
Complete the Word
题意:给定一个字符串,其中某些字符未知,要求给出一个可能的字符串,使得存在一个包含26个大写字母的长度为26的连续子串
这题也是直接乱搞吧大概,我的思路就是统计每个子串中是否有重复,没有就说明合理然后随便构造一个答案就行了
代码:
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 char s[50100]; 7 int a[30],n; 8 int cnt=0; 9 int main(){ 10 scanf("%s",s+1); 11 int n=strlen(s+1); 12 int l=1; 13 int cnt=0; 14 for (int i=1;i<=n;i++){ 15 if (s[i]=='?') { 16 cnt++; 17 }else { 18 int t=s[i]-'A'+1; 19 if (a[t]==1) { 20 while (s[i]!=s[l]) { 21 if (s[l]=='?') { 22 cnt--; 23 }else a[s[l]-'A'+1]--; 24 l++; 25 } 26 if (s[l]=='?') cnt--; 27 else a[s[l]-'A'+1]--; 28 l++; 29 } 30 a[t]++; 31 } 32 if (i-l+1==26) { 33 for (int j=1;j<l;j++) printf("%c",s[j]=='?'?'A':s[j]); 34 for (int j=l;j<=i;j++) { 35 if (s[j]!='?') printf("%c",s[j]); 36 else { 37 for (int k=1;k<=26;k++) { 38 if (a[k]) continue; 39 printf("%c",k+'A'-1); 40 a[k]++; 41 break; 42 } 43 } 44 } 45 for (int j=i+1;j<=n;j++) printf("%c",s[j]=='?'?'A':s[j]); 46 return 0; 47 } 48 } 49 printf("-1\n"); 50 return 0; 51 }
Div 2 C and Div 1 A:Plus and Square Root
题意:给定一个数和两个操作,一个操作为+k,另一个操作为开根号然后k=k+1,初始时数为1,k=1,求达到k=n+1时的操作数
考虑构造一个可行方案,设执行开方操作后那个数为t,那么有$t=mk,m\in \mathbb N$(若不满足则下一次无法开方)同时考虑开方操作前有$t^2=n(k-1),n \in \mathbb N$所以令$t=k(k-1)$ 即可
代码:
1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cstring> 5 using namespace std; 6 typedef long long ll; 7 ll n,x; 8 int main(){ 9 cin>>n; 10 x=2; 11 for (ll i=1;i<=n;i++) { 12 ll ans=(i+1)*(i+1)*i-x/i; 13 cout<<ans<<endl; 14 x=i*(i+1); 15 } 16 17 }