码迷,mamicode.com
首页 > 其他好文 > 详细

Problem J. Journey with Pigs

时间:2019-04-05 12:07:52      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:单位   stdout   while   tac   getchar   com   algo   eve   价值   

Problem J. Journey with Pigs
http://codeforces.com/gym/241680/problem/J
考察排序不等式
算出来单位重量在每个村庄的收益,然后生序排列
猪的重量也生序排列
此时价值最大

技术图片
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<queue>
 4 #include<algorithm>
 5 #include<cmath>
 6 #include<ctime>
 7 #include<set>
 8 #include<map>
 9 #include<stack>
10 #include<cstring>
11 #define inf 2147483647
12 #define ls rt<<1
13 #define rs rt<<1|1
14 #define lson ls,nl,mid,l,r
15 #define rson rs,mid+1,nr,l,r
16 #define N 100010
17 #define For(i,a,b) for(long long i=a;i<=b;i++)
18 #define p(a) putchar(a)
19 #define g() getchar()
20 
21 using namespace std;
22 long long n,t;
23 long long dis[1010];
24 struct value{
25     long long poi;
26     long long v;
27 }a[1010];
28 
29 struct pig{
30     long long poi;
31     long long w;
32 }b[1010];
33 long long ans[1010];
34 
35 void in(long long &x){
36     long long y=1;
37     char c=g();x=0;
38     while(c<0||c>9){
39         if(c==-)y=-1;
40         c=g();
41     }
42     while(c<=9&&c>=0){
43         x=(x<<1)+(x<<3)+c-0;c=g();
44     }
45     x*=y;
46 }
47 void o(long long x){
48     if(x<0){
49         p(-);
50         x=-x;
51     }
52     if(x>9)o(x/10);
53     p(x%10+0);
54 }
55 
56 bool cmp1(pig a,pig b){
57     return a.w<b.w;
58 }
59 
60 bool cmp2(value a,value b){
61     return a.v<b.v;
62 }
63 
64 int main(){
65     freopen("journey.in","r",stdin);
66     freopen("journey.out","w",stdout);
67     in(n);in(t);
68     For(i,1,n){
69         in(b[i].w);
70         b[i].poi=i;
71     }
72     sort(b+1,b+n+1,cmp1);
73     For(i,1,n)
74         in(dis[i]);
75     For(i,1,n){
76         in(a[i].v);
77         a[i].poi=i;
78     }
79     For(i,1,n)
80         a[i].v=a[i].v-dis[i]*t;
81     sort(a+1,a+n+1,cmp2);
82     For(i,1,n)
83         ans[a[i].poi]=b[i].poi;
84     For(i,1,n-1){
85         o(ans[i]);p( );
86     }
87     o(ans[n]);
88 
89     return 0;
90 }
View Code

 

Problem J. Journey with Pigs

标签:单位   stdout   while   tac   getchar   com   algo   eve   价值   

原文地址:https://www.cnblogs.com/war1111/p/10658159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!