【NOIP2015 Training Contest】2015.11.02&2015.11.03
啊啊啊啊,第一次停(dìng)课咯,感觉要记录一下联赛dìng课期间的颓废生活
第一弹:2015.11.02&2015.11.03膜你题
2015.11.02膜你题【NOIP2015 Training Contest Day 1】
Problem A. ZCC Loves Trees
感觉像是数论题哎,于是在SHC大神的指点下愉快GG
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> using namespace std; int a,b,c,ab,bc,ac,ans; int gcd(int a,int b) { while (a)a ^= b ^= a ^= b %= a; return b;} int work(int xx,int yy) { int k=-yy/xx; int tmp; tmp=min(abs(xx*k+yy),abs(xx*(k+1)+yy)); tmp=min(tmp,abs(xx*(k-1)+yy)); return tmp; } int main() { while (scanf("%d%d%d",&a,&b,&c)!=EOF) { ab=gcd(a,b); bc=gcd(b,c); ac=gcd(a,c); ans=0; for (int i=0;i<=b;i++) for (int j=0;j<=c;++j) { int tmp=0x7fffffff; tmp=min(work(ab,i),work(ac,j)); tmp=min(tmp,work(bc,abs(i-j))); ans=max(ans,tmp); } printf("%d\n",ans); } return 0; }
Problem B. ZCC Loves Travelling
为什么。一道贪心题的 最大数据 只有 1000(大雾)
没做啦,一直以为是DP于是弃疗啦(逃。。)
Problem C. ZCC Loves Pi
第一次把提答题的10个点都ACwow
这么多人一起写T3提答也是醉了,不过还挺好玩的(484时间充足?
先把一定范围内的所有任意两个数的fn()的值,由于总共就4个数,所以用lower_bound在原数组上查找符合条件的另两个数之和就可以啦
然而会被精度杀,用了long double也被精度杀,怎么办呢,不行的点直接输出差最小的四个数,结果checker给对了
一个比较鬼畜(xu)的运行数据
#include <cstdio> #include <cmath> #include <iostream> #include <fstream> #include <algorithm> #define D long double using namespace std; #define PI 7.1415926535897932384626433832795028 int n; struct REC { long double sum; int x,y; }; int tot,xa,ya,xb,yb; REC a[50000100]; long double aa[50000100]; bool cmp(REC xx,REC yy) { return xx.sum<yy.sum;} int main() { for(int T=1;T<=10;++T) { fin>>n; D xxx; for(int i=1;i<=10;++i)fans>>xxx; tot=0; bool f=0; for (int i=0;i<=n*2;++i) for (int j=i;j<=n*2;++j) a[++tot].sum=(D)exp((D)i/n)+exp((D)j/n),a[tot].x=i,a[tot].y=j; sort(a+1,a+1+tot,cmp); for (int i=1;i<=tot;++i) aa[i]=a[i].sum; D minn=0x7fffffff; for (int i=1;i<=tot;++i) { if (aa[i]>PI) break; D xx=PI-aa[i]; int yy=lower_bound(aa+1,aa+1+tot,xx)-aa; if (abs(xx-aa[yy])<=xxx) { printf("%d %d %d %d\n",a[i].x,a[i].y,a[yy].x,a[yy].y); f=1; break; } else if (abs(xx-aa[yy])<minn) { minn=abs(xx-aa[yy]); xa=a[i].x,ya=a[i].y,xb=a[yy].x,yb=a[yy].y; } if (abs(xx-aa[yy+1])<=xxx) { printf("%d %d %d %d\n",a[i].x,a[i].y,a[yy+1].x,a[yy+1].y); f=1; break; }else if (abs(xx-aa[yy+1])<minn) { minn=abs(xx-aa[yy+1]); xa=a[i].x,ya=a[i].y,xb=a[yy+1].x,yb=a[yy+1].y; } if (abs(xx-aa[yy-1])<=xxx) { printf("%d %d %d %d\n",a[i].x,a[i].y,a[yy-1].x,a[yy-1].y); f=1; break; }else if (abs(xx-aa[yy-1])<minn) { minn=abs(xx-aa[yy-1]); xa=a[i].x,ya=a[i].y,xb=a[yy-1].x,yb=a[yy-1].y; } } if (!f) printf("%d %d %d %d\n",xa,ya,xb,yb); } return 0; }
2015.11.03膜你题【NOIP2015 Training Contest Day 3】
为什么是DAY 3?(大雾)
Problem A. ZCC Loves Strings II
以每个点为支点向两边推,然后减掉一连串0带来的重复计算
前两个点特判了一下WoW
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> using namespace std; int len,ans,tota,totb; char s[2510]; int fa[2510],fb[2510],sum[2510]; int main() { while (scanf("%s",s)!=EOF) { ans=0; len=strlen(s); if (len==1) { puts("1"); continue;} bool f=1; for (int i=0;i<len-1;++i) if (s[i]!=s[i+1]) { f=0; break;} if (f) { if (s[0]=='0') { printf("%d\n",(len+1)*len/2); continue;} else if (s[0]=='1') { if (len&1) { printf("%d\n",(len+1)*(len+1)/4); continue;} else { printf("%d\n",len*(len+2)/4); continue; } } } for (int i=0;i<len;++i) { memset(fa,0,sizeof(fa)); memset(fb,0,sizeof(fb)); memset(sum,0,sizeof(sum)); sum[0]=1; sum[1]=0; fa[1]=fb[1]=1; tota=totb=0; for (int j=i-1;j>=0;--j) {if (s[j]=='1') tota+=i-j,sum[++sum[0]]=tota; fa[sum[0]]++;} int k=1; f=1; for (int j=i+1;j<len;++j) { if (s[j]=='1') { if (f) ans+=fa[k]*fb[k]; totb+=j-i; while (sum[k]<totb&&k<=sum[0]) k++; f=0; if (sum[k]==totb) f=1; } if (f) fb[k]++; } if (f) ans+=fa[k]*fb[k]; } int j=0,st,en; while (j<len) { while (s[j]!='0'&&j<len) j++; st=j; while (s[j]=='0'&&j<len) j++; en=j; int l=en-st; ans-=((l*l*l+l*l*3+2*l)/6-l*(l+1)/2); } printf("%d\n",ans); } return 0; }
Problem B. ZCC Loves Cards IV
打表卷分走人
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <cmath> using namespace std; int ans[10][10]= { {0,1,2,3,4,5,6,7,8}, {1,0}, {2,1,0}, {3,2,1,0}, {4,3,2,1,0}, {5,4,2,2,1,0}, {6,5,3,2,2,1,0}, {7,6,3,3,2,2,1,0}, {8,7,4,3,3,2,2,1,0}, }; int x,y; int main() { while (scanf("%d%d",&x,&y)!=EOF) { if (x<=8) printf("%d\n",ans[x][y]); else if (y==x-1) puts("1"); else if (x==y) puts("0"); else if (y==1) printf("%d\n",x-1); else printf("%d\n",x/y+1); } return 0; }
Problem C. ZCC Loves Factors
大暴力卷分走人(不拿程序丢人了)