一名大三older 希望能帮助大一萌新。。。加油 xiandianer!!!!;
xdoj 1260 (B) 水题 用了一下STL (好长啊。。。)
#include<iostream> #include<cstdio> #include<algorithm> #include<map> using namespace std; const int N=107; struct T{ string suj; double p; bool operator <(const T& b) const { return suj<b.suj; } }; map <T,int> mapp; int n; double f (int x) { if (x<=59) return 0.0; if (x<=62) return 1.0; if (x<=65) return 1.5; if (x<=68) return 1.7; if (x<=71) return 2.0; if (x<=74) return 2.3; if (x<=77) return 2.7; if (x<=81) return 3.0; if (x<=84) return 3.3; if (x<=89) return 3.7; return 4.0; } int main () { cin>>n; map<T,int>::iterator it; for (int i=1;i<=n;i++) { T temp; int w; cin>>temp.suj>>temp.p>>w; if (mapp[temp]<w) mapp[temp]=w; } it=mapp.begin(); double sum=0.0; double k=0.0; double nn=0.0; while (it!=mapp.end()) { sum+=(it->first.p)*(it->second); k+=(it->first.p)*f(it->second); nn+=it->first.p; it++; } printf ("%.1lf\n%.2lf\n",sum/nn,k/nn); return 0; }
xdoj 1255 (C) 水题 不明白为什么不加getchar() 会GG;
#include<iostream> #include<cstdio> #include<string> using namespace std; char* str="0123456789ABCDEF"; int main () { int x,y,z; while (~scanf("(%d, %d, %d)",&x,&y,&z)) { char s[7]; s[0]=str[x/16]; s[1]=str[x%16]; s[2]=str[y/16]; s[3]=str[y%16]; s[4]=str[z/16]; s[5]=str[z%16]; s[6]='\0'; cout<<"#"<<s<<endl; getchar(); } return 0; }
xdoj 1265(D) 取余找循环节呗。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=1010; int mod=1001; struct T { int a; int b; }; T t[N]; int p[N]; int A,B,C; int n,k; int mycmp (T aa,T bb) { return aa.a>bb.a; } int main () { int nn; scanf ("%d",&nn); while (nn--) { scanf ("%d %d %d",&A,&B,&C); memset (p,0,sizeof(p)); int i=1; t[1].a=A; p[A]=1; while (1) { t[i+1].a=(t[i].a*B+C)%mod; if (p[t[i+1].a]) break; else p[t[i+1].a]=i+1; i++; } int x1=p[t[i+1].a]; int x2=i; int num=x2-x1+1; scanf ("%d %d",&n,&k); int times=(n-x1+1)/num; for (i=1;i<=x2;i++) { if (i<x1) t[i].b=1; else if (i<=x1+(n-x1+1)%num) t[i].b=times+1; else t[i].b=times; } sort (t+1,t+1+x2,mycmp); i=1; while (1) { if (p[t[i].a]>n) {i++; continue;} if (k-t[i].b<=0) break; else k-=t[i].b; i++; } printf ("%d\n",t[i].a); } return 0; }
xdoj 1262(E) 找A前后Q数目相乘
#include<iostream> #include<cstdio> #include<cstring> using namespace std; typedef long long LL; const int N=1e5+7; char str[N]; int main () { scanf ("%s",str); int len=strlen(str); LL n1=0; for (int i=0;i<len;i++) { if (str[i]=='Q') n1++; } LL n2=0; LL sum=0; for (int i=0;i<len;i++) { if (str[i]=='Q') n2++; if (str[i]=='A') sum+=n2*(n1-n2); } printf ("%lld\n",sum); return 0; }
xdoj 1264(F) 找一下规律 发现数据按照二进制递增的
#include<cstdio> #include<cstring> #include<iostream> using namespace std; typedef long long LL; bool a[107]; int main () { LL n; while (~scanf ("%lld",&n)) { memset (a,0,sizeof(a)); int i=0; while (n) { if (n&1) a[i]=1; n=n>>1; i++; } for (int i=99;i>=0;i--) { if (a[i]) printf ("R"); else printf ("G"); } printf ("\n"); } return 0; }
xdoj 1261(G) 开始用图做的 GG了最后用的并查集
#include<cstdio> #include<cstring> #include<iostream> using namespace std; const int N=1e6+7; int p[N]; int f[N]; int n,m; int _find(int x) { if (x!=f[x]) f[x]=_find(f[x]); return f[x]; } int main () { while (~scanf ("%d %d",&n,&m)) { for (int i=1;i<=n;i++) f[i]=i; memset(p,0,sizeof(p)); for (int i=1;i<=m;i++) { int op,a,b; scanf ("%d %d %d",&op,&a,&b); if (op==0) { int x1=_find(a); int x2=_find(b); if (x1==x2||p[x1]==x2) continue; if (!p[x1]&&!p[x2]) { p[x1]=x2; p[x2]=x1; } else if (!p[x1]&&p[x2]) f[x1]=p[x2]; else if (!p[x2]&&p[x1]) f[x2]=p[x1]; else {f[x2]=p[x1]; f[p[x2]]=x1;} //for (int i=1;i<=n;i++) // cout<<_find(i)<<" "<<p[i]<<endl; } else { int x1=_find(a); int x2=_find(b); if (x1==x2) printf ("In the same category.\n"); else if (p[x1]==x2) printf ("In different category.\n"); else printf ("Not sure yet.\n"); } } } return 0; }
xdoj 1254(H) 大整数减法 基本功
#include<iostream> #include<cstdio> #include<cstring> #include<string> using namespace std; const int N=107; int a[N]; int b[N]; int x1[N]; int x2[N]; string s1,s2; int cmp (int a[],int b[]) { for (int i=101;i>=0;i--) { if (a[i]>b[i]) return 1; if (a[i]<b[i]) return -1; } return 0; } void f (int x[]) { memset(x1,0,sizeof(x1)); memset(x2,0,sizeof(x2)); int j=0; for (int i=s1.size()-1;i>=0;i--) x1[j++]=s1[i]-'0'; j=0; for (int i=s2.size()-1;i>=0;i--) x2[j++]=s2[i]-'0'; for (int i=0;i<s1.size();i++) { if (x1[i]<x2[i]) { j=i; while (x1[j+1]==0) { x1[j+1]=9; j++; } x1[j+1]--; x1[i]+=10; } x[i]=(x1[i]-=x2[i]); } return ; } int main () { cin>>s2>>s1; f(a); cin>>s2>>s1; f(b); if (cmp(a,b)>0) printf ("Ting\n"); else if (cmp(a,b)==0) printf ("Excellent\n"); else printf ("Yu\n"); return 0; }
xdoj 1257 (I) 曼哈顿距离 我也是百度的。。。哈哈哈
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; #define INF 0x3f3f3f3f int T,n; ll a1,a2,b1,b2; int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); a1=b1=INF,a2=b2=-INF; for(int i=0;i<n;i++) { ll x,y; scanf ("%lld %lld",&x,&y); a1=min(a1,x+y),a2=max(a2,x+y); b1=min(b1,x-y),b2=max(b2,x-y); } ll ans=max(a2-a1,b2-b1); printf("%lld\n",ans); } return 0; }
xdoj 1250 (J) 好吧这道题我想了好久。。一天?/ 最后感谢formilk的i提示 用的先序遍历 。。居然过了。但应该不是最好的解法
#include<cstdio> #include<algorithm> using namespace std; const int N=5e6+7; struct T { int x; int y; }; T k[100]; T s[2*N]; int ss; int t; int n_max; int a,b,c,d,n,m; void fare (int a,int b,int c,int d) { if (b+d>n_max) return ; fare (a,b,a+c,b+d); k[++t].x=(a+c); k[t].y=(b+d); fare (a+c,b+d,c,d); return ; } int gcd (int x,int y) { return !y?x:gcd(y,x%y); } void f(int& x,int& y ) { int p=gcd (x,y); x=x/p; y=y/p; return ; } int main () { int Q; scanf ("%d",&Q); while (Q--) { scanf ("%d %d %d %d %d %d",&a,&b,&c,&d,&n,&m); ss=0; f(a,b); T t1={a,b}; f(c,d); T t2={c,d}; n_max=max(b,d); t=1; k[t].x=0; k[t].y=1; fare (0,1,1,1); k[++t].x=1;k[t].y=1; int i; for (i=1;;i++) if (k[i].x==t2.x&&k[i].y==t2.y) break; for (;;i--) { s[++ss]=k[i]; if (k[i].x==t1.x&&k[i].y==t1.y) break; } int nn=0; while (1){ t1=s[ss--]; nn++; if (nn==n+1) break; if (ss==0) break; t2=s[ss]; while (1) { int x=t1.x+t2.x; int y=t1.y+t2.y; f(x,y); if (y<=m) { t2.x=x; t2.y=y; s[++ss]=t2; } else break; } } if (nn==n+1&&!(t1.x==c&&t1.y==d)) printf ("%d %d\n",t1.x,t1.y); else printf ("-1\n"); } return 0; }
有点匆忙 。。。还有作业啊 欢迎交流QQ-821474143
抓住青春的尾巴。。。