Lala Land and Apple Trees
来源:互联网 发布:mac连上wifi打不开网页 编辑:程序博客网 时间:2024/04/28 08:39
有一种痛叫做别人的代码和我的代码。一看就不是一个级别上的。。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<queue>using namespace std;#define maxn 205#define inf 0x3f3f3f3fstruct point{ int a,b; point(){};};bool cmp1(point & x,point & y){ return x.a<y.a;}bool cmp2(point & x,point & y){ return x.a>y.a;}int main(){ int n; int a,b,ls,rs,sum; //freopen("in.txt","r",stdin); while(~scanf("%d",&n)){ point left[maxn],right[maxn]; left[0].a=0,left[0].b=0; right[0].a=0,right[0].b=0; ls=1; rs=1; sum=0; for(int i=0;i<n;i++){ scanf("%d%d",&a,&b); if(a<0)left[ls].a=a,left[ls++].b=b; if(a>0)right[rs].a=a,right[rs++].b=b; if(a==0)sum+=a; } sort(right,right+rs,cmp1); sort(left,left+ls,cmp2); for(int i=1;i<ls;i++){ left[i].b+=left[i-1].b; } for(int i=1;i<rs;i++){ right[i].b+=right[i-1].b; } if(ls==rs){ sum+=right[rs-1].b+left[ls-1].b; } else if(ls>rs){ sum+=left[rs].b+right[rs-1].b; } else{ sum+=left[ls-1].b+right[ls].b; } printf("%d\n",sum); }}//别人的代码简洁明了#include<iostream>#include<utility>#include<algorithm>using namespace std;main(){int n,i,l=0,r=0,ans=0,a,b;cin>>n;pair<int,int>p[1000];for(i=0;i<n;i++){ cin>>a>>b;p[i]=make_pair(a,b);if(a<0) l++;else r++;}sort(p,p+n);for(i=max(0,l-r-1);i<=min(n,l*2);i++)ans+=p[i].second;cout<<ans;}
0 0
- Lala Land and Apple Trees
- Lala Land and Apple Trees
- Lala Land and Apple Trees
- A. Lala Land and Apple Trees
- A. Lala Land and Apple Trees
- Codeforces 558A Lala Land and Apple Trees 摘苹果
- codeforces 558A. Lala Land and Apple Trees
- Codeforces 558A Lala Land and Apple Trees(水题)
- CF 558A(Lala Land and Apple Trees-暴力)
- CF 558A Lala Land and Apple Trees
- cf 558A Lala Land and Apple Trees
- CodeForces 558A Lala Land and Apple Trees(模拟)
- CF 558 A. Lala Land and Apple Trees
- CodeForces 558A Lala Land and Apple Trees
- 【42.07%】【codeforces 558A】Lala Land and Apple Trees
- codeforces #312 558A A. Lala Land and Apple Trees(暴力)
- Codeforces 558A Lala Land and Apple Trees(Sort快排)
- Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees
- hdu 3199 Hamming Problem
- C#编程:NetworkStream类的Read
- win7 删除Windows服务的方法!
- js如何截取以逗号隔开的字符串
- 图论-最短路问题
- Lala Land and Apple Trees
- 欢迎使用CSDN-markdown编辑器
- 四大组件之 BroadcastReceiver小结
- hive 实战笔记case3
- 解决vista和win7在windows服务中交互桌面权限问题:穿透Session 0 隔离
- process and memory 对控制台输入echo hello的流程简单剖析
- 地图与定位
- 倒油问题之深搜和广搜算法
- POJ 3621(0/1分数规划,二分) Sightseeing Cows