Codeforces 简称CF,也是一个编程做题的网站。大概每周会出一次题。
由于时差的关系,我们这一般是半夜。
今天0:30,我开始了我的第一次CF之旅
CF每个用户会有一个Rating,默认1500,每次比赛完根据结果计算,如果到达1700,就可以参加Div.1的比赛。由于我第一次参赛,还是只能打Div.2,很惭愧,做了三道水题。
一共六道题,有一道事后看别人代码发现自己考虑简单了,估计是太晚了,脑子短路了。
顺便一提,CF有一个好处就是在CF里比赛结束其他人的代码都是公开的,这样就可以直接学习世界各地人的优秀代码。
还有一题,感觉也是水题,不过还是WA了,可能题目理解错了。
最后一题没空看了。
最后终于提高了35分,尴尬。
—以下是水题的题解—
A题
http://codeforces.com/problemset/problem/734/A
输入一个字符串,有A有D,然后统计AD个数,看情况输出
这个居然WA了一次,可能是我没有scanf(“%d\n”) 忘记\n了,并且一开始以为不是多组数据
现在也不知道,不过就按照多组数据来写吧,毕竟ICPC是多组数据
code
#define LOG(x) cout << #x << " = " << (x) << endl
#define PRINTLN(x) cout << (x) << endl
#define MEM(x, y) memset((x), (y), sizeof((x)))
#include <bits/stdc++.h>
using namespace std;
const double PI = 2*acos(0);
typedef long long ll;
typedef complex<double> Complex;
int nextInt()
{
int x;
scanf("%d", &x);
return x;
}
ll nextLL()
{
ll x;
scanf("%lld", &x);
return x;
}
//TEMPLATE
//MAIN
int main()
{
//freopen("in.txt", "r", stdin);
int n;
while (scanf("%d\n", &n) != EOF) {
int a = 0, d = 0;
while (n--) {
char ch;
scanf("%c", &ch);
if (ch == 'A') a++;
if (ch == 'D') d++;
}
scanf("\n");
if (a > d) puts("Anton");
if (a < d) puts("Danik");
if (a == d) puts("Friendship");
}
}
这里不得不提CF交题是按照文件来交的,和ICPC一样,感觉非常好
B题
http://codeforces.com/problemset/problem/734/B
告诉你2 3 5 6 数码的个数
然后用来组成 256 和 32 问怎么组合最大
贪心,肯定先组256,剩下不行再组32
#define LOG(x) cout << #x << " = " << (x) << endl
#define PRINTLN(x) cout << (x) << endl
#define MEM(x, y) memset((x), (y), sizeof((x)))
#include <bits/stdc++.h>
using namespace std;
const double PI = 2*acos(0);
typedef long long ll;
typedef complex<double> Complex;
int nextInt()
{
int x;
scanf("%d", &x);
return x;
}
ll nextLL()
{
ll x;
scanf("%lld", &x);
return x;
}
//TEMPLATE
//MAIN
int k2, k3, k5, k6;
void solve()
{
ll ans = 0;
int t = min(k2, min(k5, k6));
ans += (t * 256);
k2 -= t;
ans += (min(k2, k3) * 32);
cout << ans << endl;
}
int main()
{
//freopen("in.txt", "r", stdin);
while (scanf("%d%d%d%d", &k2, &k3, &k5, &k6) != EOF) {
solve();
}
}
D题
http://codeforces.com/problemset/problem/734/D
这个稍微有点难度,相比较而言
一个无限大的棋盘,有一个King,旁边有Queen,Rider,Bishop
由于ACM很喜欢和国际象棋打交道,所以大家都知道了这些棋子的走法
Queen 横竖斜都行
Rider 横竖
Bishop 斜
但是中间隔着子的话就不能直接Checkmate了
然后问有没有Checkmate
只要记录King周围8个方向离它最近的棋子是哪个,最后判断一下
#define LOG(x) cout << #x << " = " << (x) << endl
#define PRINTLN(x) cout << (x) << endl
#define MEM(x, y) memset((x), (y), sizeof((x)))
#include <bits/stdc++.h>
using namespace std;
const double PI = 2*acos(0);
typedef long long ll;
typedef complex<double> Complex;
int nextInt()
{
int x;
scanf("%d", &x);
return x;
}
ll nextLL()
{
ll x;
scanf("%lld", &x);
return x;
}
//TEMPLATE
//MAIN
const int INF = INT_MAX / 2;
int n;
struct V
{
char c;
int x, y;
V(){}
V(char c, int x, int y) : c(c), x(x), y(y) {}
};
const int MAXN = 5e5 + 9;
void solve()
{
int x0, y0;
scanf("%d%d\n", &x0, &y0);
V a[8]; //╢сио©╙й╪
a[0].y = INF;
a[1].x = INF, a[1].y = INF;
a[2].x = INF;
a[3].x = INF, a[3].y = -INF;
a[4].y = -INF;
a[5].x = -INF, a[5].y = -INF;
a[6].x = -INF;
a[7].x = -INF, a[7].y = INF;
for (int i = 0; i < n; i++) {
char c;
int x, y;
scanf("%c %d %d\n", &c, &x, &y);
V v(c, x, y);
if (x == x0 && y > y0 && y < a[0].y) a[0] = v; else // 0
if (x > x0 && y > y0 && x - x0 == y - y0 && x < a[1].x && y < a[1].y) a[1] = v; else // 1
if (y == y0 && x > x0 && x < a[2].x) a[2] = v; else // 2
if (x > x0 && y < y0 && x - x0 == y0 - y && x < a[3].x && y > a[3].y) a[3] = v; else // 3
if (x == x0 && y < y0 && y > a[4].y) a[4] = v; else // 4
if (x < x0 && y < y0 && x0 - x == y0 - y && x > a[5].x && y > a[5].y) a[5] = v; else // 5
if (y == y0 && x < x0 && x > a[6].x) a[6] = v; else // 6
if (x < x0 && y > y0 && x0 - x == y - y0 && x > a[7].x && y < a[7].y) a[7] = v; // 7
}
for (int i = 0; i < 8; i++) {
if (a[i].c == 'Q') {
puts("YES");
return;
} else
if (i % 2 == 0 && a[i].c == 'R') {
puts("YES");
return;
} else
if (i % 2 == 1 && a[i].c == 'B') {
puts("YES");
return;
}
}
puts("NO");
}
int main()
{
//freopen("in.txt", "r", stdin);
while (scanf("%d", &n) != EOF) {
solve();
}
}
之一,完。
下一章将讲解本次比赛没有AC的三道题,敬请期待!