洛谷 P1080 國王游戲

来源:https://www.cnblogs.com/poi-bolg-poi/archive/2019/10/04/11623430.html
-Advertisement-
Play Games

[TOC] 題目 "P1080 國王游戲" 思路 貪心+高精度。按$a \times b$從小到大排序就可以了、 $Code$ cpp include define MAXN 1001 define rr register using namespace std; const int Big_B = ...


目錄


題目

P1080 國王游戲

思路

貪心+高精度。按$a \times b$從小到大排序就可以了、

$Code$

#include<bits/stdc++.h>
#define MAXN 1001
#define rr register
using namespace std;
const int Big_B = 10; const int Big_L = 1;
inline int intcmp_ (int a, int b) { if (a > b) return 1; return a < b ? -1 : 0; }

struct Int  {
#define rg register
    inline int max (int a, int b) { return a > b ? a : b; }
    inline int min (int a, int b) { return a < b ? a : b; }
    std :: vector <int> c; Int () {} typedef long long LL; 
    Int (int x) { for (; x > 0; c.push_back (x % Big_B), x /= Big_B); }
    Int (LL x) { for (; x > 0; c.push_back (x % Big_B), x /= Big_B); }
    inline void CrZ () { for (; !c.empty () && c.back () == 0; c.pop_back ()); }
    inline Int &operator += (const Int &rhs){
        c.resize (max (c.size (), rhs.c.size ())); rg int i, t = 0, S;
        for (i = 0, S = rhs.c.size (); i < S; ++ i)
            c[i] += rhs.c[i] + t, t = c[i] >= Big_B, c[i] -= Big_B & (-t);
        for (i = rhs.c.size (), S = c.size (); t && i < S; ++ i)
            c[i] += t, t = c[i] >= Big_B, c[i] -= Big_B & (-t);
        if (t) c.push_back (t); return *this;
    }
    inline Int &operator -= (const Int &rhs){
        c.resize (max (c.size (), rhs.c.size ())); rg int i, t = 0, S;
        for (i = 0, S = rhs.c.size (); i < S; ++ i)
            c[i] -= rhs.c[i] + t, t = c[i] < 0, c[i] += Big_B & (-t);
        for (i = rhs.c.size (), S = c.size (); t && i < S; ++ i)
            c[i] -= t, t = c[i] < 0, c[i] += Big_B & (-t);
        CrZ (); return *this;
    }
    inline Int &operator *= (const Int &rhs){
        rg int na = c.size (), i, j, S, ai; 
        c.resize (na + rhs.c.size ()); LL t;
        for (i = na - 1; i >= 0; -- i){
            ai = c[i], t = 0, c[i] = 0;
            for (j = 0, S = rhs.c.size (); j < S; ++ j){
                t += c[i + j] + (LL) ai * rhs.c[j];
                c[i + j] = t % Big_B, t /= Big_B;
            }
            for (j = rhs.c.size (), S = c.size (); t != 0 && i + j < S; ++ j)
                t += c[i + j], c[i + j] = t % Big_B, t /= Big_B;
            assert (t == 0);
        }
        CrZ (); return *this;
    }
    inline Int &operator /= (const Int &rhs) { return *this = div (rhs); }
    inline Int &operator %= (const Int &rhs) { return div (rhs), *this; }
    inline Int &shlb (int l = 1){
        if (c.empty ()) return *this; c.resize (c.size () + l);rg int i;
        for (i = c.size () - 1; i >= l; -- i) c[i] = c[i - l];
        for (i = 0; i < l; ++ i) c[i] = 0;
        return *this;
    }
    inline Int &shrb (int l = 1){
        for (rg int i = 0; i < c.size () - l; ++ i) c[i] = c[i + l];
        c.resize (max (c.size () - l, 0)); return *this;
    }
    inline Int div (const Int &rhs){
        assert (!rhs.c.empty ()); Int q, r; rg int i; if (rhs > *this) return 0;
        q.c.resize (c.size () - rhs.c.size () + 1); rg int _l, _r, mid;
        for (i = c.size () - 1; i > c.size () - rhs.c.size (); -- i) r.shlb (), r += c[i];
        for (i = c.size () - rhs.c.size (); i >= 0; -- i){
            r.shlb (); r += c[i]; 
            if (r.Comp (rhs) < 0) q.c[i] = 0;
            else {
                _l = 0, _r = Big_B;
                for (; _l != _r; ){
                    mid = _l + _r >> 1;
                    if ((rhs * mid).Comp (r) <= 0) _l = mid + 1; else _r = mid;
                }
                q.c[i] = _l - 1, r -= rhs * q.c[i];
            }
        }
        q.CrZ (), *this = r; return q;
    }
    inline int Comp (const Int &rhs) const {
        if (c.size () != rhs.c.size ()) return intcmp_ (c.size (), rhs.c.size ());
        for (rg int i = c.size () - 1; i >= 0; -- i) 
            if (c[i] != rhs.c[i]) return intcmp_ (c[i], rhs.c[i]);
        return 0;
    }
    friend inline Int operator + (const Int &lhs, const Int &rhs)
    { Int res = lhs; return res += rhs; }
    inline friend Int operator - (const Int &lhs, const Int &rhs){ 
        if (lhs < rhs){
            putchar ('-'); 
            Int res = rhs; return res -= lhs;
        }
        else { Int res = lhs; return res -= rhs; }
    }
    friend inline Int operator * (const Int &lhs, const Int &rhs)
    { Int res = lhs; return res *= rhs; }
    friend inline Int operator / (const Int &lhs, const Int &rhs)
    { Int res = lhs; return res.div (rhs); }
    friend inline Int operator % (const Int &lhs, const Int &rhs)
    { Int res = lhs; return res.div (rhs), res; }
    friend inline std :: ostream &operator << (std :: ostream &out, const Int &rhs){ 
        if (rhs.c.size () == 0) out << "0";
        else {
            out << rhs.c.back ();
            for (rg int i = rhs.c.size () - 2; i >= 0; -- i)
                out << std :: setfill ('0') << std :: setw (Big_L) << rhs.c[i];
        }
        return out;
    } 
    friend inline std :: istream &operator >> (std :: istream &in, Int &rhs){
        static char s[100000];
        in >> s + 1; int Len = strlen (s + 1);
        int v = 0; LL r = 0, p = 1;
        for (rg int i = Len; i >= 1; -- i){
            ++ v; r = r + (s[i] - '0') * p, p *= 10;
            if (v == Big_L) rhs.c.push_back (r), r = 0, v = 0, p = 1;
        }
        if (v != 0) rhs.c.push_back (r); return in;
    }
    friend inline bool operator < (const Int &lhs, const Int &rhs)
    { return lhs.Comp (rhs) < 0; }
    friend inline bool operator <= (const Int &lhs, const Int &rhs)
    { return lhs.Comp (rhs) <= 0; }
    friend inline bool operator > (const Int &lhs, const Int &rhs)
    { return lhs.Comp (rhs) > 0; }
    friend inline bool operator >= (const Int &lhs, const Int &rhs)
    { return lhs.Comp (rhs) >= 0; }
    friend inline bool operator == (const Int &lhs, const Int &rhs)
    { return lhs.Comp (rhs) == 0; }
    friend inline bool operator != (const Int &lhs, const Int &rhs)
    { return lhs.Comp (rhs) != 0; }
#undef rg
};

