Codeforces Round #494 (Div. 3)爆炸记
一开始网站爆炸,502刷新了10min,那时就知道这场要gg了。。。
A.签到题
B.求一个01串包含a个0,b个1且恰好有x个位置s[i]不等于s[i+1];
考虑a,b大小关系确定第一个是0还是1,前面构造x-1个10或01,后面就连着输出相同的就好了。
没看到样例wa3两次。。。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <queue> 6 #include <cmath> 7 #define ll long long 8 #define out(a) printf("%d",a) 9 #define writeln printf("\n") 10 #define min(a,b) a<b?a:b; 11 #define max(a,b) a>b?a:b; 12 using namespace std; 13 int n,m,a,b,c,d,x,ans,now; 14 int read() 15 { 16 int s=0,t=1; char c; 17 while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();} 18 while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();} 19 return s*t; 20 } 21 ll readl() 22 { 23 ll s=0,t=1; char c; 24 while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();} 25 while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();} 26 return s*t; 27 } 28 int main() 29 { 30 b=read(); a=read(); x=read(); 31 if (x==1) { 32 for (int i=1;i<=a;i++) 33 out(1); 34 for (int i=1;i<=b;i++) 35 out(0); 36 return 0; 37 } 38 if (a>b) { 39 for (int i=1;i<=x;i++) 40 if (i&1) out(1),c++,now=1; 41 else out(0),d++,now=0; 42 } 43 else { 44 for (int i=1;i<=x;i++) 45 if (i&1) out(0),d++,now=0; 46 else out(1),c++,now=1; 47 } 48 a-=c; b-=d; 49 if (now==1) { 50 for (int i=1;i<=a;i++) 51 out(1); 52 for (int i=1;i<=b;i++) 53 out(0); 54 } 55 else { 56 for (int i=1;i<=b;i++) 57 out(0); 58 for (int i=1;i<=a;i++) 59 out(1); 60 } 61 return 0; 62 }
C.找一个不小于k的区间平均值最大.
读错题意罚时爆炸QAQ。
记录前缀和然后二重循环扫一遍即可。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <queue> 6 #include <cmath> 7 #define ll long long 8 #define out(a) printf("%lld",a) 9 #define writeln printf("\n") 10 #define min(a,b) a<b?a:b; 11 #define max(a,b) a>b?a:b; 12 using namespace std; 13 int n,m,a,b,x,k,num; 14 double ans; 15 int sum[100050]; 16 int read() 17 { 18 int s=0,t=1; char c; 19 while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();} 20 while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();} 21 return s*t; 22 } 23 ll readl() 24 { 25 ll s=0,t=1; char c; 26 while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();} 27 while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();} 28 return s*t; 29 } 30 int main() 31 { 32 n=read(); k=read(); 33 for (int i=1;i<=n;i++) { 34 x=read(); sum[i]=sum[i-1]+x; 35 } 36 for (int j=k;j<=n;j++) { 37 num=-2333333; 38 for (int i=j;i<=n;i++) 39 num=max(num,sum[i]-sum[i-j]); 40 if ((double)num/j>ans) ans=(double)num/j; 41 } 42 printf("%.15f",ans); 43 return 0; 44 }
D.给n个2的d次方的数,m个询问问是否有n个数的子集和等于x.
正解都想出来了,可就是没写出来,细节总是错错错QAQ
考虑把所有数都搞成2进制,如果这一位不够的话就往下一位拆。。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <queue> 6 #include <cmath> 7 #define ll long long 8 #define out(a) printf("%d",a) 9 #define writeln printf("\n") 10 using namespace std; 11 int n,k; 12 int x,cnt,m,tot,ans; 13 int a[200050],b[200050]; 14 bool flag; 15 int read() 16 { 17 int s=0,t=1; char c; 18 while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();} 19 while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();} 20 return s*t; 21 } 22 ll readl() 23 { 24 ll s=0,t=1; char c; 25 while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();} 26 while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();} 27 return s*t; 28 } 29 int main() 30 { 31 n=read(),k=read(); 32 for (int i=1;i<=n;i++){ 33 x=read(); cnt=0; 34 while (true) { 35 if (x==1||x==0) break; 36 cnt++; x/=2; 37 } 38 a[cnt]++; //out(cnt); writeln; 39 } 40 for (int i=1;i<=k;i++){ 41 m=read(); flag=false; tot=ans=0; b[0]=0; 42 while (true) { 43 b[++tot]=m%2; 44 if (flag) break; 45 m/=2; 46 if (m==0||m==1) flag=true; 47 } 48 for (int j=tot;j>=0;j--) 49 if (a[j-1]>=b[j]) ans+=b[j],b[j]=0; 50 else { 51 b[j]-=a[j-1]; 52 b[j-1]+=b[j]*2; 53 ans+=a[j-1]; 54 } 55 if (b[0]>0) out(-1); 56 else out(ans); 57 writeln; 58 } 59 return 0; 60 }
总结
1.码力还是太差了,细节问题总出错。
2.心态问题,急忙交题不测样例是大忌,被一些bug卡的很烦。
3.读题能力差,现在由于cf复制的问题不太兹磁翻译,所以基本上都是读英语或dalao翻译,题意总是看错。
There is still a long way to go....