Codeforces Round #432 (Div.2)

来源:互联网 发布:王尼玛 知乎 五五开 编辑:程序博客网 时间:2024/05/16 05:26

A.

题意:时刻1第一个人站立,时刻2第二个人站立,...,时刻k第k个人站立,k+1时刻第k+1个人站立第1个人坐下,...,n时刻第n个人站立第n-k个人坐下,...,n+k时刻第n个人坐下。问时刻t有多少人站立

样例解释 :n=10,k=5,t=3

  • At t = 0  ----------  number of standing spectators = 0.
  • At t = 1  ^---------  number of standing spectators = 1.
  • At t = 2  ^^--------  number of standing spectators = 2.
  • At t = 3  ^^^-------  number of standing spectators = 3.
  • At t = 4  ^^^^------  number of standing spectators = 4.
  • At t = 5  ^^^^^-----  number of standing spectators = 5.
  • At t = 6  -^^^^^----  number of standing spectators = 5.
  • At t = 7  --^^^^^---  number of standing spectators = 5.
  • At t = 8  ---^^^^^--  number of standing spectators = 5.
  • At t = 9  ----^^^^^-  number of standing spectators = 5.
  • At t = 10 -----^^^^^  number of standing spectators = 5.
  • At t = 11 ------^^^^  number of standing spectators = 4.
  • At t = 12 -------^^^  number of standing spectators = 3.
  • At t = 13 --------^^  number of standing spectators = 2.
  • At t = 14 ---------^  number of standing spectators = 1.
  • At t = 15 ----------  number of standing spectators = 0.

解题思路:直接找规律.0~k-1时刻,t个人站立;k~n时刻,k个人站立;n+1~n+k时刻,n+k-t个人站立

代码:

#include <iostream>#include <algorithm>#include <string>#include <cstring>#include <cmath>#include <cstdio>using namespace std;int main(){    int n,k,t;    while(scanf("%d%d%d",&n,&k,&t)==3)    {        if(t>=0&&t<=k-1)        {            printf("%d\n",t);        }        else if(t>=k&&t<=n)        {            printf("%d\n",k);        }        else if(t>=n+1&&t<=n+k)        {            printf("%d\n",n+k-t);        }    }    return 0;}

B.

题意:给三个点的坐标,判断是否存在一个旋转中心和一个旋转角度使得点a到点b的位置,点b到点c的位置

解题思路:先判断是否能组成三角形(也就是判断是否共线),然后判断只要边ab=bc即可。注意要用long long 

代码:

#include <iostream>#include <algorithm>#include <cstdio>#include <cmath>#include <cstring>#include <string>using namespace std;typedef long long ll;int main(){    ll ax,ay,bx,by,cx,cy;    while(cin>>ax>>ay>>bx>>by>>cx>>cy)    {        ll tx0=bx-ax,ty0=by-ay,tx1=cx-bx,ty1=cy-by;        ll ans1=(bx-ax)*(bx-ax)+(by-ay)*(by-ay);        ll ans2=(cx-bx)*(cx-bx)+(cy-by)*(cy-by);        if((tx0*ty1==tx1*ty0)||(ans1!=ans2))        {            cout<<"No"<<endl;        }        else cout<<"Yes"<<endl;    }    return 0;}



原创粉丝点击