题目链接:https://vjudge.net/contest/436484#problem/B
题目多组输入,并且x1个0,y1个1,z1个2,x2个0,y2个1,z2个2,通过题目可知,影响结果的只有(2.1)+2和(1.2)-2,其他项排除即可,而当2 .1数量不相同的时候,可通过其他无关项进行消除,所有无关项消除后再考虑(1.2)组合
以下代码:
#include<stdio.h> int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++){ int x1,x2,y1,y2,z1,z2,sum=0; scanf("%d %d %d %d %d %d",&x1,&y1,&z1,&x2,&y2,&z2); if(z1<=y2){ sum=2*z1,y2=y2-z1,z1=0; }else{ sum=2*y2,z1=z1-y2,y2=0; } if(x1<=z2){ z2=z2-x1,x1=0; }else{ x1=x1-z2,z2=0; } if(x1<=y2){ y2=y2-x1,x1=0; }else{ x1=x1-y2,y2=0; } if(x1<=x2){ x2=x2-x1,x1=0; }else{ x1=x1-x2,x2=0; } if(y1<=y2){ y2=y2-y1,y1=0; }else{ y1=y1-y2,y2=0; } if(z1<=z2){ z2=z2-z1,z1=0; }else{ z1=z1-z2,z2=0; } if(y1<=z2){ sum=sum-2*y1; }else{ sum=sum-2*z2; } printf("%d\n",sum); } return 0; }
原文:https://www.cnblogs.com/laocaigoul/p/14728453.html