[其他] 灵动集训第二天

[复制链接]
740|7
 楼主| l63t89 发表于 2021-1-28 22:23 | 显示全部楼层 |阅读模式
集训第二天
A题

  1. #include<stdio.h>
  2. #include<string.h>
  3. #define maxn 1000
  4. char a[19][30]={“pop”,“no”,“zip”,“zotz”,“tzec”,“xul”,“yoxkin”,“mol”,“chen”,“yax”,“zac”,“ceh”,“mac”,“kankin”,“muan”,“pax”,“koyab”,“cumhu”,“uayet”};
  5. char b[20][30]={“imix”,“ik”,“akbal”,“kan”,“chicchan”,“cimi”,“manik”,“lamat”,“muluk”,“ok”,“chuen”,“eb”,“ben”,“ix”,“mem”,“cib”,“caban”,“eznab”,“canac”,“ahau”};
  6. int FindMonth(char M[])
  7. {
  8. int i;
  9. for(i=0;i<19;i++)
  10. if(strcmp(M,a[i])==0)
  11. break;
  12. return i;
  13. }
  14. int main()
  15. {
  16. int n;
  17. scanf("%d",&n);
  18. printf("%d\n",n);
  19. for(;n>0;n–)
  20. {
  21. int M,D,Y,days=0;
  22. char s[20];
  23. scanf("%d. %s %d",&D,s,&Y);
  24. M=FindMonth(s);
  25. days=Y365+M20+D;
  26. Y=days/(1320);
  27. days%=(1320);
  28. printf("%d %s %d\n",days%13+1,b[days%20],Y);
  29. }
  30. return 0;
  31. }

害挺简单,感觉还行,主要就是打的字太多,于是我就复制粘贴,哈哈。

 楼主| l63t89 发表于 2021-1-28 22:26 | 显示全部楼层
