zoukankan      html  css  js  c++  java
  • Harbinger vs Sciencepal

    Harbinger vs Sciencepal 

    题意:给你n对人, 每一对都有2个人,每个人分别有一个值, 现在将每队人拆开塞入2组,要求分完这n对人之后,2个组的差值最小。

    题解:将每队人的差值算出来,并且对于差值求和 tot, 然后这个题目就变成了给你n个数, 分成2组, 求差值最小的题目, 对差值进行跑背包操作就好了。

             这份代码用bitset完成的, 因为在练习这个东西。

    代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
     4 #define LL long long
     5 #define ULL unsigned LL
     6 #define fi first
     7 #define se second
     8 #define pb push_back
     9 #define lson l,m,rt<<1
    10 #define rson m+1,r,rt<<1|1
    11 #define max3(a,b,c) max(a,max(b,c))
    12 #define min3(a,b,c) min(a,min(b,c))
    13 typedef pair<int,int> pll;
    14 const int INF = 0x3f3f3f3f;
    15 const LL mod = 1e9+7;
    16 const int N = 200*250+10;
    17 bitset<N> b;
    18 int a[N];
    19 int main(){
    20     ///Fopen;
    21     int T;
    22     scanf("%d", &T);
    23     while(T--){
    24         b.reset();
    25         b[0] = 1;
    26         int n, v, u, tot = 0;
    27         scanf("%d", &n);
    28         for(int i = 1; i <= n; i++){
    29             scanf("%d%d", &u, &v);
    30             a[i] = abs(u-v);
    31             tot += a[i];
    32         }
    33         for(int i = 1; i <= n; i++){
    34             b |= (b << a[i]);
    35         }
    36         int l = 0;
    37         for(int i = tot/2; i >= 0; i--){
    38             if(b[i]){
    39                 l = i;
    40                 break;
    41             }
    42         }
    43         int ans = tot - 2*l;
    44         printf("%d
    ", ans);
    45     }
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    禁止浏览器缩放功能。
    布局
    设置页面大小
    常用英语
    iOS沙盒路径的简单介绍
    关于 pragma使用
    3Dtouch API Peek and Pop
    3Dtouch API Home Screen Quick Actions
    创建一个.framework静态库
    新学期和学生一起尝试使用博客
  • 原文地址:https://www.cnblogs.com/MingSD/p/8931693.html
Copyright © 2011-2022 走看看