【例题 6-19 UVA - 1572】Self-Assembly
2024-08-29 03:21:49
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
旋转和翻转,会发现。
如果可以顺着某个方向一直放的话。
总是能转换成往下或者往右连的。
则只要能够出现一个连接顺序的循环,则总是有解的。
->转化成图论模型
如果一个正方形有A+
另外一个正方形有A-B+C+D-
那么从A+连3条边分别到B+,C+,D-
按照这样的方式连,如果能出现一个环的话,肯定是有解的
->有一条边,就已经说明能够新增加一个正方形了。
拓扑排序判环即可
【代码】
/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 52;
const int NN = (int) 4e4;
int n,tot;
map <string,int> mmap;
int g[N+10][N+10],du[N+10],num;
bool bo[N+10];
vector <int> v[NN+100];
queue <int> dl;
int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
for (char i = 'A';i <= 'Z';i++){
string temp ="";
temp+= i;temp += '-';
mmap[temp] = ++tot;
}
for (char i = 'A';i <= 'Z';i++){
string temp = "";
temp += i;temp += '+';
mmap[temp] = ++tot;
}
for (int i = 1;i <= NN;i++) v[i].resize(4);
while ( cin >> n ){
memset(g,0,sizeof g);
memset(du,0,sizeof du);
memset(bo,0,sizeof bo);
for (int ii = 1;ii <= n;ii++){
string s;
cin >> s;
string temp = "";
for (int i = 0,j = 0;i < 7;i+=2,j++){
temp = s.substr(i,2);
v[ii][j] = mmap[temp];
bo[v[ii][j]] = 1;
}
}
for (int ii = 1;ii <= n;ii++){
for (int i = 0;i < 4;i++){
if (v[ii][i]==0) continue;
int x = (v[ii][i]>26)?(v[ii][i]-26):(v[ii][i]+26);
if (!bo[x]) continue;
for (int j = 0;j <4 ;j++)
if (i!=j){
int y = v[ii][j];
if (y==0) continue;
if (!g[x][y]){
du[y]++;
}
g[x][y] = 1;
}
}
}
num = 52;
for (int i = 1;i <= 52;i++)
if (du[i]==0){
dl.push(i);
du[i] = -1;
}
while (!dl.empty()){
num--;
int x = dl.front();
dl.pop();
for (int i = 1;i <= 52;i++)
if (g[x][i]){
g[x][i] = g[i][x] = 0;
du[i]--;
if (du[i] == 0){
dl.push(i);
}
}
}
if (num!=0){
cout << "unbounded" << endl;
}else{
cout << "bounded" << endl;
}
}
return 0;
}
最新文章
- 一个大数据的demo
- HTML5的学习--performance获取加载时间的工具
- Cordova - 使用Cordova开发iOS应用实战1(配置、开发第一个应用)
- [Android Tips] 1. Getting StatusBar Height
- Android手势锁实现
- Asp.net中用户自定义控件 ascx的使用
- [数据结构]Treap简介
- Python学习之一:Python2.7与opencv2.4安装配置
- dotnet core 开发无缝兼容Http和Websocket协议的接口服务
- python NLTK安装
- VNF网络性能提升解决方案及实践
- ubuntu上编译linux内核
- Viewer.js 是一款强大的 jQuery 图像浏览插件。
- <;转>;特征工程(一)
- AppScan安全测试入门操作
- WebLogic Server 12c相对JBoss EAP 6的优势
- javascript - = 、==、===、!=、!==、&;&;、||、!
- 设置 PyCharm 软件中 Terminal 窗口 中启动的 python 交互命令的版本
- windows下启动Apache报443错误!
- [NOIP模拟赛][贪心]奶牛晒衣服.