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. hdu 2256 Problem of Precision 构造整数 + 矩阵快速幂

    http://acm.hdu.edu.cn/showproblem.php?pid=2256 题意:给定 n    求解   ? 思路: , 令  , 那么 , 得: 得转移矩阵: 但是上面求出来的并 ...

  2. Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'(using password: YSE)

    安装mysql后,使用命令登录mysql居然报错了,Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'(using ...

  3. 构件图 Component Diagram

    构件图是显示代码自身结构的实现级别的图表.构件图由诸如源代码文件.二进制代码文件.可执行文件或动态链接库 (DLL) 这样的构件构成,并通过依赖关系相连接 下面这张图介绍了构件图的基本内容: 下面这张 ...

  4. Qt Script

    旧项目运行在Qt4.x上,要加上一个脚本逻辑,只能上Qt Script.(建议新项目使用QJSEngine) QT += script #include <QtScript> int cp ...

  5. IR的评价指标—MAP,NDCG,MRR

    http://www.cnblogs.com/eyeszjwang/articles/2368087.html MAP(Mean Average Precision):单个主题的平均准确率是每篇相关文 ...

  6. C#: Create a WebRequest with HTTPClient

    http://www.cnblogs.com/shanyou/archive/2012/03/21/2410739.html http://msdn.microsoft.com/zh-cn/libra ...

  7. shell uniq sort -u 去重排序

    sort -u 和 uniq都能起到删除重复信息的功能,那么他们的区别究竟在哪呢? $ cat test jason jason jason fffff jason 下面分别执行三个命令 :sort ...

  8. 新建标准mavenWeb工程以及Maven的web应用标准目录结构建议

    到现在为止,使用Maven结构的Web工程越来越多,因此在此介绍一下通过Maven来构建项目的相关知识.     文档主要分为两部分:       1.如何通过maven来构建多模块的web项目    ...

  9. DevExpress控件使用系列--ASPxTreeList

      控件功能 结合列表控件及树控件的优点,在列表控件中实现类型树的多层级操作 官方说明 http://documentation.devexpress.com/#AspNet/clsDevExpres ...

  10. PHP开发框架[流行度排名]

    在PHP开发中,选择合适的框架有助于加快软件开发,节约宝贵的项目时间,让开发者专注于功能的实现上.Sitepoint网站做了一个小的调查,结果显示最流行的PHP框架前三甲为:Laravel.Phalc ...