[其他] 灵动集训第三天

[复制链接]
2267|39
 楼主| l63t89 发表于 2021-1-28 22:35 | 显示全部楼层 |阅读模式
AC, hd
A题 Birthday Cake 758766012cbaa5e196.png

 楼主| l63t89 发表于 2021-1-28 22:36 | 显示全部楼层
思考过程
简单的计算题,先分三类,樱桃在切的线上方、下方和在线上。然后在500的范围内枚举再输出就可以了。
 楼主| l63t89 发表于 2021-1-28 22:37 | 显示全部楼层
源代码
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. struct node
  5. {
  6.     int x;
  7.     int y;
  8. }q[201];
  9. int n;
  10. int main()
  11. {
  12.     int m,i,j,k,sum1,sum2,flag;
  13.     while(scanf("%d",&n)!=EOF)
  14.     {
  15.         if(n==0)
  16.         {
  17.             break;
  18.         }
  19.         m=n;
  20.         n=n*2;
  21.         for(i=0;i<n;i++)
  22.         {
  23.             scanf("%d%d",&q[i].x,&q[i].y);
  24.         }
  25.         sum1=0;
  26.         sum2=0;
  27.         flag=0;
  28.         for(i=-500;i<=500;i++)
  29.         {
  30.             for(j=-500;j<=500;j++)
  31.             {
  32.                 if(i==0&&j==0)
  33.                 {
  34.                     continue;
  35.                 }
  36.                 sum1=0;
  37.                 sum2=0;
  38.                 for(k=0;k<2*n;k++)
  39.                 {
  40.                     if((i*q[k].x+j*q[k].y)>0)
  41.                     {
  42.                         sum1++;
  43.                     }
  44.                     else if((i*q[k].x+j*q[k].y)<0)
  45.                     {
  46.                         sum2++;
  47.                     }
  48.                     else
  49.                     {
  50.                         break;
  51.                     }
  52.                 }
  53.                 if(sum1==sum2&&sum1==m)
  54.                 {
  55.                     printf("%d %d\n",i,j);
  56.                     flag=1;
  57.                     break;
  58.                 }
  59.             }
  60.             if(flag==1)
  61.             {
  62.                 break;
  63.             }
  64.         }
  65.     }
  66.     return 0;
  67. }
 楼主| l63t89 发表于 2021-1-28 22:37 | 显示全部楼层
B题 Is This Integration ? 423276012cc42a22fe.png
 楼主| l63t89 发表于 2021-1-28 22:39 | 显示全部楼层
思考过程 641786012cca4b11bb.png 如图,先求Z,再求Y,再求X。
 楼主| l63t89 发表于 2021-1-28 22:40 | 显示全部楼层
源代码
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. #include <iostream>
  5. #include <cmath>
  6. #include <algorithm>
  7. #define Pi acos(-1)
  8. using namespace std;
  9. int main()
  10. {
  11.         double a;
  12.         while (~scanf("%lf",&a))
  13.         {
  14.                 double s=0,x,y,z;
  15.                 s=sqrt(3.0)*a*a/4.0+Pi*a*a/6.0;
  16.                 z=4*(a*a-s);
  17.                 y=4*(a*a-Pi*a*a/4-z/2);
  18.                 x=a*a-z-y;
  19.                 printf("%.3lf %.3lf %.3lf\n",x,y,z);
  20.         }
  21.         return 0;
  22. }
 楼主| l63t89 发表于 2021-1-28 22:41 | 显示全部楼层
遇到问题
数学公式都快忘完了。
 楼主| l63t89 发表于 2021-1-28 22:41 | 显示全部楼层
C题 Simple division
54416012cd0d65b7d.png
 楼主| l63t89 发表于 2021-1-28 22:42 | 显示全部楼层
