hdu 3778
简单的dfs 但繁琐的可以了 0.0
#include<cstdio>
#include<cstring>
#include<algorithm>
using std::sort;
int n,m,cnt=0;
struct team
{
char s[50];
int low,up,d,f;
};
team a[30];
struct match
{
int x,y,re;
bool operator < (const match &p) const
{
return re < p.re;
}
};
match b[2000];
int find(char *s)
{
for(int i = 0; i < n; i++)
if(strcmp(a[i].s, s) == 0)
return i;
return -1;
} void cc(int w)
{
for(int i = 0; i < n; i++)
a[i].f = a[i].d;
for(int i = 0; i < w; i++)
if(b[i].re == 1)
{
a[b[i].x].f += 1;
a[b[i].y].f += 1;
}
else if(b[i].re == 2)
a[b[i].x].f += 3;
else
a[b[i].y].f += 3;
for(int i = 0; i < n; i++)
{
int rank=1;
for(int j = 0; j < n; j++)
{
if(j != i && a[j].f > a[i].f)
rank++;
}
if(rank > a[i].low)
a[i].low = rank;
if(rank < a[i].up)
a[i].up = rank;
}
}
void dfs(int cur,int w)
{
if(cur == w)
cc(w);
else
{
for(int i = 1; i <= 3; i++)
{
b[cur].re = i;
dfs(cur+1, w);
}
b[cur].re = 0;
}
}
void show(int a)
{
if(a == 1)
printf("1st ");
else if(a == 2)
printf("2nd ");
else if(a == 3)
printf("3rd ");
else
printf("%dth ", a);
} void show(team a)
{
printf("Team %s can finish as high as ",a.s);
show(a.up);
printf("place and as low as ");
show(a.low);
printf("place.\n");
}
int main()
{
while(scanf("%d%d",&n,&m) && m+n)
{
if(cnt++)
printf("\n");
int p,q;
char u[100],v[100];
for(int i = 0; i < n; i++)
{
scanf("%s",a[i].s);
a[i].d = a[i].low = 0, a[i].up = 50;
}
for(int i = 0; i < m; i++)
{
scanf("%s vs %s%d%d",u,v,&p,&q);
v[strlen(v)-1] = '\0';
b[i].x = find(u);
b[i].y = find(v);
int &re = b[i].re;
if(p==-1 && q==-1)
re = 0;
else if(p == q)
re = 1;
else if(p > q)
re = 2;
else
re = 3;
}
sort(b, b+m);
int j = 0;
for(j = 0; j < m; j++)
if(b[j].re != 0)
break;
for(int i = j; i < m; i++)
if(b[i].re == 1)
{
a[b[i].x].d += 1;
a[b[i].y].d += 1;
}
else if(b[i].re == 2)
a[b[i].x].d += 3;
else
a[b[i].y].d += 3;
dfs(0, j);
for(int i = 0; i < n; i++)
show(a[i]);
}
return 0;
}
hdu 3778的更多相关文章
- HDU 5643 King's Game 打表
King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
- HDU 1796How many integers can you find(容斥原理)
How many integers can you find Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d ...
- hdu 4481 Time travel(高斯求期望)(转)
(转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDU 3791二叉搜索树解题(解题报告)
1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...
随机推荐
- 【转载】Android设计中的.9.png
转载自:腾讯ISUX (http://isux.tencent.com/android-ui-9-png.html) 在Android的设计过程中,为了适配不同的手机分辨率,图片大多需要拉伸或者压 ...
- asp.net sql无限极分类实例程序
数据库结构 代码如下 复制代码 create table category( id int, clsno ...
- ubuntu下使用vi是方向键变乱码 退格键不能使用的解决方法
ubuntu下使用vi是方向键变乱码 退格键不能使用的解决方法 转载:http://blog.csdn.net/yao_qinwei/article/details/8761777 在插入模式下,按删 ...
- Google Breakpad part 1 : Getting Started With Windows Client
准备 1.Python 2.Visual Studio 3.svn checkout http://google-breakpad.googlecode.com/svn/trunk/ source c ...
- MySQL的相关设置
1.启动MySQL服务:# service mysqld start 2.为MySQL设置root用户密码:# mysql -u root mysql>set password for roo ...
- Qt模拟C#的File类对文件进行操作
其实只是QT菜鸟为了练习而搞出来的 文件头: #include <QFile> #include <QString> #include <iostream> #in ...
- 增加p()函数,方便开发中对变量打印调试
在开发的过程中,我们经常要输出一下变量看看得到的结果是什么,我们就要根据变量的类型选择使用echo,print_r或者var_dump,brophp框架中的p()函数会自动根据变量类型选择用什么方法为 ...
- 64位Python安装PIL
写个小程序需要安装PIL,但是官网只有32位,无法找到64位安装路径.根据网上教程自行编译,但是由于VS版本问题总是提示“Python error: Unable to find vcvarsall. ...
- 《WPF程序设计指南》读书笔记——第1章 应用程序与窗口
1.空白WPF项目的创建: 1)新建项目:在VS2010中,文件-新建-项目-visual c#-windows-空项目: 2)添加引用:PresentationFramework,Presentat ...
- TextBox控件
1.通过设置Multiline属性(bool)来控制文本框是否为多行显示 txt_Change.Location = , );//设置文本框位置 txt_Change.Multiline = true ...