B题
  1. #include<stdio.h>
  2. #include<string.h>
  3. struct Point
  4. {
  5. double x;
  6. double y;
  7. }g[1005];
  8. int main()
  9. {
  10. int n,i;
  11. while(scanf("%d",&n)1)
  12. {
  13. for(i=0;i<n;++i)
  14. scanf("%lf %lf",&g[i].x,&g[i].y);
  15. g[n]=g[0];
  16. printf("%d “,n);
  17. for(i=0;i<n;++i)
  18. printf(”%.6lf %.6lf “,(g[i].x+g[i+1].x)/2,(g[i].y+g[i+1].y)/2);
  19. printf(”\n");
  20. }
  21. return 0;
  22. }

这题就是简单的数学计算,主要是学习用结构体表示坐标。
 楼主| l63t89 发表于 2021-1-28 22:26 | 显示全部楼层
C题
  1. #include
  2. using namespace std;
  3. char s[55][55][55];
  4. int pre[55], last[55], mp[55], sum[55], ans[55];
  5. int getp3(int x) {
  6. int p1 = pre[x], p2 = pre[p1], p3 = pre[p2];
  7. return p3;
  8. }
  9. int getp1(int x) {
  10. int p1 = pre[x];
  11. return p1;
  12. }
  13. int main() {
  14. while(1) {
  15. scanf("%s", s[1][1]);
  16. if(s[1][1][0] == ‘#’) break;
  17. last[1] = 2; sum[1] = 1; last[0] = 1;
  18. for(int i = 2; i <= 52; i++) {
  19. scanf("%s", s[i][1]);
  20. pre[i] = i - 1;
  21. last[i] = i + 1;
  22. sum[i] = 1;
  23. }
  24. for(int i = 2; i <= 52; i = last[i]) {
  25. int p = getp3(i);
  26. if(p > 0 && (s[p][sum[p]][0] == s[i][sum[i]][0] || s[p][sum[p]][1]
  27. == s[i][sum[i]][1])) {
  28. sum[p]++;
  29. s[p][sum[p]][0] = s[i][sum[i]][0];
  30. s[p][sum[p]][1] = s[i][sum[i]][1];
  31. sum[i]–;
  32. if(sum[i] == 0) {
  33. last[pre[i]] = last[i];
  34. pre[last[i]] = pre[i];
  35. }
  36. i = p - 1;
  37. continue;
  38. }
  39. p = getp1(i);
  40. if(p > 0 && (s[p][sum[p]][0] == s[i][sum[i]][0] || s[p][sum[p]][1]
  41. == s[i][sum[i]][1])) {
  42. sum[p]++;
  43. s[p][sum[p]][0] = s[i][sum[i]][0];
  44. s[p][sum[p]][1] = s[i][sum[i]][1];
  45. sum[i]–;
  46. if(sum[i] == 0) {
  47. last[pre[i]] = last[i];
  48. pre[last[i]] = pre[i];
  49. }
  50. i = p - 1;
  51. continue;
  52. }
  53. }
  54. int cnt = 0;
  55. for(int i = 1; i <= 52; i++) {
  56. if(sum[i]) ans[cnt++] = sum[i];
  57. }
  58. printf("%d piles remaining: %d", cnt, ans[0]);
  59. for(int i = 1; i < cnt; i++) {
  60. printf(" %d", ans[i]);
  61. }
  62. printf("\n");
  63. }
  64. return 0;
  65. }

这题好难哦,要用数组代替链表,还是不太清楚,得再揣摩揣摩。
 楼主| l63t89 发表于 2021-1-28 22:27 | 显示全部楼层
D题

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. string str,ans;
  4. int Nex[100010];
  5. void solve(){
  6. int pos = 0,ls = 0;
  7. Nex[0] = 0; str = “#” + str;
  8. for(int i = 1; str[i]; i++){
  9. if(str[i] == ‘[’) pos = 0;
  10. else if(str[i] == ‘]’) pos = ls;
  11. else{
  12. Nex[i] = Nex[pos];
  13. Nex[pos] = i;
  14. if(pos == ls) ls = i;
  15. pos = i;
  16. }
  17. }
  18. for(int i = Nex[0]; i;i = Nex[i])
  19. cout << str[i];
  20. cout << endl;
  21. }
  22. int main(){
  23. while(getline(cin,str)){
  24. for(int i = 1;i <= 10;i++);
  25. solve();
  26. }
  27. return 0;
  28. }

这题也是数组代替链表,有点玄乎,得揣摩揣摩。
 楼主| l63t89 发表于 2021-1-28 22:28 | 显示全部楼层
E题

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4. #include<string.h>
  5. int main()
  6. {
  7. double s,a,ang,arc,cho;
  8. char c[5];
  9. while(scanf("%lf %lf %s",&s,&a,c)!=EOF)
  10. {
  11. if(strcmp(c,“min”)0)
  12. a=a/60;
  13. if(a>180)a=360-a;
  14. ang=aacos(-1.0)/180.0;
  15. arc=2.0(s+6440.0)sin(ang/2.0);
  16. cho=ang(s+6440.0);
  17. printf("%.6lf %.6lf\n",cho,arc);
  18. }
  19. return 0;
  20. }

重点在于数学计算,解决了数学计算代码就比较好打了。
 楼主| l63t89 发表于 2021-1-28 22:29 | 显示全部楼层
F题

  1. #include
  2. #include
  3. #include
  4. #include
  5. #include
  6. using namespace std;
  7. typedef long long ll;
  8. int sgn(double x)
  9. {
  10. if(fabs(x) < 0.00000001) return 0;
  11. else return x < 0 ? -1 : 1;
  12. }
  13. struct Point{
  14. double x, y;
  15. Point(){}
  16. Point(double _x, double _y){
  17. x = _x, y = _y;
  18. }
  19. bool operator == (Point b) const{
  20. return sgn(x - b.x) == 0 && sgn(y - b.y) == 0;
  21. }
  22. bool operator < (Point b)const{
  23. return sgn(x - b.x) == 0 ? sgn(y - b.y < 0) : x < b.x;
  24. }
  25. Point operator - (const Point &b)const{
  26. return Point(x - b.x, y - b.y);
  27. }
  28. double operator ^(const Point &b){
  29. return x * b.y - y * b.x;
  30. }
  31. double operator (const Point &b){
  32. return x * b.x + y * b.y;
  33. }
  34. double len(){
  35. return hypot(x, y);
  36. }
  37. double len2(){
  38. return x * x + y * y;
  39. }
  40. double distant(Point p){
  41. return hypot(x - p.x, y - p.y);
  42. }
  43. Point operator + (const Point &b)const{
  44. return Point (x + b.x, y + b.y);
  45. }
  46. Point operator * (const double &k)const{
  47. return Point(x * k, y * k);
  48. }
  49. Point operator / (const double &k)const{
  50. return Point(x / k, y / k);
  51. }
  52. };
  53. int main()
  54. {
  55. double x1, x2, x3, x4, y1, y2, y3, y4;
  56. Point p[4], c;
  57. while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4))
  58. {
  59. p[0] = Point(x1,y1);
  60. p[1] = Point(x2,y2);
  61. p[2] = Point(x3,y3);
  62. p[3] = Point(x4,y4);
  63. sort(p , p + 4);
  64. if(p[0] == p[1])
  65. {
  66. c = p[2] + p[3] - p[1];
  67. }
  68. if(p[1] == p[2])
  69. {
  70. c = p[0] + p[3] - p[1];
  71. }
  72. if(p[2] == p[3])
  73. {
  74. c = p[1] + p[0] - p[3];
  75. }
  76. printf("%.3f %.3f\n",c.x, c.y);
  77. }
  78. return 0;
  79. }

重点仍在于数学计算,已知平行四边形三个点计算余下一点的坐标,这是今天第N次卡在了数学上。
 楼主| l63t89 发表于 2021-1-28 22:30 | 显示全部楼层
G题

  1. #include<stdio.h>
  2. #include<math.h>
  3. int main()
  4. {
  5. double x1,y1,x2,y2,x3,y3;
  6. double a,b,c,p,s,d,l;
  7. while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF)
  8. {
  9. a=sqrt((x1-x2)(x1-x2)+(y1-y2)(y1-y2));
  10. b=sqrt((x1-x3)(x1-x3)+(y1-y3)(y1-y3));
  11. c=sqrt((x2-x3)(x2-x3)+(y2-y3)(y2-y3));
  12. p=(a+b+c)/2;
  13. s=sqrt(p(p-a)(p-b)(p-c));
  14. d=(abc)/(2s);
  15. l=d3.141592653589793;
  16. printf("%.2lf\n",l);
  17. }
  18. }

