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. [CareerCup] 11.5 Search Array with Empty Strings 搜索含有空字符串的数组

    11.5 Given a sorted array of strings which is interspersed with empty strings, write a method to fin ...

  2. windows编程原理

    这里在学网络编程时遇到了讲解windows的编程,稍微整理一下windows编程原理,顺便复习一下. 首先,理解Windows 程序运行原理:Windows应用程序,操作系统,计算机硬件之间的相互关系 ...

  3. WIN8 浏览器排版不兼容问题

    经常访问网站失败 访问部分网站只显示白底蓝字没有排版也没有图片 尝试了网上的各种方法,也是用了360和百度安全管家的网页修复 重置了IE设置 都不行!!! 最后有效的方法是 更换DNS 208.67. ...

  4. 微信支付开发-Senparc.Weixin.MP详解

    年底了,反而工作更忙了,我从15年11月开始写<1024伐木累>系列小说和爆笑对白,得到了很多身边的技术好友的支持,现在爆笑对白已经有越来越多的朋友一起帮着写段子,整理,包括小说内容的编辑 ...

  5. 第一章 OO大智慧

    今天,正式开始读王涛写的<你必须知道的.NET(第二版)>,刚开始读了序,觉得写的相当精彩,就被吸引住了.看了一会发现本书的特点可能就是以例举例,形象生动,比较期待的样子.虽然前面讲的概念 ...

  6. 16.C#初见Lambda表达式及表达式树(九章9.1-9.3)

    在说明Lambda相关知识前,我们需要了解Lambda表达式常用于LINQ,那么我们来聊下LINQ. LINQ的基本功能就是创建操作管道,以及这些操作需要的任何状态.这些操作表示了各种关于数据的逻辑: ...

  7. c# winform 火狐浏览器 查看cookie

    c# winform 火狐浏览器 查看cookie Firefox的Cookie数据位于:%APPDATA%\Mozilla\Firefox\Profiles\ 目录中的xxx.default目录,名 ...

  8. DELL R710服务器做RAID5磁盘阵列图文教程

    本文转载于:http://www.jb51.net/article/53707.htm,只为做笔记使用 同时我们还可以选择一块硬盘做热备盘,就是说当配的raid5中有一个硬盘坏了的时候,它立马顶上,然 ...

  9. Maven-改变本地存储仓库位置

    修改 maven 仓库存放位置: 找到 maven 下的 conf 下的 settings.xml 配置文件,假设maven安装在D:\Server目录中.那么配置文件应该在 D:\Server\ma ...

  10. Tomcat 使用说明

    Tomcat下有7个目录,分别是bin,conf,lib,logs,temp,webapps,work 目录 Tomcat根目录在tomcat中叫<CATALINA_HOME> 1.< ...