题目地址: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) 解题报告的更多相关文章

  1. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  2. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  3. Codeforces Round #380 (Div. 2) 解题报告

    第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...

  4. Codeforces Round #216 (Div. 2)解题报告

    又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<];    ,m2=;    ;i ...

  5. Codeforces Round #281 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...

  6. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

  7. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

  8. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  9. Codeforces Round #479 (Div. 3)解题报告

    题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...

随机推荐

  1. Error: CompareBaseObjectsInternal can only be called from the main thread

    Posted: 01:39 PM 06-17-2013 hi, we're working on a project where we need to do some calculations on ...

  2. Yii学习笔记之中的一个(安装与基础环境的配置)

    0. 下载yii http://www.yiiframework.com/download/ 1. 訪问 basic 基础文件夹下的 web 文件夹 出现图1 的错误 :    Invalid Con ...

  3. bzoj4032: [HEOI2015]最短不公共子串(SAM+DP)

    4032: [HEOI2015]最短不公共子串 题目:传送门 题解: 陈年老题良心%你赛膜爆嘎爷 当初做题...一眼SAM...结果只会两种直接DP的情况... 情况1: 直接设f[i][j] 表示的 ...

  4. UESTC--1263--The Desire of Asuna(贪心)

    The Desire of Asuna Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu Su ...

  5. Visual Studio2013下Magick++配置方法

    声明:本文系作者原创,如需转载请保持文章完整并注明出处(http://blog.csdn.net/u010281174/article/details/52224829). ImageMagick是一 ...

  6. js-apply call bind 浅析

    call 1.第一个参数指定了this,第二个参数传给this,也就是call前面的函数,作为他的参数第三个参数也一样 指定了this,就是执行环境,greet的this在i里面找 function ...

  7. P1343 地震逃生

    题目描述 汶川地震发生时,四川**中学正在上课,一看地震发生,老师们立刻带领x名学生逃跑,整个学校可以抽象地看成一个有向图,图中有n个点,m条边.1号点为教室,n号点为安全地带,每条边都只能容纳一定量 ...

  8. [原创]c语言中const与指针的用法

    最近一直在准备笔试,补补大一大二欠下的课.复习c语言时碰见这么个题:   1 2 3 4 5 int a=248, b=4; int const c=21; const int *d=&a;  ...

  9. 『转』How to Think About Your Career

    开始工作的伊始,逐渐转载及阅读Medium上知名华裔设计师Julie Zhuo的文章,这是她在medium上的介绍:Product design VP @ Facebook. Lover of foo ...

  10. Java中更精确的计时

    我们一般的java运输计时代码是 long begintime = System.currentTimeMillis(); //运算代码 long endtinme=System.currentTim ...