l63t89 发表于 2021-1-28 22:35

灵动集训第三天

A题 Birthday Cake

l63t89 发表于 2021-1-28 22:36

思考过程
简单的计算题,先分三类,樱桃在切的线上方、下方和在线上。然后在500的范围内枚举再输出就可以了。

l63t89 发表于 2021-1-28 22:37

源代码
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node
{
    int x;
    int y;
}q;
int n;
int main()
{
    int m,i,j,k,sum1,sum2,flag;
    while(scanf("%d",&n)!=EOF)
    {
      if(n==0)
      {
            break;
      }
      m=n;
      n=n*2;
      for(i=0;i<n;i++)
      {
            scanf("%d%d",&q.x,&q.y);
      }
      sum1=0;
      sum2=0;
      flag=0;
      for(i=-500;i<=500;i++)
      {
            for(j=-500;j<=500;j++)
            {
                if(i==0&&j==0)
                {
                  continue;
                }
                sum1=0;
                sum2=0;
                for(k=0;k<2*n;k++)
                {
                  if((i*q.x+j*q.y)>0)
                  {
                        sum1++;
                  }
                  else if((i*q.x+j*q.y)<0)
                  {
                        sum2++;
                  }
                  else
                  {
                        break;
                  }
                }
                if(sum1==sum2&&sum1==m)
                {
                  printf("%d %d\n",i,j);
                  flag=1;
                  break;
                }
            }
            if(flag==1)
            {
                break;
            }
      }
    }
    return 0;
}

l63t89 发表于 2021-1-28 22:37

B题 Is This Integration ?

l63t89 发表于 2021-1-28 22:39

思考过程如图,先求Z,再求Y,再求X。

l63t89 发表于 2021-1-28 22:40

源代码
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#define Pi acos(-1)
using namespace std;
int main()
{
        double a;
        while (~scanf("%lf",&a))
        {
                double s=0,x,y,z;
                s=sqrt(3.0)*a*a/4.0+Pi*a*a/6.0;
                z=4*(a*a-s);
                y=4*(a*a-Pi*a*a/4-z/2);
                x=a*a-z-y;
                printf("%.3lf %.3lf %.3lf\n",x,y,z);
        }
        return 0;
}

l63t89 发表于 2021-1-28 22:41

遇到问题
数学公式都快忘完了。

l63t89 发表于 2021-1-28 22:41

C题 Simple division

l63t89 发表于 2021-1-28 22:42

思考过程
依旧没听懂,代码直接上网搜的。

l63t89 发表于 2021-1-28 22:42

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>

using namespace std;

long long save;

int main()
{
        int count;
        while (cin >> save && save) {
                count ++;
                while (cin >> save && save)
                        count ++;
                       
                sort(save, save+count);
                int s = save-save;
                for (int i = 1 ; i < count ; ++ i)
                        if (save > save && save-save < s)
                                s = save-save;
               
                for (int i = 1 ; i <= s ; ++ i)
                        if (s%i == 0) {
                                int d = s/i,r = (save%d+d)%d,flag = 1;
                                for (int j = 1 ; j < count ; ++ j)
                                        if ((save%d+d)%d != r) {
                                                flag = 0;
                                                break;
                                        }
                                if (flag) {
                                        cout << d << endl;
                                        break;
                                }
                        }
        }
        return 0;
}

l63t89 发表于 2021-1-28 22:46

遇到问题
不会做。

l63t89 发表于 2021-1-28 22:47

D题 Euclid Problem

l63t89 发表于 2021-1-28 22:47

思考过程
求AX+BY=d的题,刚开始没懂,后来上网搜了一下,是欧几里得算法,看完解析后理解了。

l63t89 发表于 2021-1-28 22:48

源代码
#include<iostream>
#include<algorithm>
using namespace std;
int exct_gcd(int a,int b,int& x,int& y)
{
        if(!b)
        {
                x=1;
                y=0;
          return a;
    }
       int d=exct_gcd(b,a%b,y,x);
       y-=a/b*x;
       return d;
}
int main(){
        int a,b;
        while(cin>>a>>b)
        {
                int x=0,y=0;
                int d=exct_gcd(a,b,x,y);
                cout<<x<<" "<<y<<" "<<d<<endl;
        }
}

l63t89 发表于 2021-1-28 22:49

遇到问题
经验少,没有遇到过此类题型。

l63t89 发表于 2021-1-28 22:50

E题 Dead Fraction

l63t89 发表于 2021-1-28 22:50

l63t89 发表于 2021-1-28 22:51

思考过程
还不会做。

l63t89 发表于 2021-1-28 22:52

源代码
#include <cstdio>
#include <iostream>
#include <string>
#define in std::cin
#define out std::cout
#define string std::string
typedef long long ll;
ll z = {1};
string s;
void pre()
{
for (int i = 1; i <= 10; ++i)
{
z = (z<<3) + (z<<1);
}
}
ll gcd(ll a, ll b)
{
ll c;
while (b)
{
c = a % b;
a = b;
b = c;
} return a;
}
int main()
{
pre();
while ((in >> s) && s.size() > 1)
{
ll num = 0;
ll b = 0;
for (int i = 2; s != '.'; ++i)
{
num = num*10 + s-'0';
b++;
E - Dead Fraction.md 2021/1/20
3 / 3
}
ll minfz = -1;
ll minfm = -1;
ll fz, fm;
for (int i = 1; i <= b; ++i)
{
fz = num - num/z;
fm = (z-1) * (z);
ll g = gcd(fz, fm)
if (fm/g<minfm || minfm==-1)
{
minfz = fz / g;
minfm = fm / g;
}
}
printf("%lld/%lld\n", minfz, minfm);
}
return 0;
}

l63t89 发表于 2021-1-28 22:54

遇到问题
不会做。
页: [1] 2
查看完整版本: 灵动集训第三天