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的更多相关文章

  1. Seven Deadly Sins: Gluttony, Greed, Sloth, Wrath, Pride, Lust, and Envy.

    Seven Deadly Sins: Gluttony, Greed, Sloth, Wrath, Pride, Lust, and Envy.七宗罪:暴食.贪婪.懒惰.暴怒.傲慢.色欲.妒忌.

  2. Codeforces 891B - Gluttony

    891B - Gluttony 题意 给出一个数字集合 \(a\),要求构造一个数组 \(b\) 为 \(a\) 的某个排列,且满足对于所有下标集合的子集 \(S=\{x_1,x_2,...,x_k\ ...

  3. [CodeForces 892A] Greed (Java中sort实现从大到小排序)

    题目链接:http://codeforces.com/problemset/problem/892/A 具体的Java 中 sort实现降序排序:https://www.cnblogs.com/you ...

  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 892 A.Greed

    A. Greed time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  6. 892A. Greed#贪婪(优先队列priority_queue)

    题目出处:http://codeforces.com/problemset/problem/892/A 题目大意:有一些可乐(不一定装满),问能不能把所有可乐装进两个可乐瓶中 #include< ...

  7. 892B. Wrath#愤怒的连环杀人事件(cin/cout的加速)

    题目出处:http://codeforces.com/problemset/problem/892/B 题目大意:一队人同时举刀捅死前面一些人后还活着几个 #include<iostream&g ...

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

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

随机推荐

  1. MySQL索引(2)

    一.索引基础 1. B-Tree索引 <1> 所有的值都是按顺序存储的,并且每一个叶子页到根的距离相同. <2> 顺序组织存储,很适合查找范围数据,效率会非常高. <3& ...

  2. LeetCode 252. Meeting Rooms (会议室)$

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  3. 【机器学习】支持向量机(SVM)

    感谢中国人民大学胡鹤老师,课程深入浅出,非常好 关于SVM 可以做线性分类.非线性分类.线性回归等,相比逻辑回归.线性回归.决策树等模型(非神经网络)功效最好 传统线性分类:选出两堆数据的质心,并做中 ...

  4. 前端开发:如何写一手漂亮的 Vue

    前几日听到一句生猛与激励并存,可怕与尴尬同在,最无奈也无解的话:"90后,你的中年危机已经杀到".这令我很受触动.显然,这有些夸张了,但就目前这日复一日的庸碌下去,眨眼的功夫,那情 ...

  5. ES6新特性 Class的实现

    ES5之前类的继承是靠原型实现的,而这一过程的实现又涉及到一大堆的原型定义,特别是ES5推出了Object.definePorperty()方法后,代码更加晦涩.但是这种方式正是javascript这 ...

  6. CSS预处理器——Sass、LESS和Stylus实践【未删减版】

    http://www.w3cplus.com/css/css-preprocessor-sass-vs-less-stylus-2.html

  7. HTTPS协议,TLS协议

    一.HTTPS 协议 HTTPS协议其实就是HTTP over TSL,TSL(Transport Layer Security) 传输层安全协议是https协议的核心. TSL可以理解为SSL (S ...

  8. 基于Cef内核的多店铺登录器(含源码)

    公司是做电商的,在速卖通平台上开了若干店铺,每天都需要登录店铺打理,如:发货提交.获取运单号等.多个店铺的情况下,同时使用浏览器就会非常繁琐,如:要记住帐户名和密码,还要在不同店铺间切换.如果能够制作 ...

  9. 实现验证码图像文字的识别(C#调用DLL)

    请先下载http://asprise.com/product/ocr/index.php?lang=csharp 的SDK.里面提供了详细的OCR方法,如下:   将发现图像框picbVeryfyCo ...

  10. Hi,腾讯WeTest联合Unity官方打造的性能分析工具UPA,今日全新发布!

    早在2016年ChinaJoy开始,WeTest曾受邀出席过Unity中国的线下性能场的活动,介绍我们的自动化框架和王者荣耀的故事.当时的活动很成功,期间我们收到了不少Unity开发者的好评,也为我们 ...