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. iframe的2个问题

    1.iframe里的视频无全屏按钮<iframe src="" allowfullscreen></iframe>allowfullscreen有个浏览器前 ...

  2. day36 类的三大特性---封装以及Property特性

    目录 类的封装 如果真的要拿 类的property特性 setter & deleter 类属性用法 类与对象的绑定方法和非绑定方法 对象方法&类方法&静态方法 隐藏模块内的函 ...

  3. 阿里云直播鉴权java代码示例

    段时间公司需要做直播服务,所以就研究了一下阿里云的直播,在直播里面,最重要的就是url的鉴权操作(验证推流或者拉流的有效性),在网上找了很多代码,都没有发现java的demo,所以就写篇播客记录一下, ...

  4. java中为什么不允许类多重继承,却允许接口多重继承

    首先看下面这一段代码:(底下有热心网友更正,jdk1.8之后情况确实有点变化,等改天有空继续更) interface a{ void b();}interface a1 extends a{ void ...

  5. RF学习使用记录【4】

    四 Extending Robot Framework 4.1 Creating test libraries RF的测试能力由测试库支持决定,已经有许多的测试库,有一些随着RF框架安装,但是更多的需 ...

  6. 【Leetcode】【简单】【14最长公共前缀】【JavaScript】

    题目 14. 最长公共前缀 编写一个函数来查找字符串数组中的最长公共前缀. 如果不存在公共前缀,返回空字符串 "". 示例 1: 输入: ["flower",& ...

  7. 爬虫系列(十三) 用selenium爬取京东商品

    这篇文章,我们将通过 selenium 模拟用户使用浏览器的行为,爬取京东商品信息,还是先放上最终的效果图: 1.网页分析 (1)初步分析 原本博主打算写一个能够爬取所有商品信息的爬虫,可是在分析过程 ...

  8. nyoj 711 枚举+并查集

     #include<stdio.h>//从大到小不断枚举边直到找到s-t的路径,判断从s可以到t可以用并查集来判断 #include<stdlib.h>//枚举最大的一条边肯定 ...

  9. 洛谷 P2534 [AHOI2012]铁盘整理

    P2534 [AHOI2012]铁盘整理 题目描述 输入输出格式 输入格式: 共两行.第一行为铁盘个数N(1<=N<=50),第二行为N个不同的正整数,分别为从上到下的铁盘的半径R.(1& ...

  10. nginx 、tomcat 集群配置、shiro Session 共享

    一.nginx.config 配置 #user nobody; worker_processes ; #error_log logs/error.log; #error_log logs/error. ...