Codeforces Round #274 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/479
这次自己又仅仅能做出4道题来。
A题:Expression
水题。
枚举六种情况求最大值就可以。
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define LL __int64
int main()
{
LL a, b, c, d[10];
while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
{
d[0]=a*b*c;
d[1]=(a+b)*c;
d[2]=a+b+c;
d[3]=a*(b+c);
d[4]=a+b*c;
d[5]=a*b+c;
sort(d,d+6);
printf("%I64d\n",d[5]);
}
return 0;
}
B题:Towers
水题。
每次都是将最多的拿出一个给最少的,直到最大的与最少的相差小于或等于1.
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define LL __int64
struct node
{
int x, num;
}fei[1000];
int cmp(node x, node y)
{
return x.x<y.x;
}
int a[2000], b[2000];
int main()
{
int n, m, i, j, cnt, ans;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d",&fei[i].x);
fei[i].num=i;
}
cnt=0;
while(m--)
{
sort(fei,fei+n,cmp);
if(fei[n-1].x-fei[0].x<=1) break;
a[cnt]=fei[n-1].num;
b[cnt++]=fei[0].num;
fei[n-1].x--;
fei[0].x++;
}
sort(fei,fei+n,cmp);
printf("%d %d\n",fei[n-1].x-fei[0].x, cnt);
for(i=0;i<cnt;i++)
{
printf("%d %d\n",a[i]+1,b[i]+1);
}
}
return 0;
}
C题:Exams
还是水。。小贪心
小贪心。先按标记日期排个序,然后扫一遍就可以,能用小的就优先考虑小的。
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define LL __int64
struct node
{
int x, y;
}fei[6000];
int cmp(node x, node y)
{
if(x.x==y.x)
return x.y<y.y;
return x.x<y.x;
}
int main()
{
int n, i, j, ans, k, x1, x2;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
{
scanf("%d%d",&fei[i].x,&fei[i].y);
}
sort(fei,fei+n,cmp);
k=1;
for(i=0;i<n;i++)
{
if(fei[i].y>=k)
{
k=fei[i].y;
}
else
{
k=fei[i].x;
}
}
printf("%d\n",k);
}
return 0;
}
D题:
还是水。。。
。
二分。
分别考虑4种情况,x,y,x+y,y-x。然后用二分找差值为这四个数的。
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define LL __int64
int a[110000];
int bin_search(int x, int y, int high)
{
int low=0, mid;
while(low<=high)
{
mid=low+high>>1;
if(y-a[mid]==x) return 1;
else if(y-a[mid]>x) low=mid+1;
else high=mid-1;
}
return 0;
}
int main()
{
int n, l, x, y, i, j, k, flag1, flag2;
while(scanf("%d%d%d%d",&n,&l,&x,&y)!=EOF)
{
flag1=flag2=0;
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
if(a[i]==x)
flag1=1;
if(a[i]==y)
flag2=1;
}
if(flag1&&flag2)
{
printf("0\n");
}
else
{
flag1=flag2=0;
for(i=1;i<n;i++)
{
if(bin_search(x,a[i],i-1))
{
flag1=1;
break;
}
}
for(i=1;i<n;i++)
{
if(bin_search(y,a[i],i-1))
{
flag2=1;
}
}
if(flag1&&flag2)
{
printf("0\n");
}
else if(flag1) printf("1\n%d\n",y);
else if(flag2) printf("1\n%d\n",x);
else
{
int flag=0;
for(i=1;i<n;i++)
{
if(bin_search(y+x,a[i],i-1))
{
flag=1;
break;
}
}
if(flag)
{
printf("1\n%d\n",a[i]-x);
}
else
{
flag=0;
for(i=1;i<n;i++)
{
if(bin_search(y-x,a[i],i-1)&&(a[i]-y>=0||a[i]+x<=l))
{
flag=1;
break;
}
}
if(flag&&a[i]-y>=0)
{
printf("1\n%d\n",a[i]-y);
}
else if(flag&&a[i]+x<=l)
{
printf("1\n%d\n",a[i]+x);
}
else
{
printf("2\n%d %d\n",x,y);
}
}
}
}
}
return 0;
}
Codeforces Round #274 (Div. 2) 解题报告的更多相关文章
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #382 (Div. 2) 解题报告
CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...
- Codeforces Round #380 (Div. 2) 解题报告
第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...
- Codeforces Round #216 (Div. 2)解题报告
又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<]; ,m2=; ;i ...
- Codeforces Round #281 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...
- Codeforces Round #277 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- Codeforces Round #350 (Div. 2)解题报告
codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...
- Codeforces Round #479 (Div. 3)解题报告
题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...
随机推荐
- DELL灵越 n4030笔记本安装win7之无线网卡驱动安装
本人安装的是win7 32位专业版,安装完成后发现无线网卡找不到了.DELL灵越 n4030自己带无线网卡的.问题的根源在于无线网卡驱动没有安装或没有安装匹配的无线网卡驱动. 那么问题来了.什么无线网 ...
- 使用fiddler模拟http get
wireshark抓到一个http get数据包 GET /Hero/zhCN/client/alert?build=zhCN&targetRegion=0&homeCountry= ...
- hdoj--2803--The MAX(水题)
The MAX Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- 什么是jquery中的事件委派?
在jquery中有一个很重要的概念——事件委派,相信很多搞前端开发的人都听说过,零度逍遥本来对此不是十分理解,但经过一个高人的指点后,才发现这个功能还是蛮强大的,今天就给大家分享一下. 事件委派的定义 ...
- 《ServerLess 给前端带来了什么》笔记
1. Serverless 是什么 Serverless “无服务器架构”,即大量依赖第三方服务(也叫做后端即服务,即“BaaS”)或暂存容器中运行的自定义代码(函数即服务,即“FaaS”)的应用程序 ...
- Redis学习笔记(五) 基本命令:Hash操作
原文链接:http://doc.redisfans.com/hash/index.html 学习前先明确一下概念,这里我们把Redis的key称作key(键),把数据结构hash中的key称为fiel ...
- 爬虫概念与编程学习之如何爬取视频网站页面(用HttpClient)(二)
先看,前一期博客,理清好思路. 爬虫概念与编程学习之如何爬取网页源代码(一) 不多说,直接上代码. 编写代码 运行 <!DOCTYPE html><html><head& ...
- Upload图片-单张
上传图片全不怕,轻松实现图片上传, 可以实现显示缩略图喔: 后台代码: protected void btnpic_upload_Click(object sender, EventArgs e) { ...
- 不得了,微软原生提供 AI 人工智能 API,而且面向网页开放
微软原生人工智能(AI) API 不得了,微软原生提供 AI 人工智能 API,而且面向网页开放
- 浅谈javascript的面向对象思想
面向对象的三大基本特性 封装(把相关的信息(无论数据或方法)存储在对象中的能力) 继承(由另一个类(或多个类)得来类的属性和方法的能力) 多态(一个对象在不同情况下的多种形态) 定义类或对象 第一种: ...