zoukankan      html  css  js  c++  java
  • P2123-皇后游戏

    这题...一言难尽

     1 #include <bits/stdc++.h>
     2 #define maxn 13003
     3 #define _for(i,a,b) for(int i = (a);i < b;i ++)
     4 typedef long long ll;
     5 using namespace std;
     6 
     7 inline ll read()
     8 {
     9     ll ans = 0;
    10     char ch = getchar(), last = ' ';
    11     while(!isdigit(ch)) last = ch, ch = getchar();
    12     while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
    13     if(last == '-') ans = -ans;
    14     return ans;
    15 }
    16 inline void write(ll x)
    17 {
    18     if(x < 0) x = -x, putchar('-');
    19     if(x >= 10) write(x / 10);
    20     putchar(x % 10 + '0');
    21 }
    22 int T,n;
    23 struct chen
    24 {
    25     ll a;
    26     ll b;
    27 };
    28 chen per[20004];
    29 ll c[20004];
    30 ll suma[20004];
    31 bool cmp(chen x,chen y)
    32 {
    33     return min(x.a,y.b)==min(y.a,x.b)?x.a<y.a:min(x.a,y.b)<min(y.a,x.b);
    34 }
    35 
    36 int main()
    37 {
    38     T = read();
    39     while(T--)
    40     {
    41         n = read();
    42         _for(i,1,n+1)
    43             per[i].a = read(),per[i].b = read();
    44         sort(per+1,per+1+n,cmp);
    45         _for(i,1,n+1)
    46             suma[i] = suma[i-1] + per[i].a;
    47         _for(i,1,n+1)
    48             c[i] = max(c[i-1],suma[i]) + per[i].b;
    49         write(c[n]);
    50         printf("
    ");
    51     }
    52     return 0;
    53 }
  • 相关阅读:
    fastjson反序列化
    BaseBean构造
    easyUI_rowdata
    SVN提交报错
    jsp页面数据保留两位小数
    数据库 建立
    增删改查问
    解决plsql中文乱码问题
    oracle_解锁表
    ibatis_compareValue
  • 原文地址:https://www.cnblogs.com/Asurudo/p/11359337.html
Copyright © 2011-2022 走看看