2015.4 校赛回顾
用了一下午时间重刷了一次校赛题目
不参考资料做的还是2333
第一题手速题
第二题
一开始取余运算少加了一个,WA了一发
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int i,d[20000]; string c; memset(d,0,sizeof(d)); while(cin>>c) { int n=0; for(i=0;i<8;i++) { n=(n+((int(c[i])-48)*(20-i))%100000)%100000; } d[n]=d[n]+1; cout<<d[n]<<endl; } return 0; }
第三题
NOIP2014复赛题改编
硬做
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int gcd(int a,int b) { if(b==0)return a; return gcd(b,a%b); } int main() { int l,mi,i,j; long ii,jj; double x,y,shit,google,good,minus; while(cin>>x>>y>>l) { if(x==y){cout<<"1 1"<<endl;continue;} if(x>y){ good=l; shit=x/y; //cout<<shit<<endl; for(i=l;i>l/2-1;i--) { for(j=i;j>=1;j--) { google=(double)i/(double)j; minus=google-shit; //cout<<"->"<<" i:"<<i<<" j:"<<j<<" i/j:"<<google<<" -:"<<minus<<endl; if(minus<0) continue; if(minus<good) {good=minus;ii=i;jj=j;} } } mi=gcd(ii,jj); cout<<ii/mi<<" "<<jj/mi<<endl; } if(x<y){ good=l; shit=x/y; //cout<<shit<<endl; for(i=1;i<l/2+1;i++) { for(j=i;j<=l;j++) { google=(double)i/(double)j; minus=google-shit; //cout<<"->"<<" i:"<<i<<" j:"<<j<<" i/j:"<<google<<" -:"<<minus<<endl; if(minus<0) continue; if(minus<good) {good=minus;ii=i;jj=j;} } } mi=gcd(ii,jj); cout<<ii/mi<<" "<<jj/mi<<endl; } } return 0; }
第四题
没做出,先占位
第五题
NOIP题目,最烦这种数学题,
不知道结论打死也做不出来
黄金分割((sqrt(5)-1)/2)*(n+1)
#include<cstdio> #include<cmath> #include<iostream> #include<string> #include<algorithm> using namespace std; int f[10]; int main() { double a=(sqrt(5.0)-1.0)/2.0; long long d; f[0]=0; f[1]=1; f[2]=1; f[3]=2; f[4]=3; f[5]=3; f[6]=4; f[7]=4; while(~scanf("%lld",&d)) { if(d<=7){cout<<f[d]<<endl;} else{ cout<<(long long)(a*(d+1))<<endl; } } return 0; }
第六题
最小生成树
一开始打算拍模板,书上的kru-代码没打全不能用
用了前面用过的模板T掉,换做prim,书上的代码WA
前后交了十几次也是醉了
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <string> #include <algorithm> using namespace std; struct Kruskal { int x; int y; double value; }; int father[100002], son[100002]; bool cmp(const Kruskal &a, const Kruskal& b) { return a.value < b.value; } int unionsearch(int x) { if (x == father[x]) return x; else return unionsearch(father[x]);} bool join(int x, int y) { int root1 = unionsearch(x); int root2 = unionsearch(y); if (root1 == root2) return false; if (son[root1] >= son[root2]) { father[root2] = root1; son[root1] +=son[root2]; } else { father[root1] = root2; son[root2] += son[root1]; } return true; } int main() { double total = 0; double sum = 0; int n, m, flag = 0, num = 0; Kruskal edge[100002]; scanf("%lf", &total); scanf("%d", &n); m = 1; while(3 == scanf("%d%d%lf", &edge[m].x, &edge[m].y, &edge[m].value)) m++; m--; for(int i = 1; i <= n; i++) { father[i] = i; son[i] = 1; } sort(edge+1, edge+m+1, cmp); for (int i = 1; i <= m; i++) { if(join(edge[i].x, edge[i].y)) { num++; //edge number sum += edge[i].value; } if(num == n-1) { flag = 1; break; } } if (sum > total) flag = 0; if (flag) printf("Need %.2lf miles of cable\n", sum); else printf("Impossible\n"); fclose(stdin); return 0; }
第七题
还没看,占位