codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony
A 链接:http://codeforces.com/problemset/problem/892/A
签到
#include <iostream>
#include <algorithm>
using namespace std;
long long a,b[];
int main() {
int n;
long long sum1=,sum2=;
cin>>n;
for(int i=; i<n; ++i) cin>>a,sum1+=a;
for(int i=; i<n; ++i) cin>>b[i];
sort(b,b+n);
sum2=b[n-]+b[n-];
if(sum2>=sum1) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return ;
}
B 链接:http://codeforces.com/problemset/problem/892/B
O(n)倒退遍历,保存当前能到的最大长度
#include <bits/stdc++.h>
using namespace std;
int a[];
int main() {
ios::sync_with_stdio(false);
int n;
cin>>n;
for(int i=; i<=n; ++i) cin>>a[i];
int len=-;
for(int i=n; i>=; --i) {
int temp=a[i];
if(len>=) a[i]=-;
len=max(len,temp);
len--;
}
int sum=;
for(int i=; i<=n; ++i) {
if(a[i]!=-) sum++;
}
cout<<sum<<endl;
return ;
}
C 链接:http://codeforces.com/problemset/problem/891/A
检测第一次出现1的时候经历了几次操作的最小值,只要出现一次1,那么再加上n-1次操作就可以全部翻转为1
利用gcd(ai)是否等于1可以剪枝,return -1
特别地,要注意全部为1的特殊情况 return 0
代码:
#include <iostream>
using namespace std;
int a[];
int GCD(int a, int b) {
if(!b) return a;
return GCD(b,a%b);
}
int main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n,gcd,exist_one=;
cin>>n;
cin>>a[];
gcd=a[];
if(a[]==) exist_one++;
for(int i=; i<=n; ++i) {
cin>>a[i];
if(a[i]==) exist_one++;
if(gcd<=a[i]) gcd=GCD(a[i],gcd);
else gcd=GCD(gcd,a[i]);
}
if(gcd!=) {
cout<<"-1"<<endl;
return ;
}
if(exist_one) {
cout<<n-exist_one<<endl;
return ;
}
int minnum=;
for(int i=; i<n; ++i) {
gcd=a[i];
for(int j=i+; j<=n; ++j) {
if(a[j]>gcd) gcd=GCD(a[j],gcd);
else gcd=GCD(gcd,a[j]);
if(gcd==) {
minnum=min(j-i,minnum);
break;
}
}
}
cout<<minnum+n-<<endl;
return ;
}
D 链接:http://codeforces.com/problemset/problem/891/B
让每一个数都能够找到小于自己的最大值,同时假如这个数是最小值,则用最大值来替换它
∵任何两个数(最大、最小除外)的差值都小于最小值与最大值的差值
首先排序,找到对应的值,输出打印
代码:
#include <bits/stdc++.h>
using namespace std;
int a[],b[];
int main() {
ios::sync_with_stdio(false);
int n,minnum=1e9;
cin>>n;
for(int i=; i<n; ++i) {
cin>>a[i];
b[i]=a[i];
minnum=min(minnum,a[i]);
}
sort(a,a+n);
int flag=;
for(int i=; i<=n-; ++i) {
flag=;
if(b[i]==minnum) {
flag=;
b[i]=a[n-];
continue;
}
for(int j=n-; j>=; --j) {
if(a[j]<b[i]) {
flag=;
b[i]=a[j];
break;
}
}
if(!flag) {
cout<<"-1"<<endl;
return ;
}
}
for(int i=; i<n-; ++i) cout<<b[i]<<" ";
cout<<b[n-]<<endl;
return ;
}
codeforces #446 892A Greed 892B Wrath 892C Pride 891B Gluttony的更多相关文章
- Seven Deadly Sins: Gluttony, Greed, Sloth, Wrath, Pride, Lust, and Envy.
Seven Deadly Sins: Gluttony, Greed, Sloth, Wrath, Pride, Lust, and Envy.七宗罪:暴食.贪婪.懒惰.暴怒.傲慢.色欲.妒忌.
- Codeforces 891B - Gluttony
891B - Gluttony 题意 给出一个数字集合 \(a\),要求构造一个数组 \(b\) 为 \(a\) 的某个排列,且满足对于所有下标集合的子集 \(S=\{x_1,x_2,...,x_k\ ...
- [CodeForces 892A] Greed (Java中sort实现从大到小排序)
题目链接:http://codeforces.com/problemset/problem/892/A 具体的Java 中 sort实现降序排序:https://www.cnblogs.com/you ...
- 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 892 A.Greed
A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...
- 892A. Greed#贪婪(优先队列priority_queue)
题目出处:http://codeforces.com/problemset/problem/892/A 题目大意:有一些可乐(不一定装满),问能不能把所有可乐装进两个可乐瓶中 #include< ...
- 892B. Wrath#愤怒的连环杀人事件(cin/cout的加速)
题目出处:http://codeforces.com/problemset/problem/892/B 题目大意:一队人同时举刀捅死前面一些人后还活着几个 #include<iostream&g ...
- War of the Corporations CodeForces - 625B (greed)
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue the ...
- 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 ...
随机推荐
- await和async更多的理解
最近有不少网友提起await和async,呵呵,C# 5引进的语法糖. 这个语法糖还真不好吃,能绕倒一堆初学的朋友,在网上也有很多网友关于这块知识点的争论,有对有错,今天在这里把这个误区好好讲讲. 在 ...
- javascript 之作用域-06
作用域 作用域是指变量和函数可访问范围,他规定了如何查找变量,也就是确定当前执行代码对变量的访问权限. 作用域有两种工作模式: 静态作用域 :又称为词法作用域,在编译阶就可以决定变量的引用,由程序定义 ...
- css左侧固定宽度,右侧自适应的几种实现方法
左侧固定,右侧自适应或者右侧固定在,左侧自适应是一样的.这种布局很常见,而且面试过程中也经常会问到,这里我总结的方法一共有5种.要实现这种布局,也算比较简单.我们先给出html结构: <div ...
- Java并发编程--线程池
1.ThreadPoolExecutor类 java.uitl.concurrent.ThreadPoolExecutor类是线程池中最核心的一个类,下面我们来看一下ThreadPoolExecuto ...
- Android_简易的短信发送器
这个随笔将介绍如何完成一个简单的第三方的短信发送器(不打开短信界面,调用android的api完成功能) 1.首先,我们来做布局 由于我这里写的是一个简易的,,短信发送,所以只是一个LinearLay ...
- 50 years, 50 colors
50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 无阻赛的脚本(js脚本延迟方法)
js脚本的加载与执行 1.延迟脚本(defer属性) 带有defer属性的script标签,可以放置在文档的任何位置,在页面解析到该标签时,会开始下载该脚本,但是不会立即执行,直到dom加载完成(on ...
- Browsing contexts 浏览器上下文
浏览上下文就是document object 呈现给用户的所在的环境 每一个标签或者窗口都包含一个浏览器上下文,包括iframe frames 每一个browsing context ...
- ②bootstrap栅栏使用基础案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 各大网站vip视频破解
昨天朋友问我有没有XX视频网站的会员,现在的视频网站那么多个,要是都买会员,那还得了,作为一名程序员,想看vip视频还是自己可以动手的. 然后就自己动手用vue做了个破解vip视频的网站,界面简介,不 ...