[Luogu] 国王游戏
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] 国王游戏的更多相关文章
- Luogu 1080 【NOIP2012】国王游戏 (贪心,高精度)
Luogu 1080 [NOIP2012]国王游戏 (贪心,高精度) Description 恰逢H国国庆,国王邀请n位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己 ...
- Luogu P1080国王游戏(贪心)
国王游戏 题目链接:国王游戏 ps:题目数据说明了要写高精度. 这个题的答案是\(a.l * a.r < b.l * b.r\)按照这个进行排序 题解中大部分只是如何证明排序是: \(a.l * ...
- [noip2012]国王游戏<贪心+高精度>
题目链接: https://vijos.org/p/1779 https://www.luogu.org/problem/show?pid=1080 http://codevs.cn/problem/ ...
- NOIP2012 国王游戏
2国王游戏 (game.cpp/c/pas) [问题描述] 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数 ...
- 【NOIP 2012 国王游戏】 贪心+高精度
题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右 手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排 成一排,国王站在队伍 ...
- Codevs 1198 国王游戏 2012年NOIP全国联赛提高组
1198 国王游戏 2012年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 恰逢 H 国国庆,国王邀 ...
- NOIP国王游戏
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #inc ...
- AC日记——国王游戏 洛谷 P1080
国王游戏 思路: 贪心+高精: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1005 struct Dat ...
- 国王游戏 2012年NOIP全国联赛提高组(贪心+高精)
P1080 国王游戏 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成 ...
随机推荐
- Neo4j
Neo4j是一个高性能的,NOSQL图形数据库,它将结构化数据存储在网络上而不是表中.它是一个嵌入式的.基于磁盘的.具备完全的事务特性的Java持久化引擎,但是它将结构化数据存储在网络(从数学角度叫做 ...
- VS2017生成一个简单的DLL文件 和 LIB文件——C语言
下面我们将用两种不同的姿势来用VS2017生成dll文件(动态库文件)和lib文件(静态库文件),这里以C语言为例,用最简单的例子,来让读者了解如何生成dll文件(动态库文件) 生成动态库文件 姿势一 ...
- 学习扩展kmp
参考博客:https://blog.csdn.net/s_999999/article/details/89104957
- 怎样启动Nginx并设置开机自动运行
1. 启动 sudo systemctl start nginx.service 2. 设置开机自动运行 sudo systemctl enable nginx.service
- 【死磕Java并发】—–深入分析ThreadLocal
ThreadLoacal是什么? ThreadLocal是啥?以前面试别人时就喜欢问这个,有些伙伴喜欢把它和线程同步机制混为一谈,事实上ThreadLocal与线程同步无关.ThreadLocal虽然 ...
- EF7 在ASP.NET5 RC1版本中数据结构合并的问题
由于EF版本和asp.net5版本不断更新导致命令出现冲突.最新命令如下: C:\ScrumBasic\ScrumBasic>dnx ef _/\__ ---==/ \\ ___ ___ |. ...
- 配置UOJ数据的正确姿势
最近瞎搞用开源UOJ搭了个OJ,在题目配置方面搞了挺久,一开始看vfleaking的文档还折腾了SVN,特意写下这篇文章为后来人少走弯路 Step 1 拥有管理权限并设置好题面,支持\(LaTex\) ...
- Java实现发邮件功能---网易邮箱
目录 Java实现发邮件功能 前言 开发环境 代码 效果 结束语 Java实现发邮件功能 前言 电子邮件的应用场景非常广泛,例如新用户加入,即时发送优惠清单.通过邮件找回密码.监听后台程序,出现异常自 ...
- QT调用CHM方法
QDesktopServices desktopServices;QString strUrl=QCoreApplication::applicationDirPath () ;strUrl=QStr ...
- 关于Highcharts数据量超过1000时无法显示问题
今天在vue的项目中引入Highcharts,想做一个大数据量的实时刷新曲线图,发现当数据量超过1000就无法显示. 经过排查发现 Highcharts为了保证更好的性能设置了一个性能阈值检查,当数据 ...