[关闭]
@Asuna 2016-10-12T04:29:07.000000Z 字数 9270 阅读 759

题目1:Presents

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是有n个人要交换礼物,其中第i个人会把礼物送给第a[i]个人,要输出第i个人收到了谁的礼物。

分析:这可难倒了本萌妹了。但就在本萌妹晚上看美剧的时候突然灵光一现!其实建两个数组,一个数组存储输入数据,另一个数组将下标与对应元素数值调换后再次存入其中再输出就结束啦。

参考代码:

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<cstdlib>
  5. #include<string>
  6. #include<cmath>
  7. using namespace std;
  8. int n,a[105],b[105];
  9. int main()
  10. {
  11. cin>>n;
  12. for (int i=1; i<=n; i++)
  13. cin>>a[i];
  14. for (int i=1; i<=n; i++)
  15. b[a[i]]=i;
  16. for (int i=1; i<=n; i++)
  17. cout<<b[i]<<" ";
  18. return 0;
  19. }

题目2:Ternary Logic

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实这题就是定义了一个tor运算,这个tor运算非常的高大上,因为他可以把你输入的两个十进制数分别转换成三进制数并且在各个位上进行加法操作(但注意了!不会进位的!!!)然后重新转换成1个十进制数。

分析:这可难倒了本萌妹了。但就在本萌妹晚上学OC的时候突然灵光一现!(tmd这OC简直难爆了)其实我们只需要模拟三进制每一位的转换,从末位往前依次进行转换并相加即可,具体看代码啦啦啦我也讲不清楚。。和二进制差不多的啦,加油哦。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<string>
  6. using namespace std;
  7. int a,b=0,c,q=1,s,t;
  8. int main()
  9. {
  10. cin>>a>>c;
  11. s=a;
  12. t=c;
  13. while (t!=0 || s!=0)
  14. {
  15. b+=((t%3-s%3+3)%3)*q;
  16. //cout<<b<<" "<<a<<" "<<c<<" "<<q<<endl;
  17. q*=3;
  18. s/=3;
  19. t/=3;
  20. }
  21. cout<<b<<endl;
  22. return 0;
  23. }

题目3:Postcards and photos

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是给定一串含C和P的字符串,一次只能读字母相同的,并且就算相同的最多也只能一次读5个,问要多少次能把字符串读完。

分析:这可难倒了本萌妹了。但就在本萌妹晚上刷漫画的时候突然灵光一现!其实我们只要。。。只要。。。就模拟嘛。。。搞个sum计算相同的出现了多少个了,一到5就次数加一,碰到不同的也加一嘛。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<string>
  6. using namespace std;
  7. string s;
  8. char c;
  9. int i,l,sum,ans=0;
  10. int main()
  11. {
  12. cin>>s;
  13. c=s[0];
  14. l=s.size();
  15. i=1;
  16. sum=5;
  17. while (l>0)
  18. {
  19. if (c!=s[i])
  20. {
  21. ans++;
  22. c=s[i];
  23. sum=5;
  24. }else sum--;
  25. if (sum==0)
  26. {
  27. ans++;
  28. sum=5;
  29. }
  30. i++;
  31. l--;
  32. }
  33. cout<<ans<<endl;
  34. return 0;
  35. }

题目4:Permutation

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是给了n个数,最后要把这串数变为1~n,看要改变多少个数。

分析:这可难倒了本萌妹了。但就在本萌妹晚上找电影看的时候突然灵光一现!其实我们只要设置一个标记数组,标记哪些数字出现了,然后再扫一遍1~n,若有没出现的数字就把答案加一。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<algorithm>
  4. #include<cstdlib>
  5. #include<cmath>
  6. #include<cstring>
  7. #include<string>
  8. using namespace std;
  9. int n,a[5005],b[5005],ans=0;
  10. int main()
  11. {
  12. memset(b,false,sizeof(b));
  13. cin>>n;
  14. for (int i=1; i<=n; i++)
  15. {
  16. cin>>a[i];
  17. // b[a[i]]++;
  18. }
  19. sort(a+1,a+n+1);
  20. for (int i=1; i<=n; i++)
  21. b[a[i]]=true;
  22. for (int i=1; i<=n; i++)
  23. if (b[i]==false) ans++;
  24. cout<<ans<<endl;
  25. return 0;
  26. }

