A:签到。room里有一个用for写的,hack了一发1e8 1,结果用了大概600+ms跑过去了。惨绝人寰。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() {int x=0,f=1;char c=getchar();while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();return x*f; } int n,m; int main() { /*#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout); #endif*/n=read(),m=read();cout<<(n*2-1)/m+1+(n*5-1)/m+1+(n*8-1)/m+1;return 0; }
B:讨论一发即可。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 1010 char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() {int x=0,f=1;char c=getchar();while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();return x*f; } int n; int main() { /*#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout); #endif*/n=read();while (n--){int x=read(),y=read();int p=y;if (y-x+1&1) y--;int ans=x&1?(y-x+1>>1):-(y-x+1>>1);if (p-x+1&1) ans+=p&1?-p:p;printf("%d\n",ans);}return 0; }
C:对矩形求个交,冷静一下瞎算算就行了。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 1010 char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} int read() {int x=0,f=1;char c=getchar();while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();return x*f; } int T,n,m; ll area(int x1,int y1,int x2,int y2){if (x1>x2||y1>y2) return 0;return 1ll*(x2-x1+1)*(y2-y1+1);} ll calcwhite(int x1,int y1,int x2,int y2) {ll s=area(x1,y1,x2,y2);if (x1+y1&1) return s>>1;else return s+1>>1; } ll calcblack(int x1,int y1,int x2,int y2){return area(x1,y1,x2,y2)-calcwhite(x1,y1,x2,y2);} int main() { /*#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout); #endif*/T=read();while (T--){n=read(),m=read();int x1=read(),y1=read(),x2=read(),y2=read();int x3=read(),y3=read(),x4=read(),y4=read();int x5=max(x1,x3),y5=max(y1,y3),x6=min(x2,x4),y6=min(y2,y4);ll white=calcwhite(1,1,n,m),black=calcblack(1,1,n,m);ll c1=calcblack(x1,y1,x2,y2);white+=c1,black-=c1;black+=calcwhite(x3,y3,x4,y4),white-=calcwhite(x3,y3,x4,y4);if (area(x5,y5,x6,y6)) black+=calcblack(x5,y5,x6,y6),white-=calcblack(x5,y5,x6,y6);printf("%I64d %I64d\n",white,black);}return 0; }
D:考虑答案为i时的最小和最大分裂次数是多少,各种递推式求通项到最后能捣鼓出来两个式子。显然答案若存在与n相差不会很大,暴力枚举check即可。当然式子不能直接算,需要各种乱搞防溢出。数学太差推一年。
#include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll unsigned long long #define N 1010 char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;} int gcd(int n,int m){return m==0?n:gcd(m,n%m);} ll read() {ll x=0,f=1;char c=getchar();while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();return x*f; } int T,n,m; int main() { /*#ifndef ONLINE_JUDGEfreopen("a.in","r",stdin);freopen("a.out","w",stdout); #endif*/T=read();while (T--){ll n=read(),m=read();int ans=-1;for (int i=(n>=63?n-63:0);i<n;i++){ll k=1;for (int j=1;j<=n-i+1;j++) k<<=1;k-=n-i;k-=2;if (k<=m){if (n+i+1>=63) {ans=i;break;}ll k=1;for (int j=1;j<=n-i-1;j++) k<<=1;k--;ll t=k+1;for (int j=1;j<=n+i+1;j++){k<<=1;if (k>=3*m+2) {ans=i;break;}}if (ans!=-1) break;t<<=1;if (t>=3*m+2) {ans=i;break;}t<<=1;if (t>=3*m+2) {ans=i;break;}k+=t;if (k>=3*m+2) {ans=i;break;}t=1;for (int j=1;j<=2*i;j++){t<<=1;if (t>=3*m+2) {ans=i;break;}}if (ans!=-1) break;k+=t;if (k>=3*m+2) {ans=i;break;}}}if (ans==-1) printf("NO\n");else printf("YES %d\n",ans);}return 0; }
E:这个条件比较显然的等价于子矩形中每一行都能重排成回文串(即出现次数为奇数的字母不超过一个)且对称行的字母组成相同。预处理每一行的每一段是否合法以及字母出现次数的哈希值,暴力枚举子矩形左右端点,对上下端点的每段合法区间马拉车即可。完全没时间写了。
F:没看
小号打的。result:rank 139 rating +92