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 直 ...
随机推荐
- 运行shell命令
首先将shell命令命名为.sh文件 将上面的代码保存为test.sh.并 cd 到对应文件夹: chmod +x ./test.sh #使脚本具有运行权限 ./test.sh #运行脚本 假设报错/ ...
- UVA 1515 Pool construction 最大流跑最小割
Pool construction You are working for the International Company for Pool Construction, a constructio ...
- CGContext含义
代码 含义 CGContextRef context = UIGraphicsGetCurrentContext(); 设置上下文 CGContextMoveToPoint 开始画线 CGContex ...
- Codeforces 232E - Quick Tortoise bitset+分治
题意: 思路: //By SiriusRen #include <cstdio> #include <bitset> #include <vector> using ...
- ZYQAssetPickerController的使用,不错的图片选择
import UIKit class ViewController: UIViewController,ZYQAssetPickerControllerDelegate,UIImagePickerCo ...
- Android: HowTo设置app不被系统kill掉
有一种方法可以设置app永远不会被kill,AndroidManifest.xml 中添加: android:persistent="true" 适用于放在/system/app下 ...
- Log4Net快速配置
1. Log4NET的概念: a) 级别:trace.debug.info.warn.error.fatal.常用debug(调试信息,程序员临时跟踪执行,在正式运行的项目中应该不显示):warn(警 ...
- js通过经纬度计算两点之间的距离
最近这几天在做地图的时候,获取到目的地经纬度和当前所在位置的经纬度,通过这几个参数,用js代码就能获取到这两点之间的直线距离: function (lat1, lng1, lat2, lng2) { ...
- SQL--left join ,inner join, right jion, Limit
SQL Limit 语句 用于返回规定的数量记录.当数据库中的数据量十分庞大时,可以使用,返回指定的数量记录. 语句如:select * from grade limit 5.返回grade表中的前面 ...
- c++ sort函数的用法
C++ sort函数用法 FROM:http://hi.baidu.com/blackdemonfish/blog/item/e2c1d655d702a45ed0090652%2Ehtml 最近算法作 ...