ATP

题意:足球锦标赛使用二分的策略,每次淘汰剩下人的一半,并且数据表明:排名相差k(include)之内的运动员,胜负难料,否则排名前的必定战胜排名后的;问给定n(n = 2x, x∈N, n <= 5000),k可能成为冠军的最差排名为多少?

误区:认为可以利用k递推,这样最后一名可是有机会成为冠军的。。但是里面有一个限制条件,那就是足球赛的淘汰规则;每次淘汰一半,导致所有的比赛次数为log(n);这就没有给排名后的队员足够的场数来利用排名前的队员打败所有比他等级高的对手,所以这就导致了等级低的选手可能不能在规定的比赛次数的前提下获得冠军;

思路:贪心+二分(等级就是排名)

贪心:每一个选手,如果每次都能打败他所能打败的最强的对手(这名对手必须没有出局),那么他最终获得冠军的可能就越大。同时这也给后面等级低成为冠军创造了机会;直接枚举标记即可;

二分:如果等级为i的选手有可能,那么前面的选手一定是可以的,所以只需要向后搜索即可;二分的基础

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<stdlib.h>
#include<time.h>
#include<stack>
#include<set>
using namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1|1
typedef __int64 ll;
template<typename T>
void read1(T &m)
{
T x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
template<typename T>
void out(T a)
{
if(a>) out(a/);
putchar(a%+'');
}
int stk[],vis[],kase,k;
bool judge(int id)
{
MS0(vis);
int top = ;
stk[top++] = id;
rep1(i,,kase){
int last = top;
rep0(j,,last){
for(int q = max(,stk[j] - k);q < id;q++)
if(vis[q] == ){
stk[top++] = q;
vis[q] = ;
break;
}
}
}
return top == id;
}
int main()
{
int n,ans;
kase = ;
read2(n,k);
while((n & (<<kase)) == ) kase++;
int l = ,r = n;//[l,r]中的值都是可选的
while(l <= r){
int mid = l + r >> ;
if(judge(mid)) ans = mid,l = mid + ;
else r = mid - ;//**
}
out(ans);
puts("");
return ;
}

poj 1818 ATP的更多相关文章

  1. POJ 3100 &amp; ZOJ 2818 &amp; HDU 2740 Root of the Problem(数学)

    题目链接: POJ:id=3100" style="font-size:18px">http://poj.org/problem? id=3100 ZOJ:http ...

  2. poj 1696 叉积理解

    Space Ant Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3967   Accepted: 2489 Descrip ...

  3. POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理

    Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798 ...

  4. POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理

    Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   ...

  5. POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治

    The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286 ...

  6. POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法

    Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Descr ...

  7. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  8. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  9. POJ 2255. Tree Recovery

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 De ...

随机推荐

  1. 文件和目录之chown、fchown和lchown函数

    下面几个chown函数可用于更改文件的用户ID和组ID. #include <unistd.h> int chown( const char *pathname, uid_t owner, ...

  2. Asp.Net 之 未能加载文件或程序集 system.web.extensions 解决方法

    最近做项目发现未能加载文件或程序集的错误,这是由于我的机器上没有安装Ajax的原因.问题解决后,整理如下:表现:1."System.Web.Extensions, Version=1.0.61025. ...

  3. [转]Best way to sort a DropDownList in MVC3 / Razor using helper method

    本文转自:http://stackoverflow.com/questions/7223185/best-way-to-sort-a-dropdownlist-in-mvc3-razor-using- ...

  4. 关于XML的DTD概述

    1 DTD概述 1.1 什么是DTD DTD(Document Type Definition),文档类型定义,用来约束XML文档.或者可以把DTD理解为创建XML文档的结构!例如可以用DTD要求XM ...

  5. javascript for in 循环时,会取到Array.prototype

    /** *删除数组指定下标或指定对象 */ if(!Array.prototype.remove){ Array.prototype.remove = function(obj){ for(var i ...

  6. Classloaders and Classes

    Classloaders and Classes (CLASSES) An example of the classloader (CLASSES) section that includes Cla ...

  7. iOS获取webview高度

    int webHeight = [[webView stringByEvaluatingJavaScriptFromString:@"document.documentElement.scr ...

  8. TCP/IP 教程

    TCP/IP 是因特网的通信协议. 通信协议是对计算机必须遵守的规则的描述,只有遵守这些规则,计算机之间才能进行通信. 浏览器和服务器都在使用 TCP/IP 因特网浏览器和因特网服务器均使用 TCP/ ...

  9. JS学习之表格的排序

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. nodejs-fs使用

    (1)读取文本文件时须添加上'encoding'才能输出可读的内容. 02.txt hello,world! nodejs_readfile.js var fs = require('fs'); fs ...