I. Intergalactic Bidding---Gym101933(大整数+贪心)

Intergalactic Bidding

Time Limit: 1 Sec Memory Limit: 128 Mb

上面的链接是比赛的,已经交不了了,如果想练一练的话可以在这里:
练习链接https://codeforces.com/gym/101933/problem/I
Description
Today the Intergalactic Council of Pebble Coins (ICPC) conducted an intergalactic auction of the Neutronium Chaos Pebble Coin (NCPC). This coin, which was forged in the Ancient Coin Machine (ACM), is rumored to be the key to ruling the universe.

Due to the extremely competitive nature of the auction, as well as the odd mechanics of the intergalactic currency used (far too advanced for mere mortals to understand), the auction was conducted with the following rules:

only one participant was allowed to make a bid at a time,

each participant was only allowed to make one bid, and

a participant making a bid had to bid at least twice the amount of the highest bid at the time.

The first participant making a bid was allowed to make a bid of any positive amount.

After the auction there were a lot of sore losers – understandably, having just lost their chance at world domination. To make the losers feel a little better and prevent possible rioting, the ICPC has decided to hold a lottery for the participants. The winners of the lottery are determined as follows. The ICPC picks a random number s. A group of participants is called winning if the sum of their bets from the auction is equal to s. A participant wins the lottery and receives a prize – a shiny Pebble Coin – if they belong to any winning group of participants.

Given the names of the participants, the bets that they made, and the random number s chosen by the ICPC, help them determine which participants won the lottery.

Input
The first line of input contains two integers n and s, where 1 ≤ n ≤ 1 000 is the number of participants, and 1 ≤ s < 10^1 000 is the random number chosen by the ICPC.

Then follow n lines describing the participants. Each line contains a string t and an integer b, where t is the name of a participant, and 1 ≤ b < 10^1 000 is the amount of his bet. The name of each participant is unique and consists of between 1 and 20 letters from the English alphabet.

Output
Output an integer k denoting the number of participants that won the lottery. Then output k​ lines containing the names of the participants that won the lottery, one per line, in any order.

Sample Input
5 63
Vader 3
Voldemort 7
BorgQueen 20
Terminator 40
Megatron 101


4 1112
Blorg 10
Glorg 1000
Klorg 1
Zlorg 100
Sample Output
3
BorgQueen
Terminator
Vader


0


题目大意是这样的,给你n个人,和一个大整数k,接下来n行,人名 之前竞拍投入的资金。搜索一个集合,里面的资金和为k并输出集合里的人名,之前的竞赛的规则是:一次只允许一位参与者出价,每个参与者只允许进行一次竞标,并且参与者出价必须至少是当时最高出价金额的两倍。第一个参与竞标的参与者可以出价任何正数。题目的数据应该有保证。
emmm,大整数的运算,套一个板子就好了,另外就是计算时候要稍微贪心算法算一下(从大到小取数,如果大的数不取的话,后面小的全部加起来也是不可能的,比如n不取的话,1/2n+1/4n+1/8n+……是不可能大于n的)。只不过当时非常坑的是,公告栏上写着:I题要字典序输出人名。emmm,然后sort了一遍交了一发WA了。怎么说呢,这题有点毒瘤,反正排序的没过,没排序的就过了,当时可谓是哇(WA)声一片,都以为是大整数写错了emmm。。。不过幸好YD大佬勇敢地试了一发没有排序的,然后A了,emmmm。。。这铁定是在搞事情。具体解答看代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
const int maxn = 1111;
char s[maxn];
int ans[maxn],sum;
struct bigint{
    int length;
    int  x[maxn];
    bigint (){
        length=0;
        memset(x,0,sizeof x);
    }
    bool operator <(const bigint &b)const {
        if (length<b.length) return 1;
        if (length>b.length) return 0;
        for (int i=length-1;i>=0;i--)
            if (x[i]>b.x[i]) return 0;
            else if (x[i]<b.x[i]) return 1;
        return 1;
    }
    bigint operator -(const bigint &b)const {
        bigint c;
        c.length=length;
        for (int i=0;i<length;i++) c.x[i]=x[i];
        int l=length;
        for (int i=0;i<l;i++) {
            if (c.x[i]<b.x[i]) {
                c.x[i+1]--;
                c.x[i]+=10;
            }
            c.x[i]-=b.x[i];
        }
        while (c.length!=0&&c.x[c.length-1]==0) c.length--;
        return c;
    }
}M;
bigint secher(char *s){
    bigint c;
    int length=strlen(s);
    for (int i=length-1;i>=0;i--)
        c.x[c.length++]=s[i]-'0';
    return c;
}
struct S{
    int id;
    char s[maxn];
    bigint x;
    bool operator <(const S &b)const {
        return b.x<x;
    }
}F[maxn];

/*bool cmp1(string s1,string s2){   //当时愚蠢地相信了公告,进行了排序
	return s1.compare(s2) < 0 ;
}*/
string p[1111];
int main(){
    int n;
    cin >> n >> s;
    M = secher(s);
    for (int i = 1;i <= n;i++) {
        cin >> F[i].s >> s;
        F[i].x = secher(s);
    }
    sort(F+1,F+n+1);      
    for (int i = 1;i <= n;i++){
        if (F[i].x < M){
            M= M - F[i].x;   //对于给定的随机数s做减法
            ans[sum++] = i;   //标记该人
        }
    }
    if (M.length != 0) sum = 0;    //不刚好等于随机数s,ans=0
    cout << sum << endl;
    for (int i = 0 ;i < sum;i++) 
    cout << F[ans[i]].s << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值