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. poj 3740 Easy Finding 二进制压缩枚举dfs 与 DLX模板详细解析

    题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 ...

  2. .NET特性-Attribute

    两篇文章有助于学习Attribute特性的概念. http://blog.csdn.net/byondocean/article/details/6802111 http://www.cnblogs. ...

  3. Seafile V4.1 安装笔记

    yum -y install gcc gcc-c++ make cmake pcre pcre-devel expat expat-devel curl wget mlocate gd gd-deve ...

  4. MVC 删除文件

    protected void DeleteTempFiles(string iFileName) { FileInfo f = new FileInfo(iFileName); DirectoryIn ...

  5. Entity Framework(序)

    ADO.NET Entity Framework 是一个对象-关系的映射结构,它提供了ADO.NET的一个抽象,可基于引用的数据库获取对象模型.可以通过Entity Framework 使用不同的变成 ...

  6. C#中读取二维数组每位的长度

    C#中的二维数组,如int[,] A=new int[a,b];则 a=A.GetLength(0);即可获得二维数组中第一维的长度. b=A.GetLength(1);即可获得二维数组中第二维的长度 ...

  7. Javascript数据类型之Undefined和null

    Javascrip中的数据类型分为原始数据类型(primitive type)和对象数据类型(object type). 原始数据类型 原始数据类型包括:数字.字符串.布尔值.null.undefin ...

  8. DataGridView 的cell赋值没有线程间访问的限制吗?

    1.如下代码,对DataGridView 的cell赋值不会出现线程访问问题,为什么呢? public Form1() { InitializeComponent(); } private void ...

  9. WinForm中Component Class、User Control及Custom Control的区别和使用建议

    reference: http://blog.csdn.net/redstonehe/article/details/1536549 .NET Framework 为您提供了开发和实现新控件的能力.除 ...

  10. websphere变成英文了怎么变回中文

    今天进来发现,websphere在浏览器里面居然是英文的.这是因为我的浏览器少了一个中文语言设置,其实和页面编码无关. 解决办法: IE浏览器右键属性 -- internet选项 --  常规 -- ...