题目5:Petr and Book

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是有一本n页的书,并且我们知道从周一到周五我们分别能看多少页,周数是无限的且每周的每天看的页数相同。问最后是周几看完的。

分析:这可难倒了本萌妹了。但就在本萌妹晚上和闺蜜卿卿我我的时候突然灵光一现!其实就mod一下一周看的总页数,然后就可以暴力判断是哪天看完的了。特别需要注意的是假设mod完以后是0即是在某一周结束的时候看完的,那么我们需要找到一周最靠后且看的页数不为0的那天即为答案。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<string>
  6. #include<cmath>
  7. using namespace std;
  8. int a[8],n,ans,sum,k,j=1;
  9. int main()
  10. {
  11. cin>>n;
  12. for (int i=1; i<=7; i++)
  13. {
  14. cin>>a[i];
  15. sum+=a[i];
  16. }
  17. k=n%sum;
  18. //cout<<k<<endl;
  19. if (k==0)
  20. {
  21. for (int i=1; i<=7; i++)
  22. if (a[i]!=0) j=i;
  23. ans=j;
  24. }
  25. if (k!=0)
  26. {
  27. if (k<=a[1]) ans=1;
  28. if (k>a[1] && k<=a[1]+a[2]) ans=2;
  29. if (k>a[1]+a[2] && k<=a[1]+a[2]+a[3]) ans=3;
  30. if (k>a[1]+a[2]+a[3] && k<=a[1]+a[2]+a[3]+a[4]) ans=4;
  31. if (k>a[1]+a[2]+a[3]+a[4] && k<=a[1]+a[2]+a[3]+a[4]+a[5]) ans=5;
  32. if (k>a[1]+a[2]+a[3]+a[4]+a[5] && k<=a[1]+a[2]+a[3]+a[4]+a[5]+a[6]) ans=6;
  33. if ((k>a[1]+a[2]+a[3]+a[4]+a[5]+a[6] && k<=a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7])) ans=7;
  34. }
  35. cout<<ans<<endl;
  36. return 0;
  37. }

题目6:Amusing Joke

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是给我们三个字符串ABC,看A+B和C的字母组成是否完全相同。

分析:这可难倒了本萌妹了。但就在本萌妹晚上晾衣服的时候突然灵光一现!其实我们只需要把AB串在一起每个字母排个序,把C也排个序,然后看看AB串是否就是C串即可。

参考代码:

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<algorithm>
  5. #include<string>
  6. #include<cstdio>
  7. using namespace std;
  8. string a,b,c;
  9. int lc,j=0,k=0,la;
  10. int main()
  11. {
  12. cin>>a>>b>>c;
  13. a+=b;
  14. sort(a.begin(),a.end());
  15. lc=c.size();
  16. la=a.size();
  17. //cout<<la<<endl;
  18. sort(c.begin(),c.end());
  19. if (lc>la)
  20. for (int i=la; i<=lc; i++)
  21. a+="0";
  22. if (lc<la)
  23. for (int i=lc; i<=la; i++)
  24. c+="0";
  25. //cout<<la<<endl;
  26. lc=c.size();
  27. for (int i=0; i<la; i++)
  28. if (a[i]==c[i]) j++;
  29. //cout<<j<<endl;
  30. if (j==lc)
  31. cout<<"YES"<<endl;
  32. else
  33. cout<<"NO"<<endl;
  34. return 0;
  35. }

题目7:Help Vasilisa the Wise 2

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是2X2的矩形,要求对角线,横竖的和都是给定的数且矩形内只能填1~9,求矩形。

