Codeforces Round #446
Greed
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using std::vector;
using std::sort;
int cmp(const void * x, const void * y) {
//x < y
return (*((long long *)(x))) > (*((long long *)(y))) ? : -;
}
long long a[], b[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n;
scanf("%d", &n);
for (int i = ; i < n; i++)scanf("%lld", &a[i]);
for (int i = ; i < n; i++)scanf("%lld", &b[i]);
//qsort(b, n, sizeof(long long), cmp);
sort(b, b + n);
long long sum = ;
for (int i = ; i < n; i++) sum += a[i];
if (sum > b[n - ] + b[n - ]) printf("NO\n");
else printf("YES\n");
return ;
}
Wrath
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using std::vector;
using std::sort;
int cmp(const void * x, const void * y) {
//x < y
return (*((long long *)(x))) > (*((long long *)(y))) ? : -;
}
int stack[], top = ;
long long l;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n;
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%lld", &l);
while (top > && i - stack[top - ] <= l) top--;
stack[top++] = i;
}
printf("%d\n", top);
return ;
}
Pride
把一个不是1的数变成1肯定至少要1次操作,所以全变成1的最少操作次数肯定不会比a中不是1的数字个数还少。假定最初a中已经有了几个1,则直接输出n-1的个数。如果最初a中没有1,则首先用最少的操作次数弄出来一个1,然后再用n-1次操作把其他数字变成1。求弄出1的最少操作次数的方法是这样的:首先把a中相邻的数字两两求最大公约数,再对得到的数组再对相邻数字两两求最大公约数,直到出现1:则最少操作次数为迭代次数;全相同且不为1:说明不可能出现1。至于为啥,我也不知道,直觉是这样的,试了试居然过了。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using std::vector;
using std::sort;
int cmp(const void * x, const void * y) {
//x < y
return (*((long long *)(x))) > (*((long long *)(y))) ? : -;
}
long long gcd(long long a, long long b) {
long long k;
while (b != ) {
k = b;
b = a % b;
a = k;
}
return a;
}
long long a[][];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
int n, cnt = ;
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%lld", &a[][i]);
if (a[][i] == ) cnt++;
}
if (cnt) {
printf("%d\n", n - cnt);
return ;
}
int last = ;
for (int i = ; i < n; i++) {
for (int j = ; j < n - i; j++) {
a[ - last][j] = gcd(a[last][j], a[last][j + ]);
}
bool same = true, find1 = false;
for (int j = ; j < n - i; j++) {
if (a[ - last][j] == ) find1 = true;
if (j + < n - i && a[ - last][j] != a[ - last][j + ]) same = false;
}
if (find1) {
printf("%d\n", n - + i);
return ;
}
if (same) {
printf("-1\n");
return ;
}
last = - last;
}
printf("-1\n");
return ;
}
Gluttony
把每个数字用大于它的最小的数字代替,最大的数字用最小的数字代替,没有-1的情况。
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
using std::vector;
using std::sort;
int cmp(const void * x, const void * y) {
//x < y
return (*((long long *)(x))) > (*((long long *)(y))) ? : -;
}
int n;
long long a[], b[], c[];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
#endif
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%lld", &a[i]);
b[i] = a[i];
}
qsort(a, n, sizeof(long long), cmp);
for (int i = ; i < n; i++) {
for (int j = ; j < n; j++) {
if (b[i] == a[j]) {
c[i] = j;
break;
}
}
}
for (int i = ; i < n; i++) c[i] = (c[i] + ) % n;
for (int i = ; i < n; i++) printf("%lld ", a[c[i]]);
return ;
}
Envy
按边长从小到大处理(kruskal),各个询问中涉及的边也按从小到大处理。
当处理长度为i的边时,先不在整体的边集里处理,依次判断各个询问中涉及相同长度的边集全部加入会不会产生环,然后把长度为i的边全部加入最小生成树中(这个过程中产生环也无所谓,不加就行了)。
这个题标签里有个dsu,不过我用普通合并和启发式合并分别提交反而是普通合并比较快。他们都说启发式合并比较优,但是我觉得挺反直觉的,因为合并过程是一样的,得到的结果本质上也是一样的,所以我觉得启不启发没什么区别。强行要说的话,就是启发式能减少一点之后在路径压缩上花的时间。
Sloth
Last
Codeforces Round #446的更多相关文章
- Codeforces Round #446 (Div. 2)
Codeforces Round #446 (Div. 2) 总体:rating涨了好多,虽然有部分是靠和一些大佬(例如redbag和ShichengXiao)交流的--希望下次能自己做出来2333 ...
- Codeforces Round #446 Div. 1
B:即使看到n<=22也应该猜到这只是为了写spj.将每个数替换为恰好比他大的数即可,最大值替换为最小值.这样原序列中不包含最小值的集合显然都满足条件,并且容易发现包含最小值的集合的变化量都是最 ...
- Codeforces Round #446 (Div. 2) C. Pride【】
C. Pride time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #446 (Div. 2) B. Wrath【模拟/贪心】
B. Wrath time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- Codeforces Round #446 (Div. 2) A. Greed【模拟】
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- 【Codeforces Round #446 (Div. 2) C】Pride
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 想一下,感觉最后的结果肯定是从某一段开始,这一段的gcd为1,然后向左和向右扩散的. 则枚举那一段在哪个地方. 我们设这一段中所有的 ...
- 【Codeforces Round #446 (Div. 2) B】Wrath
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 倒着来,维护一个最小的点就可以了. [代码] #include <bits/stdc++.h> using namesp ...
- 【Codeforces Round #446 (Div. 2) A】Greed
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心选容量大的瓶子就好 [代码] #include <bits/stdc++.h> #define int long l ...
- Codeforces Round #446 Div1 E
题目大意 有n个数,进行k轮操作:随机一个i,让\(a_i\)减1,然后ans加上\(\Pi_{j\neq i}a_i\). 求ans的期望. 分析 发现,造成的伤害就是原来的ai的积减去k轮操作后的 ...
随机推荐
- Git更新代码
此次更新,创建新的文件与文件夹,并且删除了原有文件 通过“git status” 命令查看当前变更.通过变更信息可以看出,删除了test_case.py文件.这个删除只是在项目目录下进行删除,Git对 ...
- Django MVC与MTV概念 Ajax、分页实现
MVC与MTV概念 MTV与MVC(了解) MTV模型(django): M:模型层(models.py) T:templates ...
- 11.5 【Linq 】连接
11.5.1 使用 join 子句的内连接 如果你打算把一个巨大的序列连接到一个极小的序列上,应尽可能把小序列作为右边序列 class Program { static void Main(strin ...
- Linux C(day01)
Linux是一个和Windows类似的操作系统 通常通过终端软件使用Linux操作系统 终端软件里只能使用键盘不能使用鼠标 可以在终端软件里输入各种命令控制计算机 完成各种任务 clear命令可以清除 ...
- MAC下redis的安装和配置
1.下载 打开官网:https://redis.io/ 选择下载你要的版本压缩包 2.安装 打开终端,cd - 将下载的压缩包拷贝到local目录下:sudo cp Downloads/redis-4 ...
- 记一次惊心的网站 TCP 队列问题排查经历
https://blog.csdn.net/chenlycly/article/details/80868990 http://www.mytju.com/classcode/news_readnew ...
- 突如其来的“中断异常”,我(Java)该如何处理?
3.try-catch块 try语句块中代码执行时发生三种情况: try语句块中代码正常执行完毕,没有任何异常,那么catch语句块的代码将不会被执行. import java.util.*; pub ...
- js实现的时间轴效果
今天整理以前的资料发现以前写的一个时间轴效果,当时也是网上找了很久没有找到,就自己写了一个,现在发出来给有需要的人,代码写的可能有点乱. 效果图: 下面是美工做的设计图的效果(有个美工就是好): 下面 ...
- 【ACM】nyoj_540_奇怪的排序_201308050951
奇怪的排序时间限制:1000 ms | 内存限制:65535 KB 难度:1描述 最近,Dr. Kong 新设计一个机器人Bill.这台机器人很聪明,会做许多事情.惟独对自然数的理解与人类不一样, ...
- mongodb--find高级用法
链式查询 db.person.find().limit(4).sort({sex:-1}) // sort来说,1 是升序, -1 是降序 尽量不要用mongodb去做一些复杂的运算 分页的写法 ·· ...