zoukankan      html  css  js  c++  java
  • Free Goodies UVA

     
    Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

    []   [Go Back]   [Status]  

    Description

    Download as PDF
     

    B  Free Goodies

     
    Petra and Jan have just received a box full of free goodies, and want to divide the goodies between them. However, it is not easy to do this fairly, since they both value different goodies differently.
     
    To divide the goodies, they have decided upon the following procedure: they choose goodies one by one, in turn, until all the goodies are chosen. A coin is tossed to decide who gets to choose the first goodie.
     
    Petra and Jan have different strategies in deciding what to choose. When faced with a choice, Petra always selects the goodie that is most valuable to her. In case of a tie, she is very considerate and picks the one that is least valuable to Jan. (Since Petra and Jan are good friends, they know exactly how much value the other places on each goodie.)
     
    Jan's strategy, however, consists of maximizing his own final value. He is also very considerate, so if multiple choices lead to the same optimal result, he prefers Petra to have as much final value as possible.
     
    You are given the result of the initial coin toss. After Jan and Petra have finished dividing all the goodies between themselves, what is the total value of the goodies each of them ends up with?
     

    Input

    On the first line a positive integer: the number of test cases, at most 100. After that per test case:
     
    • One line with an integer n (1 ≤ n ≤ 1 000): the number of goodies.
       
    • One line with a string, either "Petra" or "Jan": the person that chooses first.
       
    • n lines with two integers pi and ji (0 ≤ pi,ji ≤ 1 000) each: the values that Petra and Jan assign to the i-th goodie, respectively.
       
     

    Output

    Per test case:
    • One line with two integers: the value Petra gets and the value Jan gets. Both values must be according to their own valuations.
       
     

    Sample in- and output

    Input Output
    3
    4
    Petra
    100 80
    70 80
    50 80
    30 50
    4
    Petra
    10 1
    1 10
    6 6
    4 4
    7
    Jan
    4 1
    3 1
    2 1
    1 1
    1 2
    1 3
    1 4
    
    170 130
    14 16
    9 10
    
     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 #include <math.h>
     6 using namespace std;
     7 typedef struct point
     8 {
     9     int p,j,i;
    10 } ponit;
    11 ponit a[1005];
    12 int b[1005];
    13 bool cmp(ponit x,ponit y)
    14 {
    15     if(x.p==y.p)return x.j<y.j;
    16     return x.p>y.p;
    17 }
    18 bool cnp(ponit x,ponit y)
    19 {
    20     if(x.j==y.j)return x.p<y.p;
    21     return x.j>y.j;
    22 }
    23 bool check()
    24 {
    25     int i,sum=0;;
    26     for(i=1;i<1005;i++)
    27     {
    28         sum+=b[i];
    29         if(b[i])
    30         {
    31             if(sum>(i+1)/2)return 0;
    32         }
    33     }
    34 return 1;
    35 }
    36 int main()
    37 {
    38     int t,n,p,j,i,sum[2],st;
    39     char z[20];
    40     scanf("%d",&t);
    41     while(t--)
    42     {
    43         memset(b,0,sizeof(b));
    44         scanf("%d",&n);
    45         scanf("%s",z);
    46         for(i=0; i<n; i++)
    47             scanf("%d%d",&a[i].p,&a[i].j);
    48         sort(a,a+n,cmp);
    49         sum[0]=sum[1]=0;
    50         if(strcmp(z,"Petra")==0)sum[0]+=a[0].p,st=1;
    51         else st=0;
    52         for(i=0; st<n; i++,st++)
    53         {
    54             a[i].p=a[st].p;
    55             a[i].j=a[st].j;
    56             a[i].i=i+1;
    57         }
    58         n=i;
    59         sort(a,a+n,cnp);
    60         for(i=0;i<n;i++)
    61         {
    62             b[a[i].i]=1;
    63             if(check())sum[1]+=a[i].j;
    64             else b[a[i].i]=0,sum[0]+=a[i].p;
    65         }
    66         printf("%d %d
    ",sum[0],sum[1]);
    67     }
    68 }
    View Code
  • 相关阅读:
    CocoaPods使用详细说明
    cocoapod使用
    Android-利用LinearGradient实现文字一闪一闪
    Android5.0 CheckBox颜色修改
    android实现文字渐变效果和歌词进度的效果
    Ceph 常规操作笔记
    Git版本控制器使用总结性梳理
    CentOS 7.5 部署 MySQL 5.7 基于GTID主从复制+并行复制+半同步复制+读写分离(ProxySQL) 环境- 运维笔记 (完整版)
    Ansible-playbook 运维笔记
    Docker容器基础介绍
  • 原文地址:https://www.cnblogs.com/ERKE/p/3670947.html
Copyright © 2011-2022 走看看