分析:这可难倒了本萌妹了。但就在本萌妹晚上看风景的时候突然灵光一现!其实我们暴力枚举一个格子1~9,用给定的几个数把剩下三格推出来,判断是否可行即可。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cmath>
  5. #include<cstring>
  6. #include<string>
  7. #include<algorithm>
  8. using namespace std;
  9. int r1,r2,d1,d2,c1,c2,x1=1,x2,yy1,y2;
  10. int main()
  11. {
  12. cin>>r1>>r2;
  13. cin>>c1>>c2;
  14. cin>>d1>>d2;
  15. while (x1<10)
  16. {
  17. x2=r1-x1;
  18. yy1=c1-x1;
  19. y2=d1-x1;
  20. if (x2+y2==c2 && yy1+y2==r2 && x2+yy1==d2)
  21. if (x1!=x2 && x1!=yy1 && x1!=y2)
  22. if (x2!=yy1 && x2!=y2 && yy1!=y2)
  23. if (x2>=1 && x2<=9 && yy1>=1 && yy1<=9 && y2>=1 && y2<=9)
  24. {
  25. cout<<x1<<" "<<x2<<endl;
  26. cout<<yy1<<" "<<y2<<endl;
  27. return 0;
  28. }
  29. x1++;
  30. }
  31. cout<<-1<<endl;
  32. return 0;
  33. }

题目8:Help Kingdom of Far Far Away 2

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是字符串转化问题,不过多赘述,题都不用看看样例即可。

分析:这可难倒了本萌妹了。但就在本萌妹晚上唱情歌的时候突然灵光一现!其实我们只要先判断正负,整数小数用两个数组储存,整数部分每三位打个“,”,小数部分注意不足两位补“0”,超过两位取两位即可。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<cmath>
  6. using namespace std;
  7. string s,z,x;
  8. bool bx=false;
  9. int ls,lz,lx;
  10. int main()
  11. {
  12. cin>>s;
  13. ls=s.size();
  14. if (s[0]=='-') cout<<"(";
  15. cout<<"$";
  16. for (int i=0; i<s.size(); i++)
  17. {
  18. if (s[i]=='.') bx=true;
  19. if (s[i]>='0' && s[i]<='9')
  20. if (bx==true) x+=s[i];
  21. else z+=s[i];
  22. }
  23. lz=z.size();
  24. lx=x.size();
  25. //cout<<lx<<endl;
  26. if (lz==0) cout<<0;
  27. else
  28. {
  29. for(int i=0; i<lz; i++)
  30. {
  31. if((lz-i)%3==0)
  32. {
  33. if(i!=0) cout<<",";
  34. }
  35. cout<<z[i];
  36. }
  37. }
  38. cout<<".";
  39. for (int i=0; i<2; i++)
  40. if (lx>i) cout<<x[i];
  41. else cout<<0;
  42. if (s[0]=='-') cout<<")";
  43. return 0;
  44. }

题目9:Lucky Ticket

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是一定只有4和7两个数字组成,且前n/2个数的和和后n/2个数的和相等就是lucky ticket。

分析:这可难倒了本萌妹了。但就在本萌妹晚上约汉子的时候突然灵光一现!(立刻就跑回宿舍刷题了)其实只要读入字符串,先判断有无除了4、7之外的数字,若没有每一位转成int,求前后和判断即可。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6. using namespace std;
  7. int n,sum1=0,sum2=0;
  8. string s;
  9. int main()
  10. {
  11. cin>>n;
  12. cin>>s;
  13. int flag=1;
  14. for (int i=0; i<n; i++)
  15. if (s[i]!='4' && s[i]!='7')
  16. {
  17. cout<<"NO"<<endl;
  18. return 0;
  19. }
  20. for (int i=0; i<n/2; i++)
  21. sum1+=(s[i]-'0');
  22. //cout<<sum1<<endl;
  23. for (int i=n-1; i>=n/2; i--)
  24. sum2+=(s[i]-'0');
  25. //cout<<sum2<<endl;
  26. if (sum1!=sum2) cout<<"NO"<<endl;
  27. else cout<<"YES"<<endl;
  28. return 0;
  29. }

题目10: Lucky Mask

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是给定a,b,要求比a大的其中幸运数包含b的最小那个数。(具体看题目有数字的部分吧。。。)