简单的让我怀疑是不是做错了。
 楼主| l63t89 发表于 2021-1-28 22:31 | 显示全部楼层
H题

  1. #include
  2. #include
  3. #include
  4. using namespace std;
  5. double a1,b1,a2,b2,d,r=6875/2.0;
  6. char s[99];
  7. int Get()
  8. {
  9. int a=0;
  10. char c;
  11. while((c=getchar())<‘0’||c>‘9’);
  12. for(;c>=‘0’&&c<=‘9’;c=getchar())a=a*10+c-‘0’;
  13. return a;
  14. }
  15. void GetA(double &a)
  16. {
  17. a=Get()+Get()/60.0+Get()/3600.0;
  18. scanf("%s",s);
  19. if(s[0]‘S’||s[0]‘W’)a=-a;
  20. a=aacos(-1.0)/180;
  21. }
  22. int main()
  23. {
  24. while(gets(s),s[0]!=’=’)
  25. {
  26. GetA(a1),GetA(a1),GetA(b1),GetA(a2),GetA(b2);
  27. d=racos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2));
  28. printf(“The distance to the iceberg: %.2lf miles.\n”,d);
  29. if(floor(d+0.005)<100)puts(“DANGER!”);
  30. gets(s);
  31. }
  32. return 0;
  33. }

这题直接把人搞懵圈,想了半天才发现是求两点的距离,输入只是让人加一个遇到等号停止的函数。
结语:自己看了一点C++,现在勉强能看懂源代码了,感觉有了一点进步。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

101

主题

1077

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部