https://www.luogu.org/problemnew/show/P1080

按照 a * b 排序

高精度

#include <bits/stdc++.h>

using namespace std;
const int N = ; #define LL long long int n, ak, bk;
struct Node {
int A, B, AB;
bool operator <(const Node a) const{return AB < a.AB;}
} G[N]; #define gc getchar() LL sum, Answer = ; inline int read() {
int x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c < '') x = x * + c - '', c = gc;
return x;
} int main() {
n = read(); ak = read(); bk = read();
for(int i = ; i <= n; i ++) G[i].A = read(), G[i].B = read(), G[i].AB = G[i].A * G[i].B;
sort(G + , G + n + );
sum = ak;
for(int i = ; i <= n; i ++) {
LL imp = sum / G[i].B;
if(!imp) imp = ;
Answer = max(Answer, imp);
sum *= G[i].A;
}
if(Answer == ) Answer = ;
cout << Answer;
return ;
}
/*
3
1 1
2 3
7 4
4 6
*/
#include <bits/stdc++.h>

using namespace std;

int now[],sum[],ans[],add[];

struct Node {
int a;
int b;
long long a_b;
} node[]; int read() {
int ans = , flag = ;
char ch = getchar();
while( (ch > '' || ch < '') && ch != '-' ) ch = getchar();
if(ch == '-') flag = -, ch = getchar();
while(ch >= '' && ch <= '') ans = ans * + ch - '', ch = getchar();
return ans * flag;
}
void times(int x) {
memset(add, , sizeof(add));
for(int i = ; i <= ans[]; i ++) {
ans[i] = ans[i] * x;
add[i+] += ans[i] / ;
ans[i] %= ;
}
for(int i = ; i <= ans[] + ; i ++) {
ans[i] += add[i];
if(ans[i]>=) {
ans[i+]+=ans[i]/;
ans[i]%=;
}
if(ans[i]!=) {
ans[]=max(ans[],i);
}
}
return ;
}
int divition(int x) {
memset(add,,sizeof(add));
int q=;
for(int i=ans[]; i>=; i--) {
q*=;
q+=ans[i];
add[i]=q/x;
if(add[]== && add[i]!=) {
add[]=i;
}
q%=x;
}
return ;
}
bool compare() {
if(sum[]==add[]) {
for(int i=add[]; i>=; i--) {
if(add[i]>sum[i]) return ;
if(add[i]<sum[i]) return ;
}
}
if(add[]>sum[]) return ;
if(add[]<sum[]) return ;
}
void cp () {
memset(sum,,sizeof(sum));
for(int i=add[]; i>=; i--) {
sum[i]=add[i];
}
return ;
}
bool cmp(Node a,Node b) {
return a.a_b<b.a_b;
}
int main() {
int n=read();
for(int i=; i<=n; i++) {
node[i].a=read(),node[i].b=read();
node[i].a_b=node[i].a*node[i].b;
}
sort(node+,node+n+,cmp);
ans[]=,ans[]=;
for(int i=; i<=n; i++) {
times(node[i-].a);
divition(node[i].b);
if(compare()) {
cp();
}
}
for(int i=sum[]; i>=; i--)
printf("%d",sum[i]);
return ;
}

[Luogu] 国王游戏的更多相关文章

  1. Luogu 1080 【NOIP2012】国王游戏 (贪心,高精度)

    Luogu 1080 [NOIP2012]国王游戏 (贪心,高精度) Description 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己 ...

  2. Luogu P1080国王游戏(贪心)

    国王游戏 题目链接:国王游戏 ps:题目数据说明了要写高精度. 这个题的答案是\(a.l * a.r < b.l * b.r\)按照这个进行排序 题解中大部分只是如何证明排序是: \(a.l * ...

  3. [noip2012]国王游戏<贪心+高精度>

    题目链接: https://vijos.org/p/1779 https://www.luogu.org/problem/show?pid=1080 http://codevs.cn/problem/ ...

  4. NOIP2012 国王游戏

    2国王游戏 (game.cpp/c/pas) [问题描述] 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数 ...

  5. 【NOIP 2012 国王游戏】 贪心+高精度

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

  6. Codevs 1198 国王游戏 2012年NOIP全国联赛提高组

    1198 国王游戏 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 恰逢 H 国国庆,国王邀 ...

  7. NOIP国王游戏

    #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...

  8. AC日记——国王游戏 洛谷 P1080

    国王游戏 思路: 贪心+高精: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 struct Dat ...

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

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

随机推荐

  1. 题目15 链表中倒数第K个节点

    ///////////////////////////////////////////////////////////////////////////////////// // 5. 题目15 链表中 ...

  2. python — 协程

    1. 协程 1.1 协程基础 1.协程 :能够在一个线程下的多个任务之间来回切换,那么每一个任务都是一个协程. 2.协程的优点: 1.一个线程中的阻塞都被其他的各种任务沾满了 2.让操作系统觉得这个线 ...

  3. Linux上定时shell脚本

    原文链接:http://www.92coder.com/9-Linux%E5%AE%9A%E6%97%B6shell%E8%84%9A%E6%9C%AC/#more 本文主要介绍在Linux系统上部署 ...

  4. Oracle导入数据后中文乱码的解决方法

    解决方法: 方法一. 1.在运行命令行输入regedit,打开注册表编辑器 2.找到HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraDb11g_home1 3.看N ...

  5. 深入理解Java自动装箱拆箱机制

    1.自动装箱与拆箱的定义 装箱就是自动将基本数据类型转换为包装器类型(int-->Integer): 拆箱就是自动将包装器类型转换为基本数据类型(Integer-->int). Java中 ...

  6. react portals 插槽 实现简易弹窗

    Portal 提供了一种将子节点渲染到存在于父节点以外的DOM节点的优秀方案: 尽管 portal 可以被放置在 DOM 树中的任何地方,但在任何其他方面,其行为和普通的 React 子节点行为一致. ...

  7. canvas学习之初级运用

    <html> <head> <meta charset=utf-8> <title>绘制简单图形</title> <style typ ...

  8. IDEA GIT 忽略文件

    1.装插件 .igore 2.新建忽略文件格式 3.编辑忽略后缀文件 可以是文件夹 也可以是 具体文件类型

  9. 一个比ES处理数据更快的工具--Hubble.Net

    http://www.cnblogs.com/eaglet/tag/Hubble.Net/

  10. Appium|Locator Strategy ... is not supported for this session

    appim server log InvalidSelectorError: Locator Strategy 'xpath,//android.widget.TextView[@resource-i ...