Codeforces Round #446 (Div. 2)
2 seconds
256 megabytes
standard input
standard output
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi(ai ≤ bi).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not!
The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola cans.
The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) — volume of remaining cola in cans.
The third line contains n space-separated integers that b1, b2, ..., bn (ai ≤ bi ≤ 109) — capacities of the cans.
Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower).
23 53 6
YES
36 8 96 10 12
NO
50 0 5 0 01 1 8 10 5
YES
44 1 0 35 2 2 3
YES
In the first sample, there are already 2 cans, so the answer is "YES".
n个数据的和,然后在另一个n个数取两个大就行了,我不小心爆了LL
#include<stdio.h> #include<bits/stdc++.h> using namespace std; const int N=100005; int a[N]; int main() {int n;scanf("%d",&n);long long s=0;for(int i=1;i<=n;i++){int x;scanf("%d",&x);s+=x;if(s>int(2e9)){printf("NO");return 0;}}for(int i=1;i<=n;i++)scanf("%d",&a[i]);sort(a+1,a+n+1);printf("%s",(s<=a[n]+a[n-1])?"YES":"NO");return 0; }
2 seconds
256 megabytes
standard input
standard output
Hands that shed innocent blood!
There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li.
You are given lengths of the claws. You need to find the total number of alive people after the bell rings.
The first line contains one integer n (1 ≤ n ≤ 106) — the number of guilty people.
Second line contains n space-separated integers L1, L2, ..., Ln (0 ≤ Li ≤ 109), where Li is the length of the i-th person's claw.
Print one integer — the total number of alive people after the bell rings.
40 1 0 10
1
20 0
2
101 1 3 0 0 0 2 1 0 3
3
In first sample the last person kills everyone in front of him.
直接暴力下取大
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e6+5; ll l[N],ma[N]; int main() {ios::sync_with_stdio(false);cin.tie(0);ll n;cin>>n;memset(ma,0,sizeof(ma));for(ll i=1;i<=n;i++){cin>>l[i];ll x=max(1LL,i-l[i]);ma[x]=max(i-x,ma[x]);}ll ans=0,f=0;for(ll i=1;i<=n;i++){f=max(f,ma[i]);if(f==0)ans++;f--;}cout<<ans;return 0; }
2 seconds
256 megabytes
standard input
standard output
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacentelements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the greatest common divisor.
What is the minimum number of operations you need to make all of the elements equal to 1?
The first line of the input contains one integer n (1 ≤ n ≤ 2000) — the number of elements in the array.
The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.
Print -1, if it is impossible to turn all numbers to 1. Otherwise, print the minimum number of operations needed to make all numbers equal to 1.
52 2 3 4 6
5
42 4 6 8
-1
32 6 9
4
In the first sample you can turn all numbers to 1 using the following 5 moves:
- [2, 2, 3, 4, 6].
- [2, 1, 3, 4, 6]
- [2, 1, 3, 1, 6]
- [2, 1, 1, 1, 6]
- [1, 1, 1, 1, 6]
- [1, 1, 1, 1, 1]
We can prove that in this case it is not possible to make all numbers one using less than 5 moves.
这个有1的话就得直接输出啊,n-f
#include<stdio.h> #include<bits/stdc++.h> using namespace std; const int N=2005; int a[N],b[N]; int main() {ios::sync_with_stdio(false);cin.tie(0);int n;cin>>n;int f=0;for(int i=1; i<=n; i++){cin>>a[i];if(a[i]==1)f++;}if(f)printf("%d",n-f);else{f=1;for(;;){if(f>888*n){printf("-1");return 0;}for(int i=f+1; i<=n; i++){b[i]=__gcd(a[i-1],a[i]);if(b[i]==1){cout<<f+n-1;return 0;}}f++;for(int i=1; i<=n; i++)a[i]=b[i];}}return 0; }
2 seconds
256 megabytes
standard input
standard output
You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x1, x2, ..., xk} (1 ≤ xi ≤ n, 0 < k < n) the sums of elements on that positions in aand b are different, i. e.
The first line contains one integer n (1 ≤ n ≤ 22) — the size of the array.
The second line contains n space-separated distinct integers a1, a2, ..., an (0 ≤ ai ≤ 109) — the elements of the array.
If there is no such array b, print -1.
Otherwise in the only line print n space-separated integers b1, b2, ..., bn. Note that b must be a permutation of a.
If there are multiple answers, print any of them.
21 2
2 1
41000 100 10 1
100 1 1000 10
An array x is a permutation of y, if we can shuffle elements of y such that it will coincide with x.
Note that the empty subset and the subset containing all indices are not counted.
这个P金爷讲思路,跟着做就行了
#include<bits/stdc++.h> using namespace std; const int N=200; pair<int,int>a[N]; int ans[N]; int main() {int n;scanf("%d",&n);for(int i=0; i<n; i++)scanf("%d",&a[i].first),a[i].second=i;sort(a,a+n);for(int i=0; i<n; i++){int to=a[i].second;if(i==0)ans[to]=a[n-1].first;elseans[to]=a[i-1].first;}for(int i=0; i<n; i++){printf("%d ",ans[i]);}return 0; }
转载于:https://www.cnblogs.com/BobHuang/p/7858250.html
Codeforces Round #446 (Div. 2)相关推荐
- Codeforces Round #446 (Div. 1) B. Gluttony 构造 + 补集思想
传送门 文章目录 题意: 思路: 题意: 给你一个数组aaa,保证aaa中每个数都互不相同,让你构造一个数组bbb,满足对于任意的S=x1,x2,...,xk,1≤xi≤n,0≤k<nS={x_ ...
- 【Codeforces Round #446 (Div. 2) C】Pride
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 想一下,感觉最后的结果肯定是从某一段开始,这一段的gcd为1,然后向左和向右扩散的. 则枚举那一段在哪个地方. 我们设这一段中所有的 ...
- Lust(Codeforces Round #446 Div.1-891E)(母函数\生成函数)
文章目录 题目 思路 代码 题目 你有n个数 a1,a2,...,ana_1,a_2,...,a_na1,a2,...,an ,要进行 kkk 次操作,每次在 111 ~ nnn 中随机选择一个 ...
- Codeforces Round #506 (Div. 3)
Codeforces Round #506 (Div. 3) 实习期间事不多,对div3 面向题解和数据编程了一波 A. Many Equal Substrings 题目链接 A题就是找后缀和前缀重合 ...
- Codeforces Round #563 (Div. 2)/CF1174
Codeforces Round #563 (Div. 2)/CF1174 CF1174A Ehab Fails to Be Thanos 其实就是要\(\sum\limits_{i=1}^n a_i ...
- 构造 Codeforces Round #302 (Div. 2) B Sea and Islands
题目传送门 1 /* 2 题意:在n^n的海洋里是否有k块陆地 3 构造算法:按奇偶性来判断,k小于等于所有点数的一半,交叉输出L/S 4 输出完k个L后,之后全部输出S:) 5 5 10 的例子可以 ...
- Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...
- Codeforces Round #712 Div.2(A ~ F) 超高质量题解(每日训练 Day.15 )
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #712 Div.2(A ~ F) 题解 比赛链接:https:// ...
- Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13
整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...
最新文章
- [英文面試]如何寫面試後的感謝信
- Ubuntu下使用GDB断点Go程序
- dotweb——go语言的一个微型web框架(二)启动dotweb
- Python--Redis实战:第三章:Redis命令:第七节:其他命令
- [Unity 游戏设计的元素]
- 茫茫内存,我该如何用 windbg 找到你 ?
- java树算法_Java数据结构算法(三)树
- c语言指针++_C ++此指针| 查找输出程序| 套装3
- System V 信号量
- 如何使用Git上传项目代码到github
- 马斯克惹麻烦?特斯拉股票一夜暴跌12%,千亿市值蒸发
- Num48 boss---02(pdm翻转,持久表现抽取,用户登退,消息提示,修密,自定义拦截器)...
- weblogic 解决线程阻塞
- C#中引用第三方ocx控件引发的问题以及解决办法
- 【Spring笔记】Spring创建hello程序
- Android半透明+RGB颜色代码大全
- MySQL学习1 基础入门
- 基于知识图谱的智能问答机器人技术架构
- SmartBI入门(一)介绍和安装
- 微信小程序的环境准备