两个难点。

  • 怎么想到的贪心?

首先确定算法:

显然不是数据结构题。转成图论也不太可能。

考虑DP:f[i][j]表示前i个人取j状态的最小最大值......2^1000,直接放弃。

因为出现了“最大值最小”,考虑二分答案:如果我们有一个ans是最大值,我们怎么判断是否可行?

要确保每一个数都不会超过ans,这很困难。

思路戛然而止。

然后思考:本题要求排序。zbtrs:排序不就是贪心吗?

然后想到邻位互换法,得出贪心策略。

显然很难想出贪心来......

  • 高精度

这个没什么好说的,写个高精度乘单精度,除单精度,比较大小,输出,就行了。


跑的十分之快,136ms十个点
 #include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
using namespace std;
const int N = ;
struct LL {
string num;
void out() {
for(int i = ; i < num.size(); i++) {
putchar(num[i]);
}
return;
}
LL operator * (const int& x) const {
int len = num.size();
int a[len + ];
memset(a, , sizeof(a));
for(int i = ; i < len; i++) {
a[i] = num[len - i - ] - '';
a[i] *= x;
}
for(int i = ; i < len; i++) {
if(a[i] > ) {
a[i + ] += a[i] / ;
a[i] %= ;
if(i + == len) {
len++;
}
}
}
string f = "";
for(int i = len - ; i >= ; i--) {
f += (a[i] + '');
}
LL t;
t.num = f;
return t;
}
LL operator / (const int x) const {
int len = num.size();
int a[len];
for(int i = ; i < len; i++) {
a[i] = num[len - i - ] - '';
}
for(int i = len - ; i > ; i--) {
a[i - ] += * (a[i] % x);
a[i] /= x;
}
a[] /= x;
while(len >= && a[len - ] == ) {
len--;
}
string f = "";
for(int i = len - ; i >= ; i--) {
f += (a[i] + '');
}
LL t;
t.num = f;
return t;
}
bool operator < (const LL& x) const {
if(num.size() != x.num.size()) {
return num.size() < x.num.size();
}
for(int i = ; i < num.size(); i++) {
if(num[i] != x.num[i]) {
return num[i] < x.num[i];
}
}
return ;
}
};
struct Man {
int a, b, c;
bool operator < (const Man &f) const{
return this->c < f.c;
}
}man[N];
int main() {
int n;
scanf("%d", &n);
for(int i = ; i <= n; i++) {
scanf("%d%d", &man[i].a, &man[i].b);
man[i].c = man[i].a * man[i].b;
} sort(man + , man + n + );
/*
for(int i = 1; i <= n; i++) {
printf("%d %d %d\n", man[i].a, man[i].b, man[i].c);
}
printf("\n");
*/
LL ans, now;
now.num = "";
ans.num = "";
for(int i = ; i < n; i++) {
now = now * man[i].a;
LL t = now / man[i + ].b;
if(ans < t) {
ans = t;
}
}
ans.out();
return ;
}
/**
3
1 7
6 1
2 3
2 3
ans:4
*/

AC代码

洛谷P1080 国王游戏的更多相关文章

  1. 【流水调度问题】【邻项交换对比】【Johnson法则】洛谷P1080国王游戏/P1248加工生产调度/P2123皇后游戏/P1541爬山

    前提说明,因为我比较菜,关于理论性的证明大部分是搬来其他大佬的,相应地方有注明. 我自己写的部分换颜色来便于区分. 邻项交换对比是求一定条件下的最优排序的思想(个人理解).这部分最近做了一些题,就一起 ...

  2. 【题解】洛谷 P1080 国王游戏

    目录 题目 思路 \(Code\) 题目 P1080 国王游戏 思路 贪心+高精度.按\(a \times b\)从小到大排序就可以了. \(Code\) #include<bits/stdc+ ...

  3. 洛谷P1080 国王游戏 python解法 - 高精 贪心 排序

    洛谷的题目实在是裹脚布 还编的像童话 这题要 "使得获得奖赏最多的大臣,所获奖赏尽可能的少." 看了半天都觉得不像人话 总算理解后 简单说题目的意思就是 根据既定的运算规则 如何排 ...

  4. [NOIP2012] 提高组 洛谷P1080 国王游戏

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

  5. 洛谷 P1080 国王游戏

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

  6. 洛谷—— P1080 国王游戏

    https://www.luogu.org/problem/show?pid=1080 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整 ...

  7. 洛谷P1080 国王游戏【大数】【贪心】

    题目:https://www.luogu.org/problemnew/show/P1080 题意: 一个国王和n个大臣,每个人左右手上都有一个数值. 现在将国王排在队首,将大臣进行排序.每个大臣的值 ...

  8. 洛谷 P1080 国王游戏 题解

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

  9. 【题解】洛谷P1080 [NOIP2012TG] 国王游戏(贪心+高精度)

    次元传送门::洛谷P1080 思路 我们模拟一下只有两个大臣的时候发现 当a1​∗b1​<a2​∗b2​是ans1<ans2 所以我们对所有大臣关于左右手之积进行排序 得到最多钱的大臣就是 ...

随机推荐

  1. AssemblyScript的测试

    详细文档介绍 export function f(x: i32): i32 { if (x === 1 || x === 2) { return 1; } return f(x - 1) + f(x ...

  2. python爬虫之scrapy的pipeline的使用

    scrapy的pipeline是一个非常重要的模块,主要作用是将return的items写入到数据库.文件等持久化模块,下面我们就简单的了解一下pipelines的用法. 案例一: items池 cl ...

  3. Java变量类型识别的3种方式

    内容导览 反射方式,成员变量的类型判断 isInstance用法 利用泛型识别类型 测试类: package com.cxyapi.oo; import java.util.Date; import ...

  4. mysql参数优化记录

    服务器参数16G内存,4核CPUvim /etc/my.cnf 原: back_log=170 max_connections=600 max_user_connections=0 thread_co ...

  5. 如何在Mac系统安装MySQL

    方法一: (1)使用brew install mysql (2)使用mysql -uroot连接时报错: Authentication plugin 'caching_sha2_password' c ...

  6. jdbc一点小笔记

    JDBC的常用接口的步骤, 1使用Driver或者Class.forName()进行注册驱动: 2使用DriverManager进行获取数据库的链接.使用Connection获取语句对象.使用语句对象 ...

  7. 二、kubernetes环境搭建

    主要内容 1.环境准备(2主机) 2.安装流程 3.问题分析 4.总结 环境配置(2主机) 系统:CentOS 7.3 x64 网络:局域网(VPC) 主机: master:172.16.0.17 m ...

  8. Serialize a Long as a String

    今天在写接口的时候,用postman测试,返回数据与数据库一一对应,但是给前端返回的结果,除了主键id以外,其他都一样,如下 postman: { "unitPrice": nul ...

  9. Memcached 分布式集群

    首先解释一下我的标题,用到了 分布式 和 集群两个单词,为什么是集群?解决[相同业务]问题的服务器多个以上就称为集群.这里memcached就是做相同任务的(提供缓存服务)为什么是分布式?虽然针对的是 ...

  10. 【NLP】大白话讲解word2vec到底在做些什么

    转载自:http://blog.csdn.net/mylove0414/article/details/61616617 词向量 word2vec也叫word embeddings,中文名“词向量”, ...