Codeforces Round #264 (Div. 2)

Codeforces Round #264 (Div. 2)

题目链接

A:注意特判正好的情况,其他就一个个去判断记录最大值即可

B:扫一遍,不够的用钱去填即可,把多余能量记录下来

C:把主副对角线处理出来,然后黑格白格只能各选一个最大的放即可

D:转化为DAG最长路问题,每个数字记录下在每个序列的位置,如果一个数字能放上去,那么肯定是每个序列上的数字都是在之前最末尾数字的后面

E:大力出奇迹,预处理出树,然后每次查询从当前位置一直往上找到一个符合的即可,如果没有符合的就是-1

代码:

A:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int n, s;

int main() {
	scanf("%d%d", &n, &s);
	int x, y;
	int flag = 1;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &x, &y);
		if (x == s) {
			if (y == 0) {
				ans = max(ans, y);
				flag = 0;
			}
		}
		else if (x < s) {
			ans = max(ans, (100 - y) % 100);
			flag = 0;
		}
	}
	if (flag) printf("-1\n");
	else printf("%d\n", ans);
	return 0;
}

B:

#include <cstdio>
#include <cstring>

const int N = 100005;
typedef long long ll;

int n;
ll h[N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%lld", &h[i]);
	ll now = 0;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		if (h[i] > h[i - 1]) {
			ll need = h[i] - h[i - 1];
			if (now >= need) {
				now -= need;
			} else {
				ans += need - now;
				now = 0;
			}
		} else {
			now += h[i - 1] - h[i];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

C:

#include <cstdio>
#include <cstring>

const int N = 2005;

typedef long long ll;

int n;
ll g[N][N], zhu[N + N], fu[N + N];

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			scanf("%lld", &g[i][j]);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			zhu[i - j + n] += g[i][j];
			fu[i + j] += g[i][j];
		}
	}
	ll b = -1, w = -1;
	int bx, by, wx, wy;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			ll sum = zhu[i - j + n] + fu[i + j] - g[i][j];
			if ((i + j) % 2 == 0) {
				if (b < sum) {
					b = sum;
					bx = i + 1;
					by = j + 1;
				}
			}
			else {
				if (w < sum) {
					w = sum;
					wx = i + 1;
					wy = j + 1;
				}
			}
		}
	}
	printf("%lld\n", b + w);
	printf("%d %d %d %d\n", bx, by, wx, wy);
	return 0;
}

D:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 1005;

struct Num {
	int v[10], la;
} num[N];

bool cmp(Num a, Num b) {
	return a.la < b.la;
}

int n, k, dp[N][N];

bool judge(int i, int j) {
	for (int x = 0; x < k; x++) {
		if (num[i].v[x] < num[j].v[x]) return false;
	}
	return true;
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < k; i++) {
		int tmp;
		for (int j = 1; j <= n; j++) {
			scanf("%d", &tmp);
			num[tmp].v[i] = j;
		}
	}
	for (int i = 0; i <= n; i++) {
		int maxv = 0;
		for (int j = 0; j < k; j++) {
			maxv = max(maxv, num[i].v[j]);
		}
		num[i].la = maxv;
	}
	sort(num, num + n + 1, cmp);
	/*
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			printf("%d ", num[i].v[j]);
		}
		printf("\n");
	}*/
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < i; j++) {
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (judge(i, j)) {
				dp[i][i] = max(dp[i][i], dp[i][j] + 1);
			}
		}
	}
	int ans = 0;
	for (int i = 0; i <= n; i++)
		ans = max(ans, dp[n][i]);
	printf("%d\n", ans);
	return 0;
}

E:

#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int N = 100005;

int n, q, val[N], f[N];
vector<int> g[N];

void dfs(int u, int fa) {
	f[u] = fa;
	for (int i = 0; i < g[u].size(); i++) {
		int v = g[u][i];
		if (v == fa) continue;
		dfs(v, u);
	}
}

int gcd(int a, int b) {
	while (b) {
		int tmp = a % b;
		a = b;
		b = tmp;
	}
	return a;
}

int query(int u) {
	int v = val[u];
	u = f[u];
	while (u) {
		if (gcd(val[u], v) > 1) return u;
		u = f[u];
	}
	return -1;
}

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++)
		scanf("%d", &val[i]);
	int u, v;
	for (int i = 1; i < n; i++) {
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(1, 0);
	int tp, a, b;
	while (q--) {
		scanf("%d%d", &tp, &a);
		if (tp == 1) {
			printf("%d\n", query(a));
		} else {
			scanf("%d", &b);
			val[a] = b;
		}
	}
	return 0;
}
时间: 2024-12-25 22:17:03

Codeforces Round #264 (Div. 2)的相关文章

Codeforces Round #264 (Div. 2)[ABCDE]

Codeforces Round #264 (Div. 2)[ABCDE] ACM 题目地址: Codeforces Round #264 (Div. 2) 这场只出了两题TAT,C由于cin给fst了,D想到正解快敲完了却game over了... 掉rating掉的厉害QvQ... A - Caisa and Sugar[模拟] 题意: Caisa拿s美元去超市买sugar,有n种sugar,每种为xi美元yi美分,超市找钱时不会找美分,而是用sweet代替,当然能用美元找就尽量用美元找.他

Codeforces Round #264 (Div. 2) D

题意: 给出最多5个序列,问这几个序列的最长公共子序列的长度是多少. solution : 脑抽级别我是,第一个序列每个数字位置固定,这样只要维护一个k-1维的偏序集就好了.然后在保证每个位置合法的情况下 走一遍最长上升子序列就好了. 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int inf = 0x3f3f3f3f; 4 const int MAX = 1000+10; 5 int a[MAX],x; 6 int dp

Codeforces Round #264 (Div. 2) A

题目: Caisa is going to have a party and he needs to buy the ingredients for a big chocolate cake. For that he is going to the biggest supermarket in town. Unfortunately, he has just s dollars for sugar. But that's not a reason to be sad, because there

Codeforces Round #264 (Div. 2) B

题目: B. Caisa and Pylons time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during

Codeforces Round #264 (Div. 2) C

题目: C. Gargari and Bishops time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a g

Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】

题目: 题意:给出一个矩阵,每一格都有一个数字,然后放入两个象,想可以吃掉对角线上所有的数字,问两个象能吃掉的最大值. 分析:这个题目思路就是暴力,暴力计算出每一格放象的话能得到多少钱,然后求出两个不冲突的最大值,我比赛的时候写的方法是先求出每一个值,编号之后存到数组里面,然后在通过一系列处理得到,总之很麻烦,写了一个多小时,最后才发现有一点小错误,没时间了.初始样例也没有通过. 然后看了下别人写的,太简洁了.直接用行和列和和差就可以直接求出来.看来代码能力还非常有待提高啊. 我的AC代码: #

Codeforces Round #279 (Div. 2) ABCD

Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name     A Team Olympiad standard input/output 1 s, 256 MB  x2377 B Queue standard input/output 2 s, 256 MB  x1250 C Hacking Cypher standard input/output 1 s, 256 MB  x740 D Chocolate standard input/

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