传送门 题意: 农场主 FJ 有 n 头奶牛,现在给你 m 对关系(x,y)表示奶牛x的产奶速率高于奶牛y: FJ 想按照奶牛的产奶速率由高到低排列这些奶牛,但是这 m 对关系可能不能精确确定这 n 头奶牛的关系: 问最少需要额外增加多少对关系使得可以确定这 n 头奶牛的顺序: 题解: 之所以做这道题,是因为在补CF的题时用到了bitset<>: 搜这个容器的用法是看到了一篇标题为POJ-3275:奶牛排序Ranking the Cows(Floyd.bitset)的文章: 正好拿着道题练练b…
贪心...先枚举k, 然后从左往右扫一遍, 发现位置p的牛的状态不符合就将 [p, p + k ) 的牛都转身, 假如p + k - 1 已经超过了最右边牛的位置那这个k就不符合要求. 符合要求的就可以用来更新answer.这个贪心的正确性是很显然的.前p - 1头牛都已朝前, 再改动它们也做不到更优; 而要让第p头牛转身, 那就只能让[p, p + k )的牛转身. 考虑如何判断位置p的牛的状态, 我们发现p的状态与它本身和[ p - k - 1, p )这个区间内的牛的转身次数有关, 因为转…
1702: [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 510 Solved: 196[Submit][Status][Discuss] Description Farmer John's N cows (1 <= N <= 100,000) share many similarities. In fact, FJ has been able to narrow…
Ranking the cows Description Each of Farmer John's N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ would like to order his cows according to these rates from the fastest milk producer to the slowest. FJ has already compared…
直接二分答案然后判断. ----------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define rep( i , n ) for( int i = 0 ; i < n ; ++i ) #define c…
[BZOJ1720][Usaco2006 Jan]Corral the Cows 奶牛围栏 Description Farmer John wishes to build a corral for his cows. Being finicky beasts, they demand that the corral be square and that the corral contain at least C (1 <= C <= 500) clover fields for afterno…
Ranking the Cows Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3301 Accepted: 1511 Description Each of Farmer John's N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ would like to order his cows according to…
Face The Right Way 自动转身机 bzoj-1704 Usaco-2007 Mar 题目大意:不想描述题意系列++... ...题目链接 注释:略. 想法:我们直接枚举k,然后从左往右扫. 碰见的第一个亮的就把它后面的都变了 即可. 最后,附上丑陋的代码... .. #include <cstdio> #include <cstring> int v[5001],r[5001]; char str[5]; int main() { int n,k,minm=0x7f…
POJ3275 Ranking the Cows #include <iostream> #include <cstdio> #include <bitset> using namespace std; ; int n, m; bitset<maxn> maps[maxn]; void floyd() { ; k <= n; k++) { ; i <= n; i++) { if (maps[i][k]) maps[i] |= maps[k]; }…