zoukankan      html  css  js  c++  java
  • [Noip2012] 国王游戏

    题目描述

    恰逢 $HH H$ 国国庆,国王邀请 $n nn$ 位大臣来玩一个有奖游戏。首先,他让每个大臣在左、右手上面分别写下一个整数,国王自己也在左、右手上各写一个整数。然后,让这 $nnn$ 位大臣排成一排,国王站在队伍的最前面。排好队后,所有的大臣都会获得国王奖赏的若干金币,每位大臣获得的金币数分别是:排在该大臣前面的所有人的左手上的数的乘积除以他自己右手上的数,然后向下取整得到的结果。

    国王不希望某一个大臣获得特别多的奖赏,所以他想请你帮他重新安排一下队伍的顺序,使得获得奖赏最多的大臣,所获奖赏尽可能的少。注意,国王的位置始终在队伍的最前面。

    输入输出格式

    输入格式:

    第一行包含一个整数 $n nn $,表示大臣的人数。

    第二行包含两个整数 $aaa$ 和$ bbb$ ,之间用一个空格隔开,分别表示国王左手和右手上的整数。

    接下来 $n n$ 行,每行包含两个整数 $a aa$ 和$ bbb $,之间用一个空格隔开,分别表示每个大臣左手和右手上的整数。

    输出格式:

    一个整数,表示重新排列后的队伍中获奖赏最多的大臣所获得的金币数。

    输入输出样例

    输入样例#1: 复制
    3 
    1 1 
    2 3 
    7 4 
    4 6 
    输出样例#1: 复制
    2

    说明

    【输入输出样例说明】

    按 $1 11 、 222 、 333$ 这样排列队伍,获得奖赏最多的大臣所获得金币数为 $222 $;

    111 、 333 、 222 这样排列队伍,获得奖赏最多的大臣所获得金币数为 2 22 ;

    222 、 111 、 333 这样排列队伍,获得奖赏最多的大臣所获得金币数为 222 ;

    2 22 、 333 、 11 1 这样排列队伍,获得奖赏最多的大臣所获得金币数为 9 99 ;

    333 、 111 、 22 2 这样排列队伍,获得奖赏最多的大臣所获得金币数为 222 ;

    3 33 、 222 、 111 这样排列队伍,获得奖赏最多的大臣所获得金币数为 999 。

    因此,奖赏最多的大臣最少获得 22 2 个金币,答案输出 222 。

    【数据范围】

    对于 20%的数据,有 $1≤n≤10,0<a,b<81≤ n≤ 10,0 < a,b < 81n10,0<a,b<8$ ;

    对于 40%的数据,有 $1≤n≤20,0<a,b<8 1≤ n≤20,0 < a,b < 81n20,0<a,b<8$ ;

    对于 60%的数据,有$1≤n≤1001≤ n≤1001n100$ ;

    对于 60%的数据,保证答案不超过$ 10910^9109$ ;

    对于 100%的数据,有 $1≤n≤1,000,0<a,b<100001 ≤ n ≤1,000,0 < a,b < 100001n1,000,0<a,b<10000$ 。

    NOIP 2012 提高组 第一天 第二题


    这个latex太恶心了不想改了。

    贪心参见题解233.

    高精乘高精除。


    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    inline int read() {
        int res=0;char ch=getchar();
        while(!isdigit(ch))ch=getchar();
        while(isdigit(ch))res=(res<<3)+(res<<1)+(ch^48), ch=getchar();
        return res;
    }
    #define ll long long
    #define reg register
    
    int n;
    struct date {
        int a, b;
        int c;
    }p[1005];
    
    inline bool cmp (date a, date b)
    {
        return a.c < b.c;
    }
    
    struct BigInt {
        int siz, num[5005];
        BigInt() {
            siz = 0;
            memset(num, 0, sizeof num);
        }
        BigInt(int x)
        {
            siz = 0;
            while(x)
            {
                num[++siz] = x % 10;
                x /= 10;
            }
        }
        friend bool operator < (BigInt A, BigInt B)
        {
            if (A.siz < B.siz) return 1;
            if (A.siz > B.siz) return 0;
            for (reg int i = A.siz ; i >= 1 ; i --)
                if (A.num[i] < B.num[i]) return 1;
                else if (A.num[i] > B.num[i]) return 0;
            return 1;
        }
        friend BigInt operator * (BigInt A, int x)
        {
            BigInt ans;
            ans.siz = A.siz;
            for (reg int i = 1 ; i <= A.siz ; i ++) ans.num[i] = A.num[i] * x;
            int s;
            for (reg int i = 1 ; i <= A.siz or ans.num[i] ; i ++)
            {
                ans.num[i+1] += ans.num[i] / 10;
                ans.num[i] %= 10;
                s = i;
            }
            ans.siz = ans.num[s] ? s : s - 1;
            return ans;
        }
        friend BigInt operator / (BigInt A, int x)
        {
            BigInt ans;
            ans.siz = A.siz;
            int rest = 0;
            for (reg int i = A.siz ; i >= 1 ; i --)
            {
                rest = rest * 10 + A.num[i];
                ans.num[i] = rest / x;
                rest %= x;
            }
            while(ans.siz >= 2 and ans.num[ans.siz] == 0) ans.siz--;
            return ans;
        }
        friend ostream & operator << (ostream &os, BigInt A)
        {
            for (reg int i = A.siz ; i >= 1 ; i --)
                os << A.num[i];
            return os;
        }
    }ans, qzh;
    
    int main()
    {
        n = read();
        for (reg int i = 0 ; i <= n ; i ++) p[i].a = read(), p[i].b = read(), p[i].c = p[i].a * p[i].b;
        sort (p + 1, p + 1 + n, cmp);
        ans = BigInt(1);
        qzh = BigInt(1);
        for (reg int i = 1 ; i <= n ; i ++)
        {
            if (p[i-1].a == 0) break;
            qzh = qzh * p[i-1].a;
            BigInt tmp = qzh / p[i].b;
            if (ans < tmp) ans = tmp;
        }
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    Realtime crowdsourcing
    maven 常用插件汇总
    fctix
    sencha extjs4 command tools sdk
    首次吃了一颗带奶糖味的消炎药,不知道管用不
    spring mvc3 example
    ubuntu ati driver DO NOT INSTALL recommand driver
    yet another js editor on windows support extjs
    how to use springsource tools suite maven3 on command
    ocr service
  • 原文地址:https://www.cnblogs.com/BriMon/p/9520955.html
Copyright © 2011-2022 走看看