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. swift之函数式编程(五)

    文章内容来源于<Functional Programing in Swift>,详情请看原著 The Value of Immutability swift 对于控制值改变有一些机制.在这 ...

  2. 读书笔记-你不知道的JS上-this

    关于this 与静态词法作用域不用,this的指向动态绑定,在函数执行期间才能确定.感觉有点像C++的多态? var a = 1; var obj = { a: 2, fn: function() { ...

  3. SQL语句查询表中的所有约束

    select * from sysobjects where parent_obj in(select id from sysobjects where name='表名') 或者 exec sp_h ...

  4. QT信号和槽

    QT信号和槽 ============ 信号和槽是一种高级接口,应用于对象之间的通信,它是 QT 的核心特性.要正确的处理信号和槽,必须借助一个称为 moc(Meta Object Compiler) ...

  5. zookeeper详解

    ZooKeeper 1.Zookeeper(***必须掌握***) 官方网址:http://zookeeper.apache.org/ Ø 什么是Zookeeper? l  Zookeeper 是 G ...

  6. 让普通 Java 类自动感知 Activity Lifecycle

    背景 在 Android 开发中,我们都很熟悉 Activity 的 Lifecycle,并且会在特定的 Lifecycle 下执行特定的操作.当然,我们清楚 Lifecycle 本身是带有 Andr ...

  7. 使用原生JavaScript的Canvas实现拖拽式图形绘制,支持画笔、线条、箭头、三角形、矩形、平行四边形、梯形以及多边形和圆形,不依赖任何库和插件,有演示demo

    前言 需要用到图形绘制,没有找到完整的图形绘制实现,所以自己实现了一个 - - 一.实现的功能 1.基于oop思想构建,支持坐标点.线条(由坐标点组成,包含方向).多边形(由多个坐标点组成).圆形(包 ...

  8. ubuntu 14.04搭建PHP项目基本流程

    首先准备需要安装东西的列表1.apache服务器,2.php,3.mysql,4.几个软件包的链接包,安装方式是以apt-get方式安装; 1.安装apache服务器: apt-get install ...

  9. WebService--jax-spring集成

    如果使用javax.jws内容编写webservice,则只能通过将程序打成jar包的形式运行,如果要想通过web容器进行发布,则需要使用其他webservice框架.下面介绍jaxws与spring ...

  10. meta 是什么??

    META http-equiv 大全HTTP-EQUIV类似于HTTP的头部协议,它回应给浏览器一些有用的信息,以帮助正确和精确地显示网页内容.常用的HTTP-EQUIV类型有: 1.Content- ...