[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=5139

[算法]

二分答案

时间复杂度 : O(NlogN^2)

[代码]

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + ; int n;
int a[MAXN] , b[MAXN]; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline bool check(int x)
{
for (int i = ; i < x; i++) b[i] = a[i];
sort(b + ,b + x);
int limit = n - x;
for (int i = ; i < x; i++)
{
if (b[i] > limit) return false;
++limit;
}
return true;
} int main()
{ read(n);
for (int i = ; i <= n; i++) read(a[i]);
int l = , r = n , ans = ;
while (l <= r)
{
int mid = (l + r) >> ;
if (check(mid))
{
l = mid + ;
ans = mid;
} else r = mid - ;
}
printf("%d\n",n - ans); return ; }

[USACO 2017DEC] Greedy Gift Takers的更多相关文章

  1. NC24083 [USACO 2017 Dec P]Greedy Gift Takers

    NC24083 [USACO 2017 Dec P]Greedy Gift Takers 题目 题目描述 Farmer John's nemesis, Farmer Nhoj, has N cows ...

  2. [BZOJ5139][Usaco2017 Dec]Greedy Gift Takers 权值线段树

    Description Farmer John's nemesis, Farmer Nhoj, has NN cows (1≤N≤10^5), conveniently numbered 1…N. T ...

  3. [USACO17DEC]Greedy Gift Takers

    题目描述 Farmer John's nemesis, Farmer Nhoj, has NN cows (1 \leq N \leq 10^51≤N≤105 ), conveniently numb ...

  4. P4090 [USACO17DEC]Greedy Gift Takers

    题目链接 题意分析 首先 如果当前序列中一头奶牛拿不到礼物的话 那么他后面的奶牛也拿不到礼物 所以我们可以二分 由于可以操作无限次 所以我们对于当前\([1,mid)\)的奶牛按照\(c\)值排序之后 ...

  5. USACO Training Section 1.1 贪婪的送礼者Greedy Gift Givers

    P1201 [USACO1.1]贪婪的送礼者Greedy Gift Givers 题目描述 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少.在这一个问题中,每个人都准备了一 ...

  6. Java实现【USACO】1.1.2 贪婪的礼物送礼者 Greedy Gift Givers

    [USACO]1.1.2 贪婪的礼物送礼者 Greedy Gift Givers 题目描述 对于一群要互送礼物的朋友,你要确定每个人送出的礼物比收到的多多少(and vice versa for th ...

  7. USACO . Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided to exchange gifts ...

  8. USACO Section 1.1-2 Greedy Gift Givers

    Greedy Gift Givers 贪婪的送礼者 对于一群(NP个)要互送礼物的朋友,GY要确定每个人送出的钱比收到的多多少. 在这一个问题中,每个人都准备了一些钱来送礼物,而这些钱将会被平均分给那 ...

  9. usaco training <1.2 Greedy Gift Givers>

    题面 Task 'gift1': Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends has decided t ...

随机推荐

  1. Bone Collector II(01背包kth)

    The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup&quo ...

  2. Ubuntu安装sublime Text 3并配置可以输入中文

    使用Ubuntu系统后,想找一个顺手的编辑器,sublime作为我的首选编辑器,在安装和配置可输入中文时遇到各种个样的问题,总结一些: 1:问题: 我的系统是Ubuntu 18.04 LTS,尝试多次 ...

  3. 【BZOJ2038】小Z的袜子(莫队)

    题意: 给定n个数a1, a2…… an与m个询问(L,R).对于每个询问,从aL, aL+1…… aR这R-L+1个数中随机取出两个数,求这两个数相同的概率. 数据范围:1<=n,m,ai&l ...

  4. HDU 6397 组合数学+容斥 母函数

    Character Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth ...

  5. ubuntu-12.04下安装postgresql

    2013-10-01 20:42:57|    moniter参考资料:Ubuntu 12.04下PostgreSQL-9.1安装与配置详解(在线安装)一.安装postgresqlbamboo@bam ...

  6. 2887 Big String

    splay瞎搞一下,正解是分块数组或分块链表,但是学不会啊! #include<cstdio> #include<cstdlib> #include<iostream&g ...

  7. Drainage Ditches--hdu1532(网络流 模板)

    http://acm.hdu.edu.cn/showproblem.php?pid=1532 Drainage Ditches Time Limit: 2000/1000 MS (Java/Other ...

  8. Topcoder SRM 657DIV2

    前言: 像我这样一直在DIV2的弱菜..不知道说什么了. A:一定判断有8个‘R’,每行 每列只有一个 B题:大概是  int E,int EM,int M,int MH,int H 然后EM可以给值 ...

  9. Java多线程分析案例

    1. 多线程的创建方式 (1).继承 Thread类:但Thread本质上也是实现了Runnable 接口的一个实例,它代表一个线程的实例,并且,启动线程的唯一方法就是通过 Thread 类的 sta ...

  10. Node.js+Web TWAIN,实现Web文档扫描和图像上传

      目录(?)[+] 通过Dynamic Web TWAIN SDK和Node.js的组合,只需要几行代码就可以实现在浏览器中控制扫描仪,获取图像后上传到远程服务器. 原文:Document Imag ...