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) 题解的更多相关文章

  1. UVALive 6955 Finding Lines(随机化优化)题解

    题意:问你是否有一条直线满足这条直线上的点个数与总个数之比不小于p 思路:解法太暴力了,直接随机取两个数,如果能满足条件就输出可以,否则不行.证明一下为什么可以随机化,题目给出可能有P >=20 ...

  2. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  3. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  4. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  5. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  6. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  7. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  8. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

  9. UVALive 6948 Jokewithpermutation dfs

    题目链接:UVALive 6948  Jokewithpermutation 题意:给一串数字序列,没有空格,拆成从1到N的连续数列. dfs. 可以计算出N的值,也可以直接检验当前数组是否合法. # ...

随机推荐

  1. 信息安全系统设计基础实验四:外设驱动程序设计 20135211李行之&20135216刘蔚然

    北京电子科技学院(BESTI) 实 验 报 告 封面 课程:信息安全系统设计基础                                           班级:1352           ...

  2. vs2015发现一个字符串拼接 bug

    VS2015支持 字符串拼接 如下: string user="test"; int password=123; string sql=$" user={user};pa ...

  3. Android 中 appcompat_v7与各类资源报错问题

    最近导一个项目进eclipse弄了一天都弄不好,先总结如下 首先按照网上其他同志的导入sdk/extras下的appcompat_v7项目.然后 发现 我们这里已经更新到6.0了,也就是说,我们报错的 ...

  4. 【POJ各种模板汇总】(写在逆风省选前)(不断更新中)

    1.POJ1258 水水的prim……不过poj上硬是没过,wikioi上的原题却过了 #include<cstring> #include<algorithm> #inclu ...

  5. HTML5——将图片拖拽上传

    如下图所示: 代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  6. Excel解析与导入导出

    第三次结对编程作业 结对成员: 031302610黄志鹏 031302603 陈波 功能分析 1.将初始排课表excel导入系统数据库 2.将系统数据库的排课数据显示在web界面 实现思路 一.实现将 ...

  7. Journey Of Code组组员贡献率

    628是该组的组长,前期的主要任务是数据库的设计,中后期加入实现功能模块的工作,实现了文件的上传和解析excel表格的功能,负责协调组员之间的工作和沟通,并且也是最后上台进行演示的人员:所以贡献率有3 ...

  8. JS子父窗口互相取值赋值详解介绍

    子窗口赋值到父窗口 代码如下 复制代码 <script>function openWin(str) {    window.open(siteurl+"popup/"+ ...

  9. 小菜鸟学Spring-读取属性文件值(三)

    Example: the PropertyPlaceholderConfigurer 属性配置文件内容如下所示: jdbc.driverClassName=org.hsqldb.jdbcDriver ...

  10. 黑客帝国风格必备插件ProPowerTools

    ProPowerTools  详细说明点这里