[题目链接]

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. HaHa's Morning(状压DP)

    描述 HaHa is so happy today, he is going to participate the 7th Hunan University Programming Contest. ...

  2. HDU-2159 FATE,01背包变形

    FATE 这道题和完全背包十分类似,只不过加上了忍耐度这个条件限制,所以很正常的想到用三维数组来模拟.但背包问题优化只有一层循环,这里当然也可以把种类这一层省略.d[i][j]表示杀i只怪耗费忍耐度为 ...

  3. [Istio]Kubernetes集群部署Istio 1.0

    大部分内容都是可以根据https://istio.io/docs/setup/kubernetes/quick-start/来处理的,这里主要谈部署时一些细节的问题 首先,当我们按照 istio 官方 ...

  4. 【Kubernetes】kube-dns 持续重启

    kuberbetes部署和启动正常,但是kube-dns持续重启 使用命令 kubectl get pods --all-namespaces 得到结果 从图中可以看出kube-dns-c7d8589 ...

  5. SPOJ VJudge QTREE - Query on a tree

    Query on a tree Time Limit: 851MS   Memory Limit: 1572864KB   64bit IO Format: %lld & %llu Submi ...

  6. Speculative store buffer

    A speculative store buffer is speculatively updated in response to speculative store memory operatio ...

  7. Sudoku---hdu2676(数独DFS)

    http://poj.org/problem?id=2676 递归深搜 #include<stdio.h> #include<string.h> #include<alg ...

  8. Java子类重写父类方法注意问题收集(转)

    子类不能重写父类的静态方法,私有方法.即使你看到子类中存在貌似是重写的父类的静态方法或者私有方法,编译是没有问题的,但那其实是你重新又定义的方法,不是重写.具体有关重写父类方法的规则如下: 重写规则之 ...

  9. 【神乎其神】这些EXCEL技巧,太神奇了,赶紧收藏!

    转:http://learning.sohu.com/20160215/n437421658.shtml

  10. Data obtained from ping: is it round trip or one way?

    I have 2 servers, each in two separate locations. I need to host an application on one, and the data ...