题目地址: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. Android实现能够揉动的图片

    public class Demo01 extends Activity{ private Bitmap bitmap = null; @Override protected void onCreat ...

  2. angularjs1-过滤器

    <!DOCTYPE html> <html> <body> <header> <meta http-equiv="Content-Typ ...

  3. HttpClient学习系列 -- 学习总结

    jar包: HttpClient 4.x版本 简要介绍 HttpComponents 包括 HttpCore包和HttpClient包 HttpClient:Http的执行http请求 Default ...

  4. nyoj--118--修路方案(次小生成树)

    修路方案 时间限制:3000 ms  |  内存限制:65535 KB 难度:5 描述 南将军率领着许多部队,它们分别驻扎在N个不同的城市里,这些城市分别编号1~N,由于交通不太便利,南将军准备修路. ...

  5. poj--3207--Ikki's Story IV - Panda's Trick(2-sat)

    Ikki's Story IV - Panda's Trick Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %I64d ...

  6. 不使用Store安装WSL

    Windows Store经常会因为各种原因打不开, 这时候我们可以尝试直接下载安装WSL     1. PowerShell里运行下载: PS C:\WINDOWS\system32> Inv ...

  7. 31.QT坐标系

    dialog.h #ifndef DIALOG_H #define DIALOG_H #include <QDialog> #include <QLabel> #include ...

  8. [转]Linux+XAMPP+eolinker开源版v3.2.4

    eolinker是一个由国人开源的接口管理系统(AMS),特性及介绍详见开源中国-eolinker首页. 搭建步骤参考:eolinker开源指南 系统环境:CentOS Linux release 7 ...

  9. 编译libvlc。。。

    https://wiki.videolan.org/Win32Compile按照官网教程,安装所需工具,参考 :http://qjw.qiujinwu.com/blog/2014/12/08/cros ...

  10. WPF MVVM 从Prism中学习设计模式之Event Aggregator 模式

    Prism简介 Prism是由微软Patterns & Practices团队开发的项目,目的在于帮助开发人员构建松散耦合的.更灵活.更易于维护并且更易于测试的WPF应用或是Silverlig ...