题目链接https://qduoj.com/contest/28/problems,密码:qdu1230

E题:

思路:先进行排序,然后去暴力模拟就可以,但可能WA了几次,导致此题没解出来,有点可惜

代码:

  1. #include<cstdio>
  2. #include<algorithm>
  3. #include<cstring>
  4. #include<iostream>
  5. using namespace std;
  6. int a[3005];
  7. int b[3005];
  8. int main()
  9. {
  10. int n,m;
  11. cin>>n>>m;
  12. for(int t=0;t<n;t++)
  13. {
  14. scanf("%d",&a[t]);
  15. }
  16. for(int t=0;t<m;t++)
  17. {
  18. scanf("%d",&b[t]);
  19. }
  20. sort(a,a+n);
  21. sort(b,b+m);
  22. int ma=0,mb=0;
  23. int maxna=0;
  24. int maxnb=0;
  25. for(int t=0;t<n;t++)
  26. {
  27. for(int j=t;j<n;j++)
  28. {
  29. if(ma==5)
  30. {
  31. break;
  32. }
  33. if(a[j]-a[t]<=3)
  34. {
  35. ma++;
  36. }
  37. else
  38. {
  39. ma=0;
  40. break;
  41. }
  42. maxna=max(maxna,ma);
  43. if(j==n-1)
  44. {
  45. ma=0;
  46. }
  47. }
  48. }
  49. for(int t=0;t<m;t++)
  50. {
  51. for(int j=t;j<m;j++)
  52. {
  53. if(mb==5)
  54. {
  55. break;
  56. }
  57. if(b[j]-b[t]<=3)
  58. {
  59. mb++;
  60. }
  61. else
  62. {
  63. mb=0;
  64. break;
  65. }
  66. maxnb=max(maxnb,mb);
  67. if(j==m-1)
  68. {
  69. mb=0;
  70. }
  71. }
  72. }
  73. cout<<maxna<<endl;
  74. cout<<maxnb<<endl;
  75. if(maxna<=maxnb)
  76. {
  77. cout<<"liangliang\\O..o\\"<<endl;
  78. }
  79. else
  80. {
  81. cout<<"gg/o..O/"<<endl;
  82. }
  83. return 0;
  84. }

F题:

思路:首先对于题目的理解不能有错误,是进行任意轮的命令判断是否能到达,不是就执行那一轮命令,那我们不妨设进行了k轮,然后把每次的坐标变换记录,判断在k轮是否能到达,k的值为(a-每一次的变化量)/一轮的变换量

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<iostream>
  5. using namespace std;
  6. string str;
  7. struct node
  8. {
  9. int x,y;
  10. }pos[1005];
  11. int main()
  12. {
  13. int a,b;
  14. while(cin>>a>>b>>str)
  15. {
  16. int len=str.length();
  17. int x=0,y=0;
  18. int flag=0;
  19. if(x==a&&y==b)
  20. {
  21. cout<<"Yes"<<endl;
  22. continue;
  23. }
  24. for(int t=0;t<len;t++)
  25. {
  26. if(str[t]=='U')
  27. y++;
  28. if(str[t]=='D')
  29. y--;
  30. if(str[t]=='L')
  31. x--;
  32. if(str[t]=='R')
  33. x++;
  34. pos[t].x=x;
  35. pos[t].y=y;
  36. //cout<<pos[t].x<<" "<<pos[t].y<<endl;
  37. }
  38. int k;
  39. for(int t=0;t<len;t++)
  40. {
  41. if(x)
  42. {
  43. k=(a-pos[t].x)/x;
  44. }
  45. else if(y)
  46. {
  47. k=(b-pos[t].y)/y;
  48. }
  49. if(k<0)
  50. k=0;
  51. if(a==k*x+pos[t].x&&b==k*y+pos[t].y)
  52. {
  53. flag=1;
  54. break;
  55. }
  56. }
  57. if(flag)
  58. {
  59. cout<<"Yes"<<endl;
  60. }
  61. else
  62. {
  63. cout<<"No"<<endl;
  64. }
  65. }
  66. return 0;
  67. }

