• Problem J. Journey with Pigs


    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
  • 相关阅读:
    python---常见排序算法
    flask之session
    Python常考面试题
    MySQL一致性非锁定读原理以及MVCC简介
    mysql面试常考知识点
    数据库学习笔记4数据系统的组成
    工作记录之拯救rm -rf /*(无root权限拯救恢复基础功能)
    数据库学习笔记3数据库的系统结构
    数据库学习笔记2数据模型
    数据库学习笔记1
  • 原文地址:https://www.cnblogs.com/war1111/p/10658159.html
Copyright © 2020-2023  润新知