Codeforces Round #564 (Div. 2)

传送门

A. Nauuo and Votes

B. Nauuo and Chess

参考资料:

  [1]: the Chinese Editoria

A. Nauuo and Votes

题意:

  x个人投赞同票,y人投反对票,z人不确定;

  这 z 个人由你来决定是投赞同票还是反对票;

  判断 x 与 y 的相对大小是否确定?

题解:

  如果 x == y && z == 0,输出 '0';

  如果 x-y > z,输出 '+';

  如果 y-x > z,输出 '-';

  反之,输出 '?';

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define INF 0x3f3f3f3f
 4 #define ll long long
 5 #define mem(a,b) memset(a,b,sizeof(a))
 6 #define memF(a,b,n) for(int i=0;i <= n;a[i++]=b);
 7 const int maxn=1e3+50;
 8 
 9 int x,y,z;
10 
11 char *Solve()
12 {
13     if(x == y && z == 0)
14         return "0";
15     if(x-y > z)
16         return "+";
17     if(y-x > z)
18         return "-";
19     return "?";
20 }
21 int main()
22 {
23 //    freopen("C:\\Users\\hyacinthLJP\\Desktop\\in&&out\\contest","r",stdin);
24     scanf("%d%d%d",&x,&y,&z);
25     puts(Solve());
26 
27     return 0;
28 }
View Code

B. Nauuo and Chess

题意:

  给你 n 个棋子,求满足 "for all pairs of pieces i and j, |rirj|+|cicj≥ |i−j|."的最小的方形棋盘的列;

题解:

  方形棋盘的右下角(m,m)与左上角(1,1)的距离为 2×(m-1);

  ①找到 2×(m-1) ≥ n-1 的最小的 m;

  ②将 1~n-1 个棋子从第一行开始填充,第一行填充完,填充最后一列;

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define memF(a,b,n) for(int i=0;i <= n;a[i++]=b);
 4 #define INF 0x3f3f3f3f
 5 const int maxn=2e5+50;
 6 
 7 int n;
 8 
 9 void Solve()
10 {
11     int m=(n+2)/2;
12     printf("%d\n",m);
13     int x=1,y=1;
14     for(int i=1;i < n;++i)
15     {
16         printf("%d %d\n",x,y);
17         if(y < m)///先填充第一行
18             y++;
19         else
20             x++;
21     }
22     printf("%d %d\n",m,m);
23 }
24 int main()
25 {
26     scanf("%d",&n);
27     Solve();
28 
29     return 0;
30 }
View Code

猜你喜欢

转载自www.cnblogs.com/violet-acmer/p/10989957.html