Wrong Answer

思路:

1.先枚举4的全排列,即球赛的所有可能结果,一共4!=24种情况

2.对于每种情况,DFS 未确定的比赛 的结果,判断这种情况是否可达。

剪枝:

1.对于每种全排列,只需要找到一种满足这个全排列的情况即可,如果有一种情况满足,则不必再枚举其他可能。

2.因为在每种情况下,球队之间的排名已经确定了,所以在DFS的过程中,凡是不满足此排名的情况统统可以剪掉。

这样就可以少很多情况,即使在n=0的情况下也跑出了不错的效率,但是它Wrong Answer on test 17了。。。

求指点T^T

 #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm> using namespace std; const int MAXN = ;
const int permuta[] = { , , , , , ,
, , , , , ,
, , , , , ,
, , , , ,
}; struct Team
{
int id;
int qiu;
int point;
}; bool vis[];
int game[][], gori[][]; // 0=i输j 1=i平j 3=i赢j
Team tm[], ori[];
int N, cnt; void show()
{
for ( int i = ; i <= ; ++i )
printf( "id=%d point=%d qiu=%d\n", i, tm[i].point, tm[i].qiu );
puts("");
return;
} void chuli( int i, int j, int c ) //c为队伍i的净赢球量
{
tm[i].point += game[i][j];
tm[j].point += game[j][i];
tm[i].qiu += c;
tm[j].qiu -= c;
return;
} void init()
{
memset( vis, false, sizeof(vis) );
memset( game, -, sizeof( game ) );
memset( tm, , sizeof(tm) );
for ( int i = ; i < N; ++i )
{
int a, b, c, d;
scanf( "%d%d%d%d", &a, &b, &c, &d );
if ( c == d )
{
game[a][b] = game[b][a] = ;
}
else if ( c > d )
{
game[a][b] = ;
game[b][a] = ;
}
else
{
game[a][b] = ;
game[b][a] = ;
}
chuli( a, b, c - d );
}
return;
} bool DFS( int *tmp, int cur )
{
if ( cur <= )
{
/*
for ( int i = 1; i <= 4; ++i )
printf( "id=%d point=%d qiu=%d\n", tmp[i], tm[ tmp[i] ].point, tm[ tmp[i] ].qiu );
puts("");
*/
for ( int i = ; i < ; ++i )
{
int u = tmp[i];
int v = tmp[i + ];
if ( tm[u].point < tm[v].point || ( tm[u].point == tm[v].point && tm[u].qiu < tm[v].qiu ) )
return false;
}
return true;
} int j = tmp[cur];
bool ok = true;
for ( int i = ; i <= ; ++i )
{
if ( i == j ) continue;
if ( game[j][i] == - )
{
ok = false;
for ( int k = -; k <= ; ++k ) //枚举净赢球数
{
if ( k < )
{
game[j][i] = ;
game[i][j] = ;
}
else if ( k == )
{
game[j][i] = ;
game[i][j] = ;
}
else
{
game[j][i] = ;
game[i][j] = ;
}
chuli( j, i, k ); //puts("*************");
//show(); if ( DFS( tmp, cur ) ) return true; tm[j].point -= game[j][i];
tm[i].point -= game[i][j];
game[j][i] = -;
game[i][j] = -;
tm[i].qiu += k;
tm[j].qiu -= k; //show();
//puts("=============="); }
}
} if ( ok )
{
if ( cur != )
{
int u = tmp[cur];
int v = tmp[cur + ];
//printf("%d %d %d %d\n",tm[u].point, tm[v].point, tm[u].qiu, tm[v].qiu );
if ( tm[u].point < tm[v].point || ( tm[u].point == tm[v].point && tm[u].qiu < tm[v].qiu ) )
return false;
else
{
if ( DFS( tmp, cur - ) ) return true;
}
}
else
{
if ( DFS( tmp, cur - ) ) return true;
}
}
return false;
} void solved()
{
for ( int i = ; i <= ; ++i )
{
ori[i] = tm[i];
for ( int j = ; j <= ; ++j )
gori[i][j] = game[i][j];
} int temp[];
for ( int i = ; i < ; ++i )
{
int nn = permuta[i];
for ( int j = ; j > ; --j )
{
temp[j] = nn % ;
nn /= ;
}
/*
for ( int j = 1; j <= 4; ++j )
printf( "%d ", temp[j] );
puts("");
*/
for ( int j = ; j <= ; ++j )
{
tm[j] = ori[j];
for ( int k = ; k <= ; ++k )
game[j][k] = gori[j][k];
} if ( DFS( temp, ) )
{
++cnt;
vis[i] = true;
} // puts("-------");
}
} int main()
{
//freopen("s.out", "w", stdout );
while ( ~scanf( "%d", &N ) )
{
init(); cnt = ;
solved(); int ans[];
printf( "%d\n", cnt );
for ( int i = ; i < ; ++i )
if ( vis[i] )
{
int nn = permuta[i];
for ( int j = ; j >= ; --j )
{
ans[j] = nn % ;
nn /= ;
}
for ( int j = ; j < ; ++j )
{
if ( j ) putchar(' ');
printf( "%d", ans[j] );
}
puts("");
}
}
return ;
}

URAL 1957 Wrong Answer 暴力的更多相关文章

  1. URAL 1777 D - Anindilyakwa 暴力

    D - AnindilyakwaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/v ...

  2. HDU 1269 迷宫城堡(DFS)

    迷宫城堡 Problem Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的 ...

  3. 451. Sort Characters By Frequency将单词中的字母按照从高频到低频的顺序输出

    [抄题]: Given a string, sort it in decreasing order based on the frequency of characters. Example 1: I ...

  4. URAL 1010 Discrete Function【简单暴力】

    链接:  http://acm.timus.ru/problem.aspx?space=1&num=1010 http://acm.hust.edu.cn/vjudge/contest/vie ...

  5. V - Can you answer these queries? HDU - 4027 线段树 暴力

    V - Can you answer these queries? HDU - 4027 这个题目开始没什么思路,因为不知道要怎么去区间更新这个开根号. 然后稍微看了一下题解,因为每一个数开根号最多开 ...

  6. ural 1104,暴力取模

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1104 题目大意:输入一个字符串(数字与大写字母组成),输出n,n满足此字符串为n进制时, ...

  7. URAL 2066 Simple Expression (水题,暴力)

    题意:给定三个数,让你放上+-*三种符号,使得他们的值最小. 析:没什么好说的,全算一下就好.肯定用不到加,因为是非负数. 代码如下: #pragma comment(linker, "/S ...

  8. 2019南昌邀请赛网络预选赛 I. Max answer(单调栈+暴力??)

    传送门 题意: 给你你一序列 a,共 n 个元素,求最大的F(l,r): F(l,r) = (a[l]+a[l+1]+.....+a[r])*min(l,r); ([l,r]的区间和*区间最小值,F( ...

  9. Ural 1780 Gray Code 乱搞暴力

    原题链接:http://acm.timus.ru/problem.aspx?space=1&num=1780 1780. Gray Code Time limit: 0.5 secondMem ...

随机推荐

  1. C#TCPClient应用-一个简单的消息发送和接收

    TcpSend窗口用于发送消息,另外写一个用于接收消息的应用程序,消息接受到以后,必须要关闭接收消息的窗口,才能在接收新的消息,不知道怎么能解决这个问题. 源代码: 发送消息的窗口代码 using S ...

  2. php服务器探针

    <?php /* ---------------------------------------------------- */ /* 程序名称: PHP探针-Yahei /* 程序功能: 探测 ...

  3. windows鼠标消息处理与键盘模拟函数

    1.鼠标坐标问题 BOOL GetWindowRect(   HWND hWnd,   LPRECT lpRect  ); RECT x;//定义一个二维数组x ::GetWindowRect(hwn ...

  4. Daily Scrum 11.9

    摘要:本次的meeting主要是继续讨论程序的问题以及单元测试和集成测试等,本次为1.01版本.本次的Task列表如下: Task列表 出席人员 Today's Task Tomorrow's Tas ...

  5. 面试问到:JDBC、hibernate、ibati

    一.JDBC.Connection(连接) 优点:运行高效.快捷. 缺点:代码多.异常多.不支持跨平台. 二.ibatis 1.根据jdbc的基本建立连接. 2.通过anntation+xml.jav ...

  6. 在唯一密钥属性“value”设置为“Default.aspx”时,无法添加类型为“add”的重复集合项

    环境:windows server 2012  asp.net 找到网站目录:wwwroot ,打开web.config文件,在 在<files>与</files>之间加入代码 ...

  7. SQL获取数据库名,表名,列名,说明等信息

    由于最近工作涉及SQL语句较多,对一些不常见的SQL函数.及存储过程下面进行整理和描述,供大家分享: /************************************************ ...

  8. 3640: JC的小苹果 - BZOJ

    让我们继续JC和DZY的故事.“你是我的小丫小苹果,怎么爱你都不嫌多!”“点亮我生命的火,火火火火火!”话说JC历经艰辛来到了城市B,但是由于他的疏忽DZY偷走了他的小苹果!没有小苹果怎么听歌!他发现 ...

  9. Codeforces Round #355 (Div. 2) D. Vanya and Treasure dp+分块

    题目链接: http://codeforces.com/contest/677/problem/D 题意: 让你求最短的从start->...->1->...->2->. ...

  10. Linux查看系统基本信息

    问题描述:         查看系统基本信息 问题解决:     (1)lspci 是一个用来显示系统中所有PCI总线设备或连接到该总线上的所有设备的工具. 用法:    lspci -v (1.1) ...