标签:
这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了。
#include <bits/stdc++.h>
using namespace std;
#define lson l, mid, o << 1
#define rson mid + 1, r, o << 1 | 1
typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int main(void) {
int a, b, c;
int x, y, z;
scanf ("%d%d%d", &a, &b, &c);
scanf ("%d%d%d", &x, &y, &z);
bool flag = true;
if (a < x || b < y || c < z) flag = false;
int s1 = a + b + c;
int s2 = x + y + z;
if (flag) puts ("Yes");
else if (s1 < s2) puts ("No");
else {
int less = 0, more = 0;
if (a < x) less += x - a;
else {
more += (a - x) / 2;
}
if (b < y) less += y - b;
else {
more += (b - y) / 2;
}
if (c < z) less += z - c;
else {
more += (c - z) / 2;
}
if (more >= less) puts ("Yes");
else puts ("No");
}
return 0;
}
题意:机器人按照指令走,问有几个格子能使的在第i步使机器人爆炸。
分析:没什么难的,走过了就vis掉。比赛时C做的人多,B没读懂放弃了。。
#include <bits/stdc++.h>
using namespace std;
#define lson l, mid, o << 1
#define rson mid + 1, r, o << 1 | 1
typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
char str[N];
bool vis[505][505];
int ans[N];
int n, m, x, y;
int main(void) {
scanf ("%d%d%d%d", &n, &m, &x, &y);
scanf ("%s", str + 1);
int len = strlen (str + 1);
str[0] = ‘#‘; ans[len] = n * m;
for (int i=0; i<len; ++i) {
if (i != 0) {
if (str[i] == ‘U‘ && x > 1) x--;
else if (str[i] == ‘D‘ && x < n) x++;
else if (str[i] == ‘L‘ && y > 1) y--;
else if (str[i] == ‘R‘ && y < m) y++;
}
if (vis[x][y]) ans[i] = 0;
else {
vis[x][y] = true;
ans[i] = 1; ans[len]--;
}
}
for (int i=0; i<=len; ++i) {
printf ("%d%c", ans[i], i == len ? ‘\n‘ : ‘ ‘);
}
return 0;
}
构造+贪心 C - Sorting Railway Cars
题意:每一辆车可以去头或者尾,问最少几次能使排列有序
分析:贪心的思想,把相邻数字(LIS的不一定是相邻的,有问题)排列已经有序的不动,其他的都只要动一次就能有序。
#include <bits/stdc++.h>
using namespace std;
#define lson l, mid, o << 1
#define rson mid + 1, r, o << 1 | 1
typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int a[N], p[N];
int main(void) {
int n; scanf ("%d", &n);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]); p[a[i]] = i;
}
int ans = 1, len = 1;
for (int i=2; i<=n; ++i) {
if (p[i] > p[i-1]) len++;
else len = 1;
ans = max (ans, len);
}
printf ("%d\n", n - ans);
return 0;
}
Codeforces Round #335 (Div. 2)
标签:
原文地址:http://www.cnblogs.com/Running-Time/p/5042450.html