Codeforces Round #274 (Div. 2)
A 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 ;
}
B 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)的更多相关文章
- 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 ...
- 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/ ...
- 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 ...
- codeforces水题100道 第八题 Codeforces Round #274 (Div. 2) A. Expression (math)
题目链接:http://www.codeforces.com/problemset/problem/479/A题意:给你三个数a,b,c,使用+,*,()使得表达式的值最大.C++代码: #inclu ...
- 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 ...
- Codeforces Round #274 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/479 这次自己又仅仅能做出4道题来. A题:Expression 水题. 枚举六种情况求最大值就可以. 代码例如以下: #inc ...
- Codeforces Round #274 Div.1 C Riding in a Lift --DP
题意:给定n个楼层,初始在a层,b层不可停留,每次选一个楼层x,当|x-now| < |x-b| 且 x != now 时可达(now表示当前位置),此时记录下x到序列中,走k步,最后问有多少种 ...
- 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 ...
- Codeforces Round #274 (Div. 2) --A Expression
主题链接:Expression Expression time limit per test 1 second memory limit per test 256 megabytes input st ...
随机推荐
- 通过URLHttpConnection方式来取得图片,并且显示在ImageView上
界面: 代码xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xml ...
- [terry笔记]Oracle数据泵-schema导入导出
数据泵是10g推出的功能,个人倒数据比较喜欢用数据泵. 其导入的时候利用remap参数很方便转换表空间以及schema,并且可以忽略服务端与客户端字符集问题(exp/imp需要排查字符集). 数据泵也 ...
- [Prism框架实用分享]如何在主程序中合理的弹出子窗体
大家好 说起子窗体,大家都会想到ChildWindow,多熟悉的一个控件.不错,Sliverlight中已经提供了子窗体的具体实现,而在WPF中却没有这么好的事情(有的第三方控件商已经提供此控件).最 ...
- SQL Server 一些关键字详解(一)
1.CROSS APPLY 和OUTER APPLY MSDN解释如下(个人理解不是很清晰): 使用 APPLY 运算符可以为实现查询操作的外部表表达式返回的每个行调用表值函数.表值函数作为右输入,外 ...
- JavaWeb之 JSP:内置对象,EL表达式,JSP标签基础
JSP的内置对象 什么是JSP的内置对象呢? 在JSP页面进行编程的时候,如果我们要使用一些对象,如:HttpSession,ServletConfig,ServletContext这些对象,如果每次 ...
- 小心指针被delete两次
C++类中,有时候使用到传值调用(对象实体做参数),遇到这种情况,可要小心了!特别是当你所传值的对象生命周期较长,而非临时对象(生命周期段)的时候.来看看下面的情况: #include <ios ...
- hdu 5273 Dylans loves sequence
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5273 Dylans loves sequence Description Dylans is give ...
- Windows Phone Emoji
今天基于项目的需要,研究了一下windows phone 8里面的Emoji实现.如果大家用过wp版本的微信或者qq,相比一定对它里面的表情符号影像深刻吧!是的,只要你细看一下,其实在微信里面包括两种 ...
- Quartus II Error总结与解答
(1).Error (209015): Can't configure device. Expected JTAG ID code 0x020B20DD for device 1, but found ...
- ALTERA MAX10官方评估板,新鲜出炉!
刚刚拿到骏龙提供的ALTERA MAX10官方评估板,还热乎呢,呵呵!赶紧跟大家分享一下 板子很简单,把IO口都扩展出来了,其他功能基本上没有. FPGA型号是10M08SAE144C8GES,144 ...