链接:
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=456&page=show_problem&problem=4098
刘汝佳书上的例题(训练指南P16),感觉这题很好,尤其是生成旋转序列的方法,这也是这题的重点。学习了。
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<string>
using namespace std;
map<string,int>color;
int cube[5][6];
int now[5][6];
int n, ans;
int p[7];
int cnt[25];
int dice24[24][6] = {
3,1,0,5,4,2,
1,2,0,5,3,4,
2,4,0,5,1,3,
4,3,0,5,2,1,
3,5,1,4,0,2,
5,2,1,4,3,0,
2,0,1,4,5,3,
0,3,1,4,2,5,
0,1,2,3,4,5,
1,5,2,3,0,4,
5,4,2,3,1,0,
4,0,2,3,5,1,
5,1,3,2,4,0,
1,0,3,2,5,4,
0,4,3,2,1,5,
4,5,3,2,0,1,
3,4,5,0,1,2,
4,2,5,0,3,1,
2,1,5,0,4,3,
1,3,5,0,2,4,
3,0,4,1,5,2,
0,2,4,1,3,5,
2,5,4,1,0,3,
5,3,4,1,2,0,
};
int left[] = {1,5,2,3,0,4};
int up[] = {3,1,0,5,4,2};
// “旋转”
void rot(int* T, int* p){
int q[6];
memcpy(q,p,sizeof(q));
for(int i=0; i<6; ++i) p[i] = q[T[i]];
}
// 生成旋转序列用的
void func(){
int p0[6] = {0,1,2,3,4,5};
printf("int dice24[24][6] = {\n");
for(int i=0; i<6; ++i) {
int p[6];
memcpy(p, p0, sizeof(p0));
if(i==0) rot(up, p);
if(i==1) { rot(left,p); rot(up, p); }
if(i==3) { rot(up,p); rot(up, p); }
if(i==4) { rot(left, p); rot(left,p); rot(up,p); }
if(i==5) { rot(left, p); rot(left,p); rot(left,p); rot(up,p);}
for(int j=0; j<4; ++j){
printf("%d,%d,%d,%d,%d,%d,\n",p[0],p[1],p[2],p[3],p[4],p[5]);
rot(left,p);
}
}
printf("};\n");
}
// dfs暴力答案
void dfs(int cur){
if(cur>=n){
int counter=0;
for(int i=0; i<6; ++i) {
memset(cnt, 0, sizeof(cnt));
int tmp=0;
for(int j=0; j<n; ++j){
tmp = max(tmp, ++cnt[now[j][i]]);
}
counter += n-tmp;
}
ans = min(counter, ans);
return;
}
for(int i=0; i<24; ++i){
for(int j=0; j<6; ++j)
now[cur][j] = cube[cur][dice24[i][j]];
dfs(cur+1);
}
}
int main(){
char c[30];
int idx;
while(~scanf("%d", &n) && n){
idx=0;
color.clear();
for(int i=0; i<n; ++i){
for(int j=0; j<6; ++j) {
scanf("%s", c);
if(color.find(c) == color.end()){
color[c] = ++idx;
}
cube[i][j] = color[c];
}
}
ans = 10000000;
for(int i=0; i<6; ++i) now[0][i]=cube[0][i];
dfs(1);
printf("%d\n", ans);
}
return 0;
}
分享到:
相关推荐
各种unity shader教程需要的脚本资源。使用时在本地Asset目录下建立一个Hidden目录,然后把shader脚本放进去就可以了
北大POJ2513-Colored Sticks【TrieTree+MergeSet+EulerPath】 解题报告+AC代码
simulate_dual-colored_ball(仿真模拟双色源码_含用到的自制工具).zip
Colored Time Range Selector A smart colored time range selector. Users can select just free time with a handy colorful range selector. Screen Shots Features Select a time range between 2 hours ...
ln -s ../../irssi-colored-nicks/colored_nicks.pl 要自动启用脚本,请将其添加到~/.irssi/scripts/autorun/ : cd ~/.irssi/scripts/autorun ln -s ../colored_nicks.pl 转到.irssi并链接关联的主题,以便可以在...
fisher add decors/fish-colored- man omf install https://github.com/decors/fish-colored- man 颜色选择 如果要更改颜色,请在config.fish添加以下选项。 # Solarized Dark & Green highlight set -g man_blink ...
responsive-website-colored-columns:练习创建响应式网站
自定义进度条的颜色。可以任意改变进度条中移动进度的颜色(UIProgressView默认是蓝色,而且无法改变)。 注意:请在Mac下解压使用
gem 'activerecord-colored_log_subscriber' 然后执行: $ bundle 或将其自己安装为: $ gem install activerecord-colored_log_subscriber 发展 签出仓库后,运行bin/setup来安装依赖项。 然后,运行bundle ...
建立在安装 $ composer require noximo/php-colored-ascii-linechart用法简单输出: $ linechart = new Linechart ();echo $ linechart -> addMarkers ([ 1 , 2 , 3 , 4 , 5 , 6 ])-> addPoint ( 4 , 2 )-> chart ...
A hybrid algorithm based on seeded region growing and k-means clustering was... Experimental results show that the proposed method is suitable for segmentation of multi-colored object, while conventional
随机游走matlab代码彩色随机游走 论文中提出的方法的实现: 作者:Yaowei ...Colored Random Walk}, author={Yan, Yaowei and Bian, Yuchen and Luo, Dongsheng and Lee, Dongwon and Zhang, Xiang}, booktitle
covid彩色法国地图法国有关covid19的一些数据的地图这是一个静态网站,可以根据需要托管。
双面,自发光,带透明通,带透明贴图,材质。可供参考使用。通过贴图,颜色,透明通道叠加实现。通过贴图,颜色,透明通道叠加实现。
数独色在此实验中,我创建了过度叠加的彩色数独。 该项目的灵感来自Alex Bellos的tridokus,我在他的《雪花贝壳之星:Numberland中的着色历险记》一书中发现了这个故事。入门先决条件您将需要安装以下软件包(如果...
升起的儿子,或有色人种的前身和进步这是``The Rising Son''或William Wells Brown的《 Colored Race的前身和进步》一书的源文件的git存储库。 本书是美国的公共领域。有关详细信息,请参阅LICENSE文件。发现错误? ...
Quake2色refsoft 在Knightmare的非官方Q2修补程序中使用彩色灯光的Quake2的ref_soft.dll。 这是一个替代ref_soft.dll,为Quake 2软件渲染器添加了彩色照明和宽屏水扭曲支持。 Alphatest和透明度得到了提高,这是一...
俄罗斯方块从0到彩色界面大一c语言课设写的俄罗斯方块,看了好几遍原著的源码,从0开始重新写入原著进行了注释,改进与优化。原著能力很强,感谢原著自写的初版参考,原著链接: : 阅读指引(重要)文字说明比较长,...
-- Accent-colored raised button with ripple --><button class="mdl-button mdl-js-button mdl-button--raised mdl-button--accent mdl-js-ripple-effect"> Button</button><!-- Colored FAB ...
开源项目-saschagrunert-ccli.zip,ccli - colored command line argument parsing