UVALive 6125 I’ve Got Your Back(gammon) 题解
http://vjudge.net/problem/viewProblem.action?id=37481
East Central Regional Contest Problem D: I’ve Got Your Back(gammon)
A friend of yours is working on an AI program to play backgammon, and she has a small problem. At
the end of the game, each player’s pieces are moved onto a set of board positions called
points
,
numbered through . The pieces can be distributed in any manner across these points: all could
be on point ; could be on point , on point , on point and on point ; etc. Your friend
wants to store all these possible configurations (of which there are ) into a linear array, but she
needs a mapping from configuration to array location. It seems logical that the configuration with all
pieces on point should correspond to array location , and the configuration of all pieces on point
should correspond to the last array location. It’s the ones in between that are giving her problems.
That’s why she has come to you.
You decide to specify a configuration by listing the number of pieces on each point, starting with
point . For example, the two configurations described above could be represented by (
, , , , ,
)
and (
, , , , ,
). Then you can order the configurations in lexicographic ordering, starting with
(,,,,,), then (
, , , , ,
)
,
(
, , , , ,
)
, . . . ,
(
, , , , ,
)
,
(
, , , , ,
)
,
(
, , , , ,
),
(
, , , , ,
), etc., ending with (
, , , , ,
). Now all you need is a way to map these orderings to
array indices. Literally, that’s all you need, because that’s what this problem is all about.
Input
Each test case will consist of one line, starting with a single character, either
‘m’
or
‘u’
. If it is an
‘m’
it will be followed by a configuration and you must determine what array index it gets mapped to. If
it is a
‘u’
then it will be followed by an integer array index i,
≤
i <
, and you must determine
what configuration gets mapped to it. A line containing the single character
‘e’
will end input.
Output
For each test case, output the requested answer – either an array index or a configuration. Follow the
format in the examples below.
Sample Input
m
u
e
Sample Output
Case :
Case :
题目
把15分配到6个格子里,对应一个数。
例如0 0 0 0 0 15是1;
15 0 0 0 0 0是15503。
做法就是先把这些6人组不重复地全部弄出来存起来…然后排个序!然后就和数一一对应了,随便玩。
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll; struct six
{
int a[];
}; six d;
vector<six> v; void dfs(int x,int y)
{
int i;
if(x==)
{
d.a[]=-y;
v.push_back(d);
return;
}
for(i=; i<=-y; i++)
{
d.a[x]=i;
dfs(x+,y+i);
}
} bool cmp(six x,six y)
{
for(int i=; i<; i++)
{
if(x.a[i]<y.a[i]) return true;
if(x.a[i]>y.a[i]) return false;
}
return false;
} bool issame(six x,six y)
{
for(int i=; i<; i++)
{
if(x.a[i]!=y.a[i]) return false;
}
return true;
} int main()
{
int i,j;
v.clear();
dfs(,);
sort(v.begin(),v.end(),cmp);
// for(j=0; j<46; j++)
// {
// cout<<j<<". ";
// for(i=0; i<6; i++)
// cout<<v[j].a[i]<<' ';
// cout<<endl;
// }
char c;
six s;
int t=,x;
while(scanf(" %c",&c)!=EOF)
{
if(c=='m')
{
for(i=;i<;i++)
scanf("%d",&s.a[i]);
for(i=;i<;i++)
if(issame(s,v[i]))
{
printf("Case %d: %d\n",t++,i);
break;
}
}
else if(c=='u')
{
scanf("%d",&x);
printf("Case %d:",t++);
for(i=;i<;i++)
printf(" %d",v[x].a[i]);
puts("");
}
else if(c=='e')
{
break;
}
}
return ;
}
UVALive 6125 I’ve Got Your Back(gammon) 题解的更多相关文章
- UVALive 6955 Finding Lines(随机化优化)题解
题意:问你是否有一条直线满足这条直线上的点个数与总个数之比不小于p 思路:解法太暴力了,直接随机取两个数,如果能满足条件就输出可以,否则不行.证明一下为什么可以随机化,题目给出可能有P >=20 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- UVALive 6948 Jokewithpermutation dfs
题目链接:UVALive 6948 Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...
随机推荐
- Python类库下载
https://sourceforge.net/projects/pywin32/files/pywin32/ WMI库的安装 下载 http://timgolden.me.uk/python/wmi ...
- [CareerCup] 13.3 Virtual Functions 虚函数
13.3 How do virtual functions work in C++? 这道题问我们虚函数在C++中的工作原理.虚函数的工作机制主要依赖于虚表格vtable,即Virtual Table ...
- 《Linux及安全》实验安排
SEED(SEcurity EDucation)项目由雪城大学杜文亮教授2002年创立,为计算机教学提供一套信息安全实验环境,目前已开发超过30个实验,涵盖广泛的安全原理,被全世界数百个高校采用. 实 ...
- 查询一个ID出现2种结果的情况
项目中书籍分个人和机构,分属不同的表 所以有的时候ID是一样的,那么只根据ID查询书籍就会存在ID=xxx的既有个人又有机构,而通常我们可能只需要一个,多的没做区分就出问题了! 所以数据统一做查询的时 ...
- Unity3D UGUI中ScrollRect的一些知识点
需求 这几天在公司里,项目需要将游戏游戏中的2D城堡界面在拉动的时候显示出3D的拉近效果.当时是在Cocos2d-x下实现的.回家的时候自己重新用Unity实现的了一遍. 虽然现在Unity已经到了5 ...
- 原生js dom记忆的内容
1.DOM基础getElementByIdgetElementByTagNamegetElementByName getElementsByClass querySelector querySelec ...
- 'UserInfoBLL' node cannot be resolved for the specified context [MVC展示数据.Controllers.LoginController]问题解决
我们在配置Spring.Net时,往往会提示找不到,然而看了看都对着呢?那么问题出在了哪? 问题呈现: 进行如下修改,将名字随便取个,不为BLL方法名字即可,我这里添加了一个1,注意这里改了,控制器里 ...
- angular自己的笔记
angular知道怎么用了, 就打算读一读源代码; <html ng-app="phonecatApp"> <head> <meta charset= ...
- poj 3233 矩阵快速幂+YY
题意:给你矩阵A,求S=A+A^1+A^2+...+A^n sol:直接把每一项解出来显然是不行的,也没必要. 我们可以YY一个矩阵: 其中1表示单位矩阵 然后容易得到: 可以看出这个分块矩阵的左下角 ...
- poj 3683 2-SAT入门
原题模型:两者(A,B)不能同时取 #include "cstdio" #include "vector" #include "stack" ...