luoguP1080 国王游戏 题目

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define il inline
#define rg register
#define ll long long
#define N 10001
#define inf 1000000010
using namespace std;
int n,a,b;
struct T{
int le,ri;
}h[N];
ll now[N],ans[N],zs[N];
int len1,alen,flag;
il void re(rg int &x);
int cmp(const T &x,const T &y);
void solve(rg int k);
void add(rg int k);
int main()
{
re(n),re(a),re(b);
for(rg int i=;i<=n;++i)
re(h[i].le),re(h[i].ri);
sort(h+,h+n+,cmp);
while(a)
now[++len1]=(a%),a/=;
for(rg int i=;i<=n;++i)
solve(i),add(i);
for(rg int i=len1;i>=;--i){
if((!flag)&&(!ans[i]))continue;
cout<<ans[i];
flag=;
}
return ;
} il void re(rg int &x){
rg int res=,w=;char c=getchar();
while((c<''||c>'')&&c!='-')c=getchar();
if(c=='-')w=-,c=getchar();
while(c>=''&&c<='')res=(res<<)+(res<<)+c-'',c=getchar();
x=w*res;
}
int cmp(const T &x,const T &y){
return (x.le*x.ri)<(y.le*y.ri);
}
void solve(rg int k){
memset(zs,,sizeof(zs));
rg int c=h[k].ri,p=;
for(rg int i=len1;i>=;--i){
p=p*+now[i];
zs[i]=p/c,p%=c;
} for(rg int i=len1;i>=;--i){
if(ans[i]==zs[i])continue;
if(ans[i]>zs[i])break;
memcpy(ans,zs,sizeof(zs));
break;
}
}//除以自己右手上的值统计
void add(rg int k){
rg int c=h[k].le;
for(rg int i=;i<=len1;++i)
now[i]*=c;
for(rg int i=;i<=len1;++i){
if(now[i]>=){
rg int w=i;
while(now[w]>=){
now[w+]+=now[w]/,now[w]%=,w++;
if(w>len1)len1=w;
}
}
}
while(now[len1+]>=)
now[len1+]=(now[len1]/),now[len1]%=,len1++;
}

luoguP1080 国王游戏 题解(NOIP2012)(贪心+高精)的更多相关文章

  1. [贪心][高精]P1080 国王游戏(整合)

    题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成一排,国王站在队伍的最 ...

  2. GZOJ 1361. 国王游戏【NOIP2012提高组DAY1】

    国王游戏[NOIP2012提高组DAY1] Time Limit:1000MS Memory Limit:128000K Description 国王游戏(game.cpp/c/pas) [问题描述] ...

  3. 国王游戏 2012年NOIP全国联赛提高组(贪心+高精)

    P1080 国王游戏 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成 ...

  4. NOIP 2012 T2 国王游戏 (贪心+高精)

    思路: 呃呃网上那么多题解写得都不错-.. 就是高精 巨坑... 这里展出的是任氏高精(纯自己yy滴) //By SiriusRen #include <cstdio> #include ...

  5. noip 2012 国王游戏(贪心+高精)

    /* 我是不会说我考试的时候想到了正解却把金币取大看成金币求和的.... 觉得只按左右手乘积排序不太对 有反例 也可能我反例放到这个题里是错的吧 按自己的理解排的序 就是各种讨论... 假设 第i个人 ...

  6. 洛谷 P1080 国王游戏 题解

    原题 传送门 思路 分析 我们先假设队伍如下: People left hand right hand Before \(S_a\) A \(a_1\) \(b_1\) B \(a_2\) \(b_2 ...

  7. [bzoj2729][HNOI2012]排队 题解 (排列组合 高精)

    Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不 ...

  8. [NOIp2012] 国王游戏(排序 + 贪心 + 高精度)

    题意 给你两个长为 \(n+1\) 的数组 \(a,b\) ,你需要定义一个顺序 \(p\) (\(p_0\) 永远为 \(0\)) 能够最小化 \[ \max_{i=1}^{n} \frac{\pr ...

  9. luoguP1080 国王游戏 (贪心+高精度)

    题目链接:https://www.luogu.org/problemnew/show/P1080 参考:https://www.luogu.org/problemnew/solution/P1080 ...

随机推荐

  1. 67.Task Scheduler(任务规划)

    Level: Medium 题目描述: Given a char array representing tasks CPU need to do. It contains capital letter ...

  2. 20191114PHP验证码

    <?phpob_clean();$img=imagecreate(40,20);$back=imagecolorallocate($img,200,200,200); $blue=imageco ...

  3. Ajax —— 服务器端发送JSON数据

    重点需要解决的问题:服务器端如何构建JSON数据 思考:JavaBean转JSON数据,集合转JSON数据,普通java对象(String,Number)转JSON数据 一.Gson开源jar包   ...

  4. JS中 [] == ![]结果为true,而 {} == !{}却为false

     为什么? 先转换再比较      (==) 仅比较而不转换  (===) ==转换规则?   ==比较运算符会先转换操作数(强制转换),然后再进行比较 ①如果有一个操作数是布尔值,则在比较相等性之前 ...

  5. C# DataTable、实体相互转换

    public static T GetEntity<T>(DataTable table) where T : new() { T entity = new T(); foreach (D ...

  6. Linux系统中创建大文件,并作为文件系统使用

    在LInux系统的使用过程中,有时候会遇到诸如某个磁盘分区的大小不够用了,导致其下的文件系统不能正常写入数据.亦或者是系统swap分区太小,不够用或者不满足条件而导致的其他一系列问题.如果我们系统上挂 ...

  7. 二、SQL Server 分页

    一.SQL Server 分页 --top not in方式 select top 条数 * from tablename where Id not in (select top 条数*页数 Id f ...

  8. Vue组件-组件组合

    组件设计初衷就是要配合使用的,最常见的就是形成父子组件的关系:组件 A 在它的模板中使用了组件 B. <html> <head> <title>Vue组件 A 在它 ...

  9. ltp-ddt smp_cpu_affinity

    # @name SMP CPU Affinity# @desc Check that processes assigned to multiple CPUs complete without erro ...

  10. ltp-ddt realtime_cpuload_10p 涉及的cpuloadgen交叉编译及安装

    1.下载源码 https://github.com/ptitiano/cpuloadgen/archive/v0.94.tar.gz 解压 tar -zxvf cpuloadgen-0.94.tar. ...