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. excel 处理方法

    //.方法一:采用OleDB读取EXCEL文件: //打开excel 返回指定表中的所有数据 public DataSet ExcelToDS(string Path) { string strCon ...

  2. 获取第n天日期

    function datezh(s){ return s = s>9 ? s:"0"+s } function dateTime(t){ var getNowTime = v ...

  3. 【剑指Offer】 24、二叉树中和为某一值的路径

      题目描述:   输入一颗二叉树的根结点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中, ...

  4. Bamboo Django Celery定时任务和时间设置

    1.Celery加入定时任务 Celery除了可以异步执行任务之外,还可以定时执行任务.在实例代码的基础上写个测试方法: 1 #coding:utf-8 2 from celery.task.sche ...

  5. python爬虫04 | 长江后浪推前浪,Reuqests库把urllib库拍在沙滩上

    最近 有些朋友 看完小帅b的文章之后 把小帅b的表情包都偷了 还在我的微信 疯狂发表情包嘚瑟 我就呵呵了 只能说一句 盘他 还有一些朋友 看完文章不点好看 还来催更 小帅b也只能说一句 继续盘他   ...

  6. python3实现UDP协议的简单服务器和客户端

    利用python中的socket模块中的来实现UDP协议,这里写一个简单的服务器和客户端.为了说明网络编程中UDP的应用,这里就不写图形化了,在两台电脑上分别打开UDP的客户端和服务端就可以了. UD ...

  7. QT5的模块介绍【摘】

    Qt 5 模块分为 Essentials Modules 和 Add-on Modules 两部分.前者是基础模块,在所有平台上都可用:后者是扩展模块,建立在基础模块的基础之上,在能够运行 Qt 的平 ...

  8. 【hihocoder 1475】 数组分拆

    [题目链接]:http://hihocoder.com/problemset/problem/1475 [题意] _< [题解] /* 别人的题解 首先对于每个位置预处理数组的前缀和,即s[i] ...

  9. Feign 负载均衡

    一.是什么 Feign 是一个声明式 WebService 客户端.使用 Feign 能让编写 Web Service 客户端更加简单,他的使用方法是定义一个接口,然后在上面添加注解.同时也支持 JA ...

  10. Spring Cloud-hystrix Feign(九)

    前面使用ribbon拦截RestTemplate 实现服务的负载均衡 使用Hystrix进行熔断降级请求缓存  用原生的方式 将会有大量的模板代码,feigin就是rabbon和Histrix的整合 ...