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 ...
随机推荐
- java调用oracle数据库发布WebService
package com.hyan.service; import java.io.FileInputStream;import java.sql.Connection;import java.sql. ...
- TCP协议的滑动窗口协议以及流量控制
参考资料 http://blog.chinaunix.net/uid-26275986-id-4109679.html http://network.51cto.com/art/201501/4640 ...
- TCP建立连接和断开连接图解
参考博客: http://blog.csdn.net/whuslei/article/details/6667471 http://www.2cto.com/net/201310/251896.htm ...
- Windows环境下多线程编程原理与应用读书笔记(8)————信号量及其应用
<一>线程间同步原因 线程间竞争共享资源: 线程间为完成某个任务而协作: 通过互斥量可以实现线程间由于竞争所需要的同步,通过事件可以实现线程间由于协作所需要的同步. 信号量很好地将互斥量和 ...
- Uncle Tom's Inherited Land*
Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java ...
- ⑦bootstrap按钮 图片 辅助使用基础案例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Postman参数化使用以及中文乱码问题解决
1.参数化详解 准备工作,数据准备 2.使用csv文件时中文乱码可以通过使用txt文本,json文本改变调用json文件改变文件的编码格式解决 3:参数化数据调用的两种方式通过调用读取文件传入环境变量 ...
- Java 面试题:百度前200页都在这里了
基本概念 操作系统中 heap 和 stack 的区别 什么是基于注解的切面实现 什么是 对象/关系 映射集成模块 什么是 Java 的反射机制 什么是 ACID BS与CS的联系与区别 Cookie ...
- HTML的用法
今天学习了HTMIL,标签.这个东西吧,没什么很难的,就是得多练多打.今天的一些个人心得: 标签:成对存在的名称 标签注意:1.标签名放在<> 2.标签成对存在的 3.结束标签有斜杠/ 例 ...
- Unity3D游戏GC优化总结---protobuf-net无GC版本优化实践
protobuf-net优化效果图 protobuf-net是Unity3D游戏开发中被广泛使用的Google Protocol Buffer库的c#版本,之所以c#版本被广泛使用,是因为c++版本的 ...