分析:这可难倒了本萌妹了。但就在本萌妹晚上卸妆的时候突然灵光一现!其实只要让一个数从a开始滚,然后用一个k记录这个数中的幸运数是什么,当k==b的时候就找到了。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cmath>
  5. #include<algorithm>
  6. using namespace std;
  7. long long a,b,ans,k,q,ans1;
  8. int main()
  9. {
  10. cin>>a>>b;
  11. ans1=a+1;
  12. while (k!=b)
  13. {
  14. k=0;
  15. q=1;
  16. ans=ans1;
  17. while (ans>0)
  18. {
  19. if (ans%10==4 || ans%10==7)
  20. {
  21. k+=q*(ans%10);
  22. q*=10;
  23. }
  24. ans/=10;
  25. }
  26. ans1++;
  27. }
  28. cout<<ans1-1<<endl;
  29. return 0;
  30. }

题目11:Insomnia cure

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是给4个数和一个k,看1~k中有几个数是这4个数中其中一个的倍数。

分析:暴力找呗,本萌妹都会做哼~

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<cstdlib>
  6. using namespace std;
  7. int a[10],d,j,ans;
  8. bool bo=false;
  9. int main()
  10. {
  11. for (int i=1; i<=4; i++)
  12. cin>>a[i];
  13. cin>>d;
  14. j=1;
  15. while (j<=d)
  16. {
  17. for (int i=1; i<=4; i++)
  18. if ((j%a[i]==0))
  19. {
  20. bo=true;
  21. }
  22. if (bo==true) ans++;
  23. //cout<<j<<" "<<bo<<endl;
  24. bo=false;
  25. j++;
  26. }
  27. cout<<ans<<endl;
  28. return 0;
  29. }

题目12:Division into Teams

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是给n个球员,分成两队,要满足题目给定的三个条件。输出的是球员的号数哦~

分析:这可难倒了本萌妹了。但就在本萌妹晚上画工程图的时候突然灵光一现!其实我们只需要标记下每个人的号数,然后按照他们的能力排个序,隔开相邻两个人分队即可。(我代码手打快排有问题求各位dalao们看了帮我优化一蛤)

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstdlib>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<vector>
  7. using namespace std;
  8. struct node
  9. {
  10. int v;
  11. int p;
  12. }a[100005];
  13. int n;
  14. bool cmp(node x,node y)
  15. {
  16. if (x.v==y.v) return x.p<y.p;
  17. else return x.v<y.v;
  18. }
  19. /*void qsort(int l,int r)
  20. {
  21. int l1=l,r1=r;
  22. bool flag=true;
  23. int q=a[l1].v,o=a[l1].p;
  24. while (l<r)
  25. {
  26. while (l<r && ((a[r].v>q) || (a[r].v==q && a[r].p>o)))
  27. {
  28. r--;
  29. flag=false;
  30. }
  31. a[l]=a[r];
  32. while (l<r && ((a[l].v<q) || (a[l].v==q && a[l].p<o)))
  33. {
  34. l++;
  35. flag=false;
  36. }
  37. a[r]=a[l];
  38. }
  39. a[l].v=q;
  40. a[l].p=o;
  41. //cout<<a[l].v<<" "<<a[l].p<<endl;
  42. if (!flag)
  43. {
  44. qsort(l1,l-1);
  45. qsort(l+1, r1);
  46. }
  47. }*/
  48. int main()
  49. {
  50. cin>>n;
  51. for (int i=1; i<=n; i++)
  52. {
  53. cin>>a[i].v;
  54. a[i].p=i;
  55. }
  56. sort(a+1,a+n+1,cmp);
  57. /*for (int i=1; i<=n; i+=1)
  58. cout<<a[i].v<<" ";
  59. cout<<endl;
  60. for (int i=1; i<=n; i+=1)
  61. cout<<a[i].p<<" ";
  62. cout<<endl;*/
  63. cout<<(n+1)/2<<endl;
  64. for (int i=1; i<=n; i+=2)
  65. cout<<a[i].p<<" ";
  66. cout<<endl;
  67. cout<<n/2<<endl;
  68. for (int i=2; i<=n; i+=2)
  69. cout<<a[i].p<<" ";
  70. return 0;
  71. }

