Codeforces Round #498 (Div. 3)
这场..
不知道说什么好了唉。。。
A.签到++
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <queue> 6 #include <map> 7 #define ll long long 8 #define out(a) printf("%d ",a) 9 #define writeln printf("\n") 10 #define N 100050 11 using namespace std; 12 int n; 13 int a[N]; 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 n=read(); 31 for (int i=1;i<=n;i++) 32 a[i]=read(); 33 for (int i=1;i<=n;i++) 34 if (a[i]&1) out(a[i]); 35 else out(a[i]-1); 36 return 0; 37 }
B.n个数,找个方案分成k个区间使每个区间最大值的和最大.
排序找最大的k个数,然后下标减一减就好了。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <queue> 6 #include <map> 7 #include <algorithm> 8 #define ll long long 9 #define out(a) printf("%d ",a) 10 #define writeln printf("\n") 11 #define N 100050 12 using namespace std; 13 int n,k,tot,ans,now; 14 int b[N]; 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 struct dist 30 { 31 int h,id; 32 }a[N]; 33 bool cmp(dist a,dist b) 34 { 35 return a.h==b.h?a.id<b.id:a.h>b.h; 36 } 37 int main() 38 { 39 n=read(); k=read(); 40 for (int i=1;i<=n;i++) 41 a[i].h=read(),a[i].id=i; 42 sort(a+1,a+n+1,cmp); 43 for (int i=1;i<=k;i++) 44 ans+=a[i].h,b[++tot]=a[i].id; 45 out(ans); writeln; 46 sort(b+1,b+tot+1); now=0; 47 for (int i=1;i<=tot;i++) 48 if (i!=k) out(b[i]-now),now=b[i]; 49 else out(n-now); 50 return 0; 51 }
C.n个数分成三个区间,求第一个区间和sum1等于第三个区间和sum3时sum1最大值,区间可以是空集。
预处理出前缀和,后缀和,从两端往中间扫,区间重合的时候break掉.记得开ll
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <queue> 6 #include <map> 7 #define ll long long 8 #define out(a) printf("%lld",a) 9 #define writeln printf("\n") 10 #define N 200050 11 using namespace std; 12 int n; 13 int a[N]; 14 int x,y; 15 ll sum1[N],sum2[N],ans; 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(); 33 for (int i=1;i<=n;i++) 34 a[i]=read(),sum1[i]=sum1[i-1]+a[i]; 35 for (int i=n;i>=1;i--) 36 sum2[i]=sum2[i+1]+a[i]; 37 for (int i=1;i<=n;i++){ 38 if (sum1[n]-sum1[i]==sum1[i]){ 39 out(sum1[i]); 40 return 0; 41 } 42 } 43 x=1; y=n; 44 while (x<=n&&y>=1){ 45 if (x>=y) break; 46 if (sum1[x]==sum2[y]) ans=sum1[x]; 47 if (sum1[x]>sum2[y]) y--; 48 else x++; 49 } 50 out(ans); 51 return 0; 52 }
看了下此时排名300多海星,然而接下来就是一个多小时的玩泥巴了。。。
看D,诶这个样例怎么来的....
哦哦哦懂了,好像分类一下就好了,唉好麻烦啊。
诶这个E怎么过这么多了,诶好像xjb写写就能过了.
coding....诶不对啊样例过不了,诶不对啊我想错了GG
滚回去看D,分类好久过样例,无限wa3.。。
唉算了好困回去碎觉了..结果1000多名滚粗,涨分的大好局势毁了..
D,E找时间补补吧。
总结:这场ABC写的海星,手速和思维都够快且失误较少,但是后面的题还是缺少耐心去写导致GG,时间安排也不太好吧..总之div3写不出5题不能算是合格吧.....