博客
关于我
AtCoder Beginner Contest 100 D - Patisserie ABC[思维]
阅读量:535 次
发布时间:2019-03-08

本文共 994 字,大约阅读时间需要 3 分钟。

题意:n个物品,每个物品有三个属性a,b,c(可能正,可能负) .现在取m个,使得|sigma a| + |sigma b| + |sigma c| 最大化

思路:考虑绝对值里的符号.每个绝对值里的符号取值无非有2种情况. 趋向   极负/极正  .那么就有2*2*2=8种符号可能.每次排序nlogn,按i*a+j*b+c*k排序.8种情况必有一种情况满足要求

#include
#define PI acos(-1.0)#define pb push_back#define F first#define S secondusing namespace std;typedef long long ll;const int N=1e5+5;//ll a[N],sum[N];struct node{ ll a,b,c;}p[N];int n,m,i,j,k;bool cmp(node x,node y){ return x.a*i+x.b*j+x.c*k>y.a*i+y.b*j+y.c*k;}int main(void){ ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); cin >> n>>m; ll ans=0; for(int i=1;i<=n;i++) cin >>p[i].a>>p[i].b >>p[i].c; for( i=-1;i<=1;i+=2){// i,j,k分别代表绝对值里的符号趋向 for( j=-1;j<=1;j+=2){ for( k=-1;k<=1;k+=2){ sort(p+1,p+1+n,cmp); ll t[4]={0}; for(int te=1;te<=m;te++) t[1]+=p[te].a,t[2]+=p[te].b,t[3]+=p[te].c; ans=max(ans,t[1]*i+t[2]*j+t[3]*k); } } } cout << ans << endl; return 0;}

转载地址:http://xykiz.baihongyu.com/

你可能感兴趣的文章
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>