思考过程
依旧没听懂,代码直接上网搜的。
 楼主| l63t89 发表于 2021-1-28 22:42 | 显示全部楼层
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <cmath>

  6. using namespace std;

  7. long long save[1001];

  8. int main()
  9. {
  10.         int count;
  11.         while (cin >> save[count=0] && save[count]) {
  12.                 count ++;
  13.                 while (cin >> save[count] && save[count])
  14.                         count ++;
  15.                        
  16.                 sort(save, save+count);
  17.                 int s = save[count-1]-save[0];
  18.                 for (int i = 1 ; i < count ; ++ i)
  19.                         if (save[i] > save[i-1] && save[i]-save[i-1] < s)
  20.                                 s = save[i]-save[i-1];
  21.                
  22.                 for (int i = 1 ; i <= s ; ++ i)
  23.                         if (s%i == 0) {
  24.                                 int d = s/i,r = (save[0]%d+d)%d,flag = 1;
  25.                                 for (int j = 1 ; j < count ; ++ j)
  26.                                         if ((save[j]%d+d)%d != r) {
  27.                                                 flag = 0;
  28.                                                 break;
  29.                                         }
  30.                                 if (flag) {
  31.                                         cout << d << endl;
  32.                                         break;
  33.                                 }
  34.                         }
  35.         }
  36.         return 0;
  37. }
 楼主| l63t89 发表于 2021-1-28 22:46 | 显示全部楼层
遇到问题
不会做。
 楼主| l63t89 发表于 2021-1-28 22:47 | 显示全部楼层
D题 Euclid Problem
432176012ce615b832.png
 楼主| l63t89 发表于 2021-1-28 22:47 | 显示全部楼层
思考过程
求AX+BY=d的题,刚开始没懂,后来上网搜了一下,是欧几里得算法,看完解析后理解了。

 楼主| l63t89 发表于 2021-1-28 22:48 | 显示全部楼层
源代码
  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. int exct_gcd(int a,int b,int& x,int& y)
  5. {
  6.         if(!b)
  7.         {
  8.                 x=1;
  9.                 y=0;
  10.             return a;
  11.     }
  12.          int d=exct_gcd(b,a%b,y,x);
  13.          y-=a/b*x;
  14.          return d;
  15. }
  16. int main(){
  17.         int a,b;
  18.         while(cin>>a>>b)
  19.         {
  20.                 int x=0,y=0;
  21.                 int d=exct_gcd(a,b,x,y);
  22.                 cout<<x<<" "<<y<<" "<<d<<endl;
  23.         }
  24. }
 楼主| l63t89 发表于 2021-1-28 22:49 | 显示全部楼层
遇到问题
经验少,没有遇到过此类题型。
 楼主| l63t89 发表于 2021-1-28 22:50 | 显示全部楼层
E题 Dead Fraction
371656012cf0277ac9.png
 楼主| l63t89 发表于 2021-1-28 22:50 | 显示全部楼层
 楼主| l63t89 发表于 2021-1-28 22:51 | 显示全部楼层
思考过程
还不会做。
 楼主| l63t89 发表于 2021-1-28 22:52 | 显示全部楼层
源代码
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <string>
  4. #define in std::cin
  5. #define out std::cout
  6. #define string std::string
  7. typedef long long ll;
  8. ll z[11] = {1};
  9. string s;
  10. void pre()
  11. {
  12. for (int i = 1; i <= 10; ++i)
  13. {
  14. z[i] = (z[i-1]<<3) + (z[i-1]<<1);
  15. }
  16. }
  17. ll gcd(ll a, ll b)
  18. {
  19. ll c;
  20. while (b)
  21. {
  22. c = a % b;
  23. a = b;
  24. b = c;
  25. } return a;
  26. }
  27. int main()
  28. {
  29. pre();
  30. while ((in >> s) && s.size() > 1)
  31. {
  32. ll num = 0;
  33. ll b = 0;
  34. for (int i = 2; s[i] != '.'; ++i)
  35. {
  36. num = num*10 + s[i]-'0';
  37. b++;
  38. E - Dead Fraction.md 2021/1/20
  39. 3 / 3
  40. }
  41. ll minfz = -1;
  42. ll minfm = -1;
  43. ll fz, fm;
  44. for (int i = 1; i <= b; ++i)
  45. {
  46. fz = num - num/z[i];
  47. fm = (z[i]-1) * (z[b-i]);
  48. ll g = gcd(fz, fm)
  49. if (fm/g<minfm || minfm==-1)
  50. {
  51. minfz = fz / g;
  52. minfm = fm / g;
  53. }
  54. }
  55. printf("%lld/%lld\n", minfz, minfm);
  56. }
  57. return 0;
  58. }
 楼主| l63t89 发表于 2021-1-28 22:54 | 显示全部楼层
遇到问题
不会做。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

101

主题

1077

帖子

1

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