struct qwq {
    Int a,b,cj;
}qaq[MAXN];

bool cmp(qwq x,qwq y) {
    return x.cj<y.cj;
}

int Main (){
    int n;
    cin>>n;
    cin>>qaq[0].a>>qaq[0].b;
    for(rr int i=1;i<=n;++i) {
        cin>>qaq[i].a;
        cin>>qaq[i].b;
        qaq[i].cj=qaq[i].a*qaq[i].b;
    }
    sort(qaq+1,qaq+n+1,cmp);
    Int maxx=0,flag=1;
    for(rr int i=1;i<=n;++i) {
        flag*=qaq[i-1].a;
        maxx=max(maxx,flag/qaq[i].b);
    }
    cout<<maxx;
    return 0;
}
int ZlycerQan = Main ();
int main (int argc, char *argv[]) {;}

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 裝飾模式: 1、定義:動態地給一個對象增加一些額外的職責,就增加對象功能來說,裝飾模式比生成子類實現更為靈活 2、模型結構: (1)抽象構件(Component):定義一個抽象介面以規範準備接收附加責任的對象 (2)具體構件(ConcreteComponent):實現抽象構件,通過裝飾角色為其添加一 ...
  • 職責鏈模式(Chain of Responsibility): 在現實生活中,常常會出現這樣的事例:一個請求需要多個對象處理,但每個對象的處理條件或許可權不同。如公司員工報銷差旅費,可審批的領導有部分負責人、副總經理、總經理等,但每個領導能審批的金額是不同的,不同的金額需要找相應的領導審批,也就是說要 ...
  • # -*- coding: utf-8 -*-"""Spyder Editor This is a temporary script file.tensor flow 之線性回歸模式2019-oct-5""" import tensorflow as tfimport numpy as npimpo ...
  • 本文主要講解Spring Boot 整合Jwt 認證的示例,詳細內容,詳見文末源碼。 ...
  • time模塊 作用:列印日期,做時間轉換。 import timeimport datetime #示例一:sleep()print("start to sleep.....")time.sleep(5) #讓程式停止5秒print("wake up...") #示例二:時間戳print(time. ...
  • 高強度訓練第二十天總結:Mybatis面試題 什麼是Mybatis? 1. Mybatis 是一個半 ORM(對象關係映射)框架,它內部封裝了 JDBC,開發時 只需要關註 SQL 語句本身,不需要花費精力去處理載入驅動、創建連接、創建 statement 等繁雜的過程。程式員直接編寫原生態 sql ...
  • CAP定理與BASE理論 CAP定理 2000 年 7 月,加州大學伯克利分校的 Eric Brewer 教授在 ACM PODC 會議上提出 CAP 猜想。2年後,麻省理工學院的 Seth Gilbert 和 Nancy Lynch 從理論上證明瞭 CAP。之後,CAP 理論正式成為分散式計算領域 ...
  • 概述 優點 第一 ,它解決了複雜問題。它把可能會變得龐大的單體應用程式分解成一套服務。雖然功能數量不變,但是應用程式已經被分解成可管理的塊或者服務。每個服務都有一個明確定義邊界的方式,如遠程過程調用(RPC)驅動或消息驅動 API。微服務架構模式強制一定程度的模塊化,實際上,使用單體代碼來實現是極其 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...