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 ;
}

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)的更多相关文章

  1. 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 ...

  2. 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/ ...

  3. 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 ...

  4. codeforces水题100道 第八题 Codeforces Round #274 (Div. 2) A. Expression (math)

    题目链接:http://www.codeforces.com/problemset/problem/479/A题意:给你三个数a,b,c,使用+,*,()使得表达式的值最大.C++代码: #inclu ...

  5. 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 ...

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

    题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...

  7. Codeforces Round #274 Div.1 C Riding in a Lift --DP

    题意:给定n个楼层,初始在a层,b层不可停留,每次选一个楼层x,当|x-now| < |x-b| 且 x != now 时可达(now表示当前位置),此时记录下x到序列中,走k步,最后问有多少种 ...

  8. 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 ...

  9. Codeforces Round #274 (Div. 2) --A Expression

    主题链接:Expression Expression time limit per test 1 second memory limit per test 256 megabytes input st ...

随机推荐

  1. Delphi中TStringList类常用属性方法详解

    TStrings是一个抽象类,在实际开发中,是除了基本类型外,应用得最多的. 常规的用法大家都知道,现在来讨论它的一些高级的用法. 先把要讨论的几个属性列出来: 1.CommaText 2.Delim ...

  2. How to get Financial Dimension Value from Worker Position[AX2012]

    To get financial dimension value from worker position, add a new method in hcmWorker Table with scri ...

  3. 05-树9 Huffman Codes

    哈夫曼树 Yes 需满足两个条件:1.HuffmanTree 结构不同,但WPL一定.子串WPL需一致 2.判断是否为前缀码 开始判断用的strstr函数,但其传值应为char *,不能用在strin ...

  4. c语言结构体保存并输出学生信息

    最近在学习数据结构,巩固下c语言. #include<stdio.h> /*定义结构体student并设置别名stud*/ /*typedef struct student{ int nu ...

  5. 从0 开始 WPF MVVM 企业级框架实现与说明 ---- 第二讲 WPF中 绑定

    说到WPF, 当然得从绑定说起,这也是WPF做的很成功的一个地方,这也是现在大家伙都在抛弃使用winform的其中一个主要原因,Binding这个东西从早说到完其实都说不完的,我先就做一些基本的介绍, ...

  6. uva 11538 Chess Queen<计数>

    链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  7. [JAVA][RCP] Eclipse4/RCP/Lifecycle

    E4AP provides two levels of lifecycles, for contributions and for the application. Contents [hide]  ...

  8. VS模板文件修改,自动生成注释

    VS的模板文件存放在IDE下的ItemTemplatesCache文件夹下 1.不同VS版本IDE文件夹路径个有不同,下面以VS2012为例,IDE文件夹路径如图:

  9. 读取、添加、删除、修改配置文件 如(Web.config, App.config)

    private Configuration config; public OperateConfig() : this(HttpContext.Current.Request.ApplicationP ...

  10. Controltemplate datatemplate

    DataTemplate ControlTemplate we can search many posts about this topic. some valuable link: DataTemp ...