简单的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的更多相关文章

  1. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  2. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  4. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  5. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  6. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  7. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  8. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

  9. HDU 3791二叉搜索树解题(解题报告)

    1.题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=3791 2.参考解题 http://blog.csdn.net/u013447865/articl ...

随机推荐

  1. WDatePicker 屏蔽onchange事件的解决办法

    受下面文章的启发,使用DatePicker自带的年月日相关的change事件,可以“勉强”实现input控件的onchange(),直接上代码: 1.第一种方式:利用DatePicker提供的年.月. ...

  2. response小结(五)—通过response实现请求重定向

    请求重定向指的是一个web资源收到客户端请求后,通知客户端去访问另外一个web资源,这称之为请求重定向.302状态码和location头即可实现重定向. 请求重定向最常见的应用场景就是用户登录. 下面 ...

  3. Java之趣味编程结婚问题

    问题如下:判断结婚的组合对数数.定义: 好三位新郎为 A,B,C ;三位新娘为X,Y,Z 有人想要知道他们谁和谁结婚 ,于是问了其中的三位. 回答是这样的:A说他将和X结婚 :X说她的未婚夫是C ;C ...

  4. C# 中控件 WebBrowser 对 frameset/ iframe 操作和内容获取

    1.获取frame的document HtmlDocument htmlDoc = webBrowser1.Document;  htmlDoc = webBrowser1.Document.Wind ...

  5. (转) DockPanel 右键增加关闭,除此之外全部关闭的功能

    在项目中新建一个class文件,代码如下: using System; using System.Collections.Generic; using System.ComponentModel; u ...

  6. 【转载】干货再次来袭!Linux小白最佳实践:《超容易的Linux系统管理入门书》(连载八)用命令实现批量添加用户

    Windows添加用户需要至少5个界面,而Linux一条命令就搞定了,这是不是高效人士办公第一法则呢.本文不给你一堆参数和选项,不让你见识教条主义,只给你最实用的代码. 想每天能听到小妞的语音播报,想 ...

  7. PerformSelector may cause a leak because its selector is unknown 解决方法

    我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3801030.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...

  8. map容器按value值排序

    1 vector<pair<key,value> >类型的容器中存放所有元素,sort(pair默认按照value比较大小?) 2 map<value,key>

  9. java学习笔记_GUI(2)

    import javax.swing.*; import java.awt.event.*; class Gui implements ActionListener{ JButton button = ...

  10. 按照自己的理解实现比特交换协议(alternating-bit protocol)

    一开始的思路是想写两个程序的,发送端和接收端.但是后来想了下,因为是模拟的,所以不用这么麻烦,直接自己定制场景(比如说丢包阿,包出错阿,超时之类的). 基本上是根据上图所写的,一个函数发包,一个函数接 ...