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,不过我用普通合并和启发式合并分别提交反而是普通合并比较快。他们都说启发式合并比较优,但是我觉得挺反直觉的,因为合并过程是一样的,得到的结果本质上也是一样的,所以我觉得启不启发没什么区别。强行要说的话,就是启发式能减少一点之后在路径压缩上花的时间。

Solution

Sloth

Last

Codeforces Round #446的更多相关文章

  1. Codeforces Round #446 (Div. 2)

    Codeforces Round #446 (Div. 2) 总体:rating涨了好多,虽然有部分是靠和一些大佬(例如redbag和ShichengXiao)交流的--希望下次能自己做出来2333 ...

  2. Codeforces Round #446 Div. 1

    B:即使看到n<=22也应该猜到这只是为了写spj.将每个数替换为恰好比他大的数即可,最大值替换为最小值.这样原序列中不包含最小值的集合显然都满足条件,并且容易发现包含最小值的集合的变化量都是最 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 【Codeforces Round #446 (Div. 2) C】Pride

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 想一下,感觉最后的结果肯定是从某一段开始,这一段的gcd为1,然后向左和向右扩散的. 则枚举那一段在哪个地方. 我们设这一段中所有的 ...

  7. 【Codeforces Round #446 (Div. 2) B】Wrath

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 倒着来,维护一个最小的点就可以了. [代码] #include <bits/stdc++.h> using namesp ...

  8. 【Codeforces Round #446 (Div. 2) A】Greed

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心选容量大的瓶子就好 [代码] #include <bits/stdc++.h> #define int long l ...

  9. Codeforces Round #446 Div1 E

    题目大意 有n个数,进行k轮操作:随机一个i,让\(a_i\)减1,然后ans加上\(\Pi_{j\neq i}a_i\). 求ans的期望. 分析 发现,造成的伤害就是原来的ai的积减去k轮操作后的 ...

随机推荐

  1. react构建前端项目方法汇总

    react简介: 一.使用react 创建一个PC端的项目 (a):使用 yemon 创建一个 webpack 的 react 的项目 控制台安装并且产看 yemon 的版本 yo -v (b): 全 ...

  2. Commons IO

    Common IO 是一个工具库,用来帮助开发IO功能 它包括6个主要部分 Utility classes – 包括一些静态方法来执行常用任务 Input – InputStream 和 Reader ...

  3. js中call、apply、bind的区别

    var Person = { name : 'alice', say : function(txt1,txt2) { console.info(txt1+txt2); console.info(thi ...

  4. 数据结构与算法(2)- vector概念介绍

    声明:虽然本系列博客与具体的编程语言无关.但是本文作者对c++相对比较熟悉,其次是java,所以难免会有视角上的偏差.举例也大多是和这两门语言相关. Vector的出现主要是为了解决数组的静态空间的问 ...

  5. 51nod1046 A^B Mod C【快速幂】

    给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = 3. Input 3个正整数A B C,中间用空格分隔.(1 <= A,B,C <= 10^9) ...

  6. Font Awesome使用方法

    Font Awesome(中文站点)是一套为Bootstrap而创造的图标字体库及CSS框架,在业界享有盛誉. FA包含了常规web开发所需要用到的几乎所有图标,并且免费授权使用,只需要下载即可.所有 ...

  7. floyd求最小环 模板

    http://www.cnblogs.com/Yz81128/archive/2012/08/15/2640940.html 求最小环 floyd求最小环 2011-08-14 9:42 1 定义: ...

  8. codevs——T1267 老鼠的旅行

    http://codevs.cn/problem/1267/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Descr ...

  9. javascript推断浏览器类型

    <script> window["MzBrowser"]={};(function() { if(MzBrowser.platform) return; var ua ...

  10. 使用Html5和Js进行拖动

    function init() {             var source = document.getElementById("dragme");             ...