G题:G题看一下数据量就会明白暴力必然超时,那如何去解,我们可以进行分组枚举所有结果,然后,去另一个查找有多少个相等的。我们可以有1,4和2,3两种分法,我们看1,4也十分容易超时,故选用2,3,然后把所有的结果分别放在两个数组里。我们查找的时候用二分进行查找,故要先进行排序,然后我们在较小的里面找较大的,复杂度稍低,然后我们不应该是找是否存在,而应该找存在多少个,所以一个是找左边的下标,一个找右边的下标,这样一减就是个数。还有一个问题,就是开数组的大小,我一开始开的是1e6和1e4,但是会溢出,我就试着跑了下,一个在1e6+1e4左右,另一个没跑,直接就多开大算了。

代码:

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4. #include<cstring>
  5. using namespace std;
  6. int a[10400000];
  7. int b[14005];
  8. int k1,k2;
  9. // 查找第一个相等的元素
  10. int findFirstEqual(int a[], int key) {
  11. int left = 0;
  12. int right = k1 - 1;
  13. while (left <= right) {
  14. int mid = (left + right) / 2;
  15. if (a[mid] >= key) {
  16. right = mid - 1;
  17. }
  18. else {
  19. left = mid + 1;
  20. }
  21. }
  22. if (left < k1 && a[left] == key) {
  23. return left;
  24. }
  25. return -1;
  26. }
  27. // 查找最后一个相等的元素
  28. int findLastEqual(int a[], int key) {
  29. int left = 0;
  30. int right = k1- 1;
  31. while (left <= right) {
  32. int mid = (left + right) / 2;
  33. if (a[mid] <= key) {
  34. left = mid + 1;
  35. }
  36. else {
  37. right = mid - 1;
  38. }
  39. }
  40. if (right >= 0 && a[right] == key) {
  41. return right;
  42. }
  43. return -1;
  44. }
  45. int main()
  46. {
  47. int T;
  48. cin>>T;
  49. int x1,x2,x3,x4,x5;
  50. for(int t=0;t<T;t++)
  51. {
  52. k1=0;
  53. k2=0;
  54. scanf("%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5);
  55. for(int j1=-50;j1<=50;j1++)
  56. {
  57. for(int j2=-50;j2<=50;j2++)
  58. {
  59. for(int j3=-50;j3<=50;j3++)
  60. {
  61. if(j1==0||j2==0||j3==0)
  62. {
  63. continue;
  64. }
  65. a[k1++]=x1*j1*j1*j1+x2*j2*j2*j2+x3*j3*j3*j3;
  66. }
  67. }
  68. }
  69. for(int j1=-50;j1<=50;j1++)
  70. {
  71. for(int j2=-50;j2<=50;j2++)
  72. {
  73. if(j1==0||j2==0)
  74. {
  75. continue;
  76. }
  77. b[k2++]=x4*j1*j1*j1+x5*j2*j2*j2;
  78. }
  79. }
  80. sort(a,a+k1);
  81. int sum=0;
  82. for(int j=0;j<k2;j++)
  83. {
  84. int l,r;
  85. if(findFirstEqual(a,-b[j])!=-1&&findLastEqual(a,-b[j])!=-1)
  86. {
  87. l=findFirstEqual(a,-b[j]);
  88. r=findLastEqual(a,-b[j]);
  89. sum+=r-l+1;
  90. }
  91. }
  92. cout<<sum<<endl;
  93. }
  94. return 0;
  95. }

H题:是codeforce一道题的简化版,我的想法是去找原来的串,找原来的串可以通过最长的两个,和最短的两个来确定,通过拼接共有八中情况,由于题目说是有唯一存在,所以必然存在一种是两者相同的,这就是原来的串,找到原来的串,由于数据范围比较小,就可以暴力去找前缀和后缀了,标记一下,最后根据标记来判断前缀和后缀

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. using namespace std;
  6. string str[305];
  7. string s1[305],s2[305];
  8. int vis[305]={0};
  9. int main()
  10. {
  11. int n;
  12. cin>>n;
  13. for(int t=0;t<2*n-2;t++)
  14. {
  15. cin>>str[t];
  16. }
  17. string len1[2],len_n[2];
  18. int k1=0,k2=0;
  19. for(int t=0;t<2*n-2;t++)
  20. {
  21. if(str[t].length()==1)
  22. {
  23. len1[k1++]=str[t];
  24. }
  25. if(str[t].length()==n-1)
  26. {
  27. len_n[k2++]=str[t];
  28. }
  29. }
  30. string stand;
  31. string sss1[4],sss2[4];
  32. //八种情况
  33. sss1[0]=len1[0]+len_n[0];
  34. sss1[1]=len_n[0]+len1[0];
  35. sss1[2]=len1[1]+len_n[0];
  36. sss1[3]=len_n[0]+len1[1];
  37. sss2[0]=len1[0]+len_n[1];
  38. sss2[1]=len_n[1]+len1[0];
  39. sss2[2]=len1[1]+len_n[1];
  40. sss2[3]=len_n[1]+len1[1];
  41. for(int t=0;t<4;t++)
  42. {
  43. for(int j=0;j<4;j++)
  44. {
  45. if(sss1[t]==sss2[j])
  46. {
  47. stand=sss1[t];
  48. }
  49. }
  50. }
  51. // cout<<stand<<endl;
  52. string s[205];
  53. s[0]=stand[0];
  54. for(int t=1;t<n-1;t++)
  55. {
  56. s[t]=s[t-1]+stand[t];
  57. }
  58. for(int t=0;t<2*n-2;t++)
  59. {
  60. for(int j=0;j<n-1;j++)
  61. {
  62. if(str[t]==s[j])
  63. {
  64. vis[t]=1;
  65. }
  66. }
  67. }
  68. for(int t=0;t<2*n-2;t++)
  69. {
  70. if(vis[t]==1)
  71. {
  72. cout<<"P";
  73. }
  74. else
  75. {
  76. cout<<"S";
  77. }
  78. }
  79. cout<<endl;
  80. return 0;
  81. }

I题:

思路:狼和草是可以共存的群体,羊和狼草都不能共存,我们就可以分为两大阵营,羊,狼草,然后他们的存在状态总的有两种,一在岸上,一种是在船上,当小的等于d时,如果两大阵营的大的超过船的两倍载重,就会出现混的情况,就会混乱,故当小的等于d时,多的必须小于等于2*d,当小的小于d是时,可以不断的去运多的,就不必考虑多的数量,都可以运

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<algorithm>
  4. #include<iostream>
  5. using namespace std;
  6. int main()
  7. {
  8. int a,b,c,d;
  9. while(cin>>a>>b>>c>>d)
  10. {
  11. int maxn=max(a+c,b);
  12. int minn=min(a+c,b);
  13. if(minn==d&&maxn<=2*d||(minn<d))
  14. {
  15. cout<<"YES"<<endl;
  16. }
  17. else
  18. {
  19. cout<<"NO"<<endl;
  20. }
  21. }
  22. return 0;
  23. }

QDU第一届程序设计大赛——E到I题解法(非官方题解)的更多相关文章

  1. 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛

    "波导杯"安徽科技学院第七届程序设计大赛 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time:  2016-0 ...

  2. 2016 "Bird Cup" ICPC7th@ahstu--“波导杯”安徽科技学院第七届程序设计大赛

    "波导杯"安徽科技学院第七届程序设计大赛 原文章网页 Contest - 2016 "Bird Cup" ICPC7th@ahstu Start time:   ...

  3. 江西财经大学第一届程序设计竞赛 G题 小Q的口袋校园

    链接:https://www.nowcoder.com/acm/contest/115/G来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  4. “九韶杯”河科院程序设计协会第一届程序设计竞赛 D数列重组 next_permutation

    "九韶杯"河科院程序设计协会第一届程序设计竞赛 D数列重组  next_permutation 题目 原题链接: https://ac.nowcoder.com/acm/conte ...

  5. 哈理工软件学院"兆方美迪"杯第六届程序设计大赛【高年级组】--决赛 题解

    比赛链接:http://acm-software.hrbust.edu.cn/contest.php?cid=1082 A.好SB啊真是,还以为lis-数有多少个数不一样. #include < ...

  6. 江西财经大学第一届程序设计竞赛 F题 解方程

    链接:https://www.nowcoder.com/acm/contest/115/F来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  7. 江西财经大学第一届程序设计竞赛 H题 求大数的阶乘

    链接:https://www.nowcoder.com/acm/contest/115/H 来源:牛客网 晚上,小P喜欢在寝室里一个个静静的学习或者思考,享受自由自在的单身生活. 他总是能从所学的知识 ...

  8. “东信杯”广西大学第一届程序设计竞赛(同步赛)H

    链接:https://ac.nowcoder.com/acm/contest/283/H来源:牛客网 题目描述 由于临近广西大学建校90周年校庆,西大开始了喜闻乐见的校园修缮工程! 然后问题出现了,西 ...

  9. 江西财经大学第一届程序设计竞赛 I

    链接:https://www.nowcoder.com/acm/contest/115/I来源:牛客网 题目描述 小P和小Q是好朋友,今天他们一起玩一个有趣的游戏. 他们的初始积分都为1,赢的人可以将 ...

随机推荐

  1. CentOS Wifi Connection

    方法一: http://wiki.centos.org/HowTos/Laptops/WpaSupplicant http://www.cnblogs.com/tanghuimin0713/p/343 ...

  2. 实现远程连接MySQL

    首先登录远程服务器,然后登录mysql:mysql -u用户 -p密码; 创建允许远程登录的用户并赋权:grant all privileges on 数据库.表名 to 用户名@'IP地址' ide ...

  3. PyNLPIR python中文分词工具

    官网:https://pynlpir.readthedocs.io/en/latest/  github:https://github.com/tsroten/pynlpir          NLP ...

  4. HihoCoder1652 : 三角形面积和2([Offer收割]编程练习赛38)(几何)(不会几何,占位)

    描述 如下图所示,在X轴上方一共有N个三角形.这些三角形的底边与X轴重合,底边上两个顶点的坐标分别是(Li, 0)和(Ri, 0),底边的对顶点坐标是(Xi, Yi).其中Li ≤ Xi ≤ Ri 且 ...

  5. bzoj 1954 & poj 3764 The xor-longest Path dfs+Trie

    题目大意 给定一棵n个点的带权树,求树上最长的异或和路径 题解 因为\(xor\)操作满足可结合性,所以有 \(a\text{ }xor\text{ }b\text{ }xor\text{ }b = ...

  6. mysql基础itcast笔记

    1. 课程回顾 mysql基础 1)mysql存储结构: 数据库 -> 表 -> 数据   sql语句 2)管理数据库: 增加: create database 数据库 default c ...

  7. scores

    题意: m维偏序问题. 解法: 考虑对每一维按照每一个元素在这一维的数值分块,对于每一个块维护一个大小为 n 的bitset,表示前缀/后缀满足条件的元素集合. 对于每一个询问,我们可以枚举找到相应的 ...

  8. CF-822B

    B. Crossword solving time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. wireshark里无网络接口解决办法

    管理员模式下开启npf服务,该服务能捕获网络接口,net start npf

  10. ]Linq to EF 增删改查

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...