Codeforces Round #524 (Div. 2)
好不容易考完电路,又可以回来刷题了,只是现在恐怕码力连新生都比不上了。
A |
开头就是一大水题,意思就是制作一张贺卡需要几张什么颜色的纸,一共做n份,一叠纸有k张纸,问你需要几叠纸。
1 #include<iostream> 2 #include<cmath> 3 using namespace std; 4 int main() 5 { 6 int n,k; 7 scanf("%d%d",&n,&k); 8 printf("%d\n",(int)ceil(1.0*n*8/k)+(int)ceil(1.0*n*5/k)+(int)ceil(1.0*n*2/k)); 9 }
给你一个数组,-1,2,-3,4.。。。。。,q次询问,求l到r之间的数组和
直接算就可以了。相邻的两个差距为1嘛!
1 #include<iostream> 2 using namespace std; 3 int main() 4 { 5 int T; 6 scanf("%d",&T); 7 while(T--){ 8 int l,r; 9 scanf("%d%d",&l,&r); 10 int flag1,flag2; 11 if(!(l&1)){l--;flag1=l;} 12 else flag1=0; 13 if(r&1){r++;flag2=r;} 14 else flag2=0; 15 printf("%d\n",(r-l+1)/2+flag1-flag2); 16 } 17 }
C |
过程稍稍有些麻烦,但是确实不难,就是那个求两矩形相交的公式是新学的,我实在是太弱了。
中间有一个过程,(a+b)%2==0换成(a+b)&1==0就会出问题,虽然我也不知道为什么
1 #include<iostream> 2 #include<algorithm> 3 #include<vector> 4 #include<stack> 5 #include<queue> 6 #include<map> 7 #include<set> 8 #include<cstdio> 9 #include<cstring> 10 #include<cmath> 11 #include<ctime> 12 #define fuck(x) cout<<#x<<" = "<<x<<endl; 13 #define ls (t<<1) 14 #define rs ((t<<1)+1) 15 using namespace std; 16 typedef long long ll; 17 typedef unsigned long long ull; 18 const int maxn = 100086; 19 const int inf = 2.1e9; 20 const ll Inf = 999999999999999999; 21 const int mod = 1000000007; 22 const double eps = 1e-6; 23 const double pi = acos(-1); 24 25 ll cal(ll x,ll y) 26 { 27 if(x%2==0||y%2==0){return x*y/2;} 28 return x*y/2+1; 29 } 30 31 int main() 32 { 33 34 int T; 35 scanf("%d",&T); 36 ll a,b,c,d,e,f,g,h; 37 ll white,black; 38 ll n,m; 39 while(T--){ 40 scanf("%lld%lld",&n,&m); 41 white = cal(n,m); 42 black = n*m-white; 43 scanf("%lld%lld%lld%lld",&a,&b,&c,&d); 44 ll t = cal(c-a+1,d-b+1); 45 if((a+b)%2==0){t = (c-a+1)*(d-b+1)-t;} 46 white+=t; 47 black-=t; 48 49 scanf("%lld%lld%lld%lld",&e,&f,&g,&h); 50 t = cal(g-e+1,h-f+1); 51 if((e+f)&1){t = (g-e+1)*(h-f+1)-t;} 52 white-=t; 53 black+=t; 54 55 a = max(a,e);b=max(b,f);c=min(c,g);d=min(d,h); 56 t = cal(c-a+1,d-b+1); 57 if((a+b)%2==0){t = (c-a+1)*(d-b+1)-t;} 58 if(c<a||d<b){t=0;} 59 white-=t; 60 black+=t; 61 printf("%lld %lld\n",white,black); 62 } 63 64 65 return 0; 66 }
如需转载,请注明出处
如有侵权,联系删除
2290713181@qq.com
如有侵权,联系删除
2290713181@qq.com