Codeforces Round #274 (Div. 2)
A http://codeforces.com/contest/479/problem/A
枚举情况
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int a,b,c;
while(~scanf("%d%d%d",&a,&b,&c)){
int ans=;
ans=max(ans,a+b+c);
ans=max(ans,a*b*c);
ans=max(ans,a*b+c);
ans=max(ans,a+b*c);
ans=max(ans,(a+b)*c);
ans=max(ans,a*(b+c));
printf("%d\n",ans);
}
return ;
}
B http://codeforces.com/contest/479/problem/B
暴力,每次拿一个,然后排序。
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
const int inf=0x3f3f3f3f;
struct G{
int val,id;
friend bool operator <(const G &a,const G &b){
return a.val<b.val;
}
}g[];
struct A{
int x,y;
}now;
vector<A> ans;
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
int big=,sma=inf,cha;
for(int i=;i<n;i++){
scanf("%d",&g[i].val);
g[i].id=i+;
big=max(big,g[i].val);
sma=min(sma,g[i].val);
}
cha=big-sma;
ans.clear();
while(k--&&cha){
sort(g,g+n);
g[].val++;
g[n-].val--;
big=;
sma=inf;
for(int i=;i<n;i++){
big=max(big,g[i].val);
sma=min(sma,g[i].val);
}
if(big-sma>cha) break;
cha=big-sma;
now.x=g[n-].id;
now.y=g[].id;
ans.push_back(now);
}
printf("%d %d\n",cha,ans.size());
int len=ans.size();
for(int i=;i<len;i++){
printf("%d %d\n",ans[i].x,ans[i].y);
}
}
return ;
}
c
贪心
#include<cstdio>
#include<algorithm>
using namespace std;
const int M=;
struct G{
int a,b;
friend bool operator <(const G &a,const G &b){
return a.a<b.a;
}
}g[M];
int main(){
int n;
while(~scanf("%d",&n)){
for(int i=;i<n;i++){
scanf("%d%d",&g[i].a,&g[i].b);
}
sort(g,g+n);
int now=;
for(int i=;i<n;){
int s=i,t;
int big=;
int sma=0x3f3f3f3f;
for(int j=i;j<n;j++){
if(g[i].a==g[j].a){
t=j;
big=max(big,g[j].b);
sma=min(sma,g[j].b);
}
else{
break;
}
}
if(big<g[i].a&&sma>=now){
now=big;
}
else{
now=g[i].a;
}
i=t+;
}
printf("%d\n",now);
}
return ;
}
d
map 判断是否存在
#include<cstdio>
#include<map>
using namespace std;
const int M=1e5+;
int a[M];
int l;
map<int,bool> mp;
bool has(int x,int y) {
if(mp[x+y]||mp[x-y]) return true;
return false;
}
bool in(int x) {
if(x>=&&x<=l) return true;
return false;
}
int main() {
int n,x,y;
while(~scanf("%d%d%d%d",&n,&l,&x,&y)) {
mp.clear();
for(int i=; i<n; i++) {
scanf("%d",&a[i]);
mp[a[i]]=true;
}
bool fx=false,fy=false;
for(int i=; i<n; i++) {
if(has(a[i],x)) {
fx=true;
}
if(has(a[i],y)) {
fy=true;
}
}
if(fx&&fy) {
puts("");
continue;
}
if(!fx&&fy) {
puts("");
printf("%d\n",x);
continue;
}
if(fx&&!fy) {
puts("");
printf("%d\n",y);
continue;
}
int ans=-;
for(int i=; i<n; i++) {
if(in(a[i]-x)&&has(a[i]-x,y)) {
ans=a[i]-x;
break;
}
if(in(a[i]+x)&&has(a[i]+x,y)) {
ans=a[i]+x;
break;
}
if(in(a[i]-y)&&has(a[i]-y,x)) {
ans=a[i]-y;
break;
}
if(in(a[i]+y)&&has(a[i]+y,x)) {
ans=a[i]+y;
break;
}
}
if(ans!=-) {
puts("");
printf("%d\n",ans);
} else {
puts("");
printf("%d %d\n",x,y);
}
}
return ;
}
end
Codeforces Round #274 (Div. 2)的更多相关文章
- Codeforces Round #274 (Div. 1) C. Riding in a Lift 前缀和优化dp
C. Riding in a Lift Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/pr ...
- Codeforces Round #274 (Div. 1) B. Long Jumps 数学
B. Long Jumps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/ ...
- Codeforces Round #274 (Div. 1) A. Exams 贪心
A. Exams Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/problem/A Des ...
- codeforces水题100道 第八题 Codeforces Round #274 (Div. 2) A. Expression (math)
题目链接:http://www.codeforces.com/problemset/problem/479/A题意:给你三个数a,b,c,使用+,*,()使得表达式的值最大.C++代码: #inclu ...
- Codeforces Round #274 (Div. 2)-C. Exams
http://codeforces.com/contest/479/problem/C C. Exams time limit per test 1 second memory limit per t ...
- Codeforces Round #274 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...
- Codeforces Round #274 Div.1 C Riding in a Lift --DP
题意:给定n个楼层,初始在a层,b层不可停留,每次选一个楼层x,当|x-now| < |x-b| 且 x != now 时可达(now表示当前位置),此时记录下x到序列中,走k步,最后问有多少种 ...
- Codeforces Round #274 (Div. 2) E. Riding in a Lift(DP)
Imagine that you are in a building that has exactly n floors. You can move between the floors in a l ...
- Codeforces Round #274 (Div. 2) --A Expression
主题链接:Expression Expression time limit per test 1 second memory limit per test 256 megabytes input st ...
随机推荐
- 第六章Linux的文件权限与目录配置
一.Linux用户分类 1.Linux用户分为:(文件|目录)所有者(OWN),(同组内的)用户组,其他人; 2.一个天神:root;,几乎能完成任何事.... 二.目录权限的意义 目录的权限和文件的 ...
- 测试C#代码执行时间
这个测试方法不是太精确,不过在同等环境下 可以测试下C#代码逻辑的执行性能吧 网上Copy来的. System.Diagnostics.Stopwatch stopwatch = new System ...
- 设置SVN hooks实现自动发布
# CentOS下安装SVN yum -y install subversion svnserve --version cd /home/ mkdir svn cd svn/ /usr/bin/svn ...
- Lex+YACC详解
1. 简介 只要你在Unix环境中写过程序,你必定会邂逅神秘的Lex&YACC,就如GNU/Linux用户所熟知的Flex&Bison,这里的Flex就是由Vern Paxon实现的一 ...
- Java之HttpURLConnection的变态事: Keep-Alive
HttpURLConnection的变态事: Keep-Alive JDK自带的HttpURLConnection默认启动Keep-Alive, 使用后的HttpURLConnection会放入池里重 ...
- [译]AMQP 0-9-1 Quick Reference : basic
Basic basic.ack(delivery-tag delivery-tag, bit multiple)Support: fullAcknowledge one or more message ...
- Reverse String
Write a function that takes a string as input and returns the string reversed. Example:Given s = &qu ...
- 用Swift重写公司OC项目(Day1)--程序的AppIcon与LaunchImage如何设置
公司之前的APP呢经过了两次重写,都是使用OC由本人独立开发的,不过这些东西我都不好意思说是自己写的,真心的一个字:丑!!! 客观原因来说主要是公司要的特别急,而且注重的是功能而非效果,公司的美工之前 ...
- 引用类型a=b
List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); Cache["Key ...
- 如何破解UltraEdit
在断网的前提下,软件->帮助->注册->激活->脱机激活—>用户和密码随便输入->还有两个空着,就是该用注册机激活了. 打开注册机->输入ULtredit的自 ...