题目13:Soft Drinking

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实各位dalao看看样例解释就能明白了。。这道题题意要这么讲清楚真的很难呐呐呐呐。。。

分析:这可难倒了本萌妹了。但就在本萌妹晚上写国二卷的时候突然灵光一现!其实就是个贪心。具体怎么贪心嘿嘿。。程序里有哟。

参考代码:

  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include<cstdlib>
  6. using namespace std;
  7. int n,k,l,c,d,p,nl,np,sum1,sum2,sum3,sum4,ans;
  8. int main()
  9. {
  10. cin>>n>>k>>l>>c>>d>>p>>nl>>np;
  11. sum1=(k*l)/nl;
  12. sum2=p/np;
  13. sum3=c*d;
  14. sum4=min(sum2,sum3);
  15. ans=min(sum1,sum4);
  16. ans/=n;
  17. cout<<ans<<endl;
  18. return 0;
  19. }

题目14:

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,其实就是n个人m科学科,只要这个人在某一学科成绩是所有人中最高的(可以相等),那这个人就是优秀的,判断有几个人是优秀的。

分析:这可难倒了本萌妹了。但就在本萌妹晚上抱果聚大腿的时候突然灵光一现!其实只要把每科需要达到优秀的成绩算出来,再把每个人的每科成绩拿来判断,要是有一个和最高分相等,那就标记为1。最后统计有多少1即可。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<cmath>
  6. using namespace std;
  7. int n,s,maxx,a[10005],ans,b[1005];
  8. char c;
  9. int main()
  10. {
  11. cin>>n>>s;
  12. for (int i=0; i<n; i++)
  13. {
  14. for(int j=0; j<s; j++)
  15. {
  16. cin>>c;
  17. a[i*s+j]=c-'0';
  18. }
  19. }
  20. for (int i=0; i<n; i++)
  21. b[i]=0;
  22. for (int i=0; i<s; i++)
  23. {
  24. maxx=0;
  25. for(int j=0; j<n; j++)
  26. {
  27. maxx=max(maxx,a[j*s+i]);
  28. }
  29. for(int j=0; j<n; j++)
  30. {
  31. if (a[j*s+i]==maxx) b[j]=1;
  32. }
  33. }
  34. //for (int i=0; i<n; i++) cout<<b[i]<<" ";
  35. //cout<<endl;
  36. for (int j=0; j<n; j++)
  37. {
  38. ans+=b[j];
  39. }
  40. cout<<ans<<endl;
  41. return 0;
  42. }

题目15

题意:这是一道难度极大的题。本萌妹苦思冥想许久才明白这道题要我做什么,给定一个矩形大小和起始位置,给定一个k和k个向量,每个向量走到不能走为止,求最后走了几步。

分析:这可难倒了本萌妹了。但就在本萌妹晚上睡觉睡到一半的时候突然灵光一现!每个向量都判断走多少步出边界,依次判断最大步数即可。

参考代码:

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<cstdlib>
  6. using namespace std;
  7. long long n,m,x,y,k,dx,dy,sum,ans,xx=1000000000,yy=1000000000;
  8. int main()
  9. {
  10. cin>>n>>m>>x>>y>>k;
  11. while (k>0)
  12. {
  13. xx=1000000000;
  14. yy=1000000000;
  15. cin>>dx>>dy;
  16. if (dx>0) xx=(n-x)/dx;
  17. else
  18. if (dx<0) xx=(x-1)/(-dx);
  19. if (dy>0) yy=(m-y)/dy;
  20. else
  21. if (dy<0) yy=(y-1)/(-dy);
  22. if (xx<yy) sum=xx; else sum=yy;
  23. x+=dx*sum;
  24. y+=dy*sum;
  25. //cout<<x<<" "<<y<<endl;
  26. ans+=sum;
  27. k--;
  28. }
  29. cout<<ans<<endl;
  30. return 0;
  31. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注