• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

wvellichor

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

五一训练礼包B-2

You are given two sequences a1,a2,…,ana1,a2,…,an and b1,b2,…,bnb1,b2,…,bn. Each element of both sequences is either 00, 11 or 22. The number of elements 00, 11, 22 in the sequence aa is x1x1, y1y1, z1z1 respectively, and the number of elements 00, 11, 22 in the sequence bb is x2x2, y2y2, z2z2 respectively.

You can rearrange the elements in both sequences aa and bb however you like. After that, let's define a sequence cc as follows:

Ci={

  ai bi  ,ai>bi;

  0  ,ai=bi;

  -ai bi  ,ai<bi;

}

You'd like to make ∑ni=1ci∑i=1nci (the sum of all elements of the sequence cc) as large as possible. What is the maximum possible sum?

 

由于只有0,1,2,ci的取值只有2,0,-2三个值。

1.ci=2时,ai=2(z1),bi=1(y2);

2.ci=-2时,ai=1(y1),bi=2(z2);

3.其余ci=0;

使分最高,则“1”要多,“2”要少。

#include<stdio.h>
int main(){
    int t,x1,y1,z1,x2,y2,z2,two,ftwo;
    scanf("%d",&t);
    while(t--){
        scanf("%d %d %d %d %d %d",&x1,&y1,&z1,&x2,&y2,&z2);
        if(z1>y2)
            two = y2;
        else
            two = z1;
        y2-=two;
        z1-=two;
        if(y1-x2-y2>0)
            ftwo=y1-x2-y2;
        else
            ftwo=0;
        printf("%d\n",2*(two-ftwo));
    }
    return 0;
}

 

posted on 2021-05-05 21:03  wvellichor  阅读(27)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3