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. Python之str(),repr(),``

    对于对象obj: str()生成的字串是给人看的 repr()生成的字串是给解析器看的 ``与repr()等义. 最直接就是: ------------------- obj=eval(repr(ob ...

  2. mysql 查询

    查询数据:select s_name from student limit 1;//限制数量 select * from student where s_id in (select s_id from ...

  3. 【F#】 WebSharper框架

    WebSharper,它是一个基于F#构建的Web开发平台,使用F#构造从前到后的一整套内容.其中利用到F#中许多高级的开发特性,并可以将F#代码直接转化JavaScript,这样服务器端和客户端的通 ...

  4. [转]- Winform 用子窗体刷新父窗体,子窗体改变父窗体控件的值

    转自:http://heisetoufa.iteye.com/blog/382684 第一种方法: 用委托,Form2和Form3是同一组 Form2  using System; using Sys ...

  5. MVC 使用 FluentScheduler 定时器计划任务

    MVC 使用 FluentScheduler 定时器计划任务 MacBook Pro 只有四个 USB Type-C 接口是否错了? 一项新技术的诞生总会对已存在的事物造成冲击或影响,如果大家都害怕冲 ...

  6. android 解决启动页面加载图片空白以及去掉标题栏

    有时候启动页面根据白天晚上来启动时实现加载不同的图片效果,但是加载时会出现短暂的空白,解决方法如下: android:theme="@android:style/Theme.Transluc ...

  7. Ajax ContentType 列表

    ".*"="application/octet-stream" ".001"="application/x-001" & ...

  8. jquery 取值赋值

    <input type="text" id="range_complete" /> $('#range_complete').val();//取值 ...

  9. nenu contest3 The 5th Zhejiang Provincial Collegiate Programming Contest

    ZOJ Problem Set - 2965 Accurately Say "CocaCola"!  http://acm.zju.edu.cn/onlinejudge/showP ...

  10. app被Rejected 的各种原因翻译

    1. Terms and conditions(法律与条款) 1.1 As a developer of applications for the App Store you are bound by ...