A.

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//next_permutation
ll mod = 1e9 + ;
int main()
{
//freopen("out1.txt", "w", stdout);
int v1, v2, v3, vm;
int anser;
cin >> v1 >> v2 >> v3 >> vm;
int flag = ;
if (vm >= v2)
{
cout << - << endl;
exit();
}
for (int i = v3; i <= * v3; i++)
{
if (i >= vm && i <= * vm)
{
flag = ;
anser = i;
break;
}
}
if (flag)
{
cout << * v1 << endl;
cout << * v2 << endl;
cout << anser << endl;
}
else
{
cout << - << endl;
}
}

B.

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//next_permutation
ll mod = 1e9 + ;
char f[][];
bool judge(int x)
{
int flag = ;
int cur = (x - ) / ;
x = x % ;
if (x == )
{
x = ;
}
int cur1 = x - ;
// cout << "y" << " " << cur1 * 3 + 1 << " " << cur1 * 3 + 3 << endl;
// cout << "x" << " " << cur * 3 + 1 << " " << cur * 3 + 3 << endl;
for (int i = cur * + ; i <= cur * + ; i++)
{
for (int j = cur1 * + ; j <= cur1 * + ; j++)
{
if (f[i][j] == '.')
{
f[i][j] = '!';
flag = ;
}
}
}
if (flag)
{
return false;
}
else
{
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
if (f[i][j] == '.')
{
f[i][j] = '!';
}
}
}
return true;
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out1.txt", "w", stdout);
char now;
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
scanf("%c", &now);
if (now != '.' && now != 'x' && now != 'o')
{
j--;
}
else
{
f[i][j] = now;
}
}
}
int x, y;
cin >> x >> y;
x = x % ;
if (x == )
{
x = ;
}
y = y % ;
if (y == )
{
y = ;
}
int want = (x - ) * + y;
//cout << want << endl;
judge(want);
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
cout << f[i][j];
if (j % == && j % != )
{
cout << " ";
}
if (j % == )
{
cout << endl;
}
}
if (i % == )
{
cout << endl;
}
}
}

C.

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//next_permutation
ll mod = 1e9 + ;
int flag = ;
int cur = ;
char letter = '.';
int num[];
int test[];
unordered_set<char> ans;
int main()
{
//freopen("out1.txt", "w", stdout);
ios::sync_with_stdio();
cin.tie();
cout.tie(); int n;
int anser = ;
cin >> n;
char a;
string b;
for (int i = ; i < ; i++)
{
ans.insert('a' + i);
}
for (int i = ; i <= n; i++)
{
cin >> a >> b;
if (ans.size() == )
{
if (a == '!')
{
anser++;
}
else if (a == '?')
{
if (b[] == letter)
{
break;
}
else if(!ans.count(b[]))
{
anser++;
}
}
continue;
}
if (a == '!')
{ unordered_set<char> now;
for (char j : b)
{
now.insert(j);
}
for (auto it = ans.begin(); it != ans.end();)
{
if (!now.count(*it))
{
ans.erase(it++);
}
else
{
it++;
}
}
}
else
{
for (char j : b)
{
ans.erase(j);
}
}
}
cout << anser << endl;
}

D.给你一个N*M的矩阵 每位的编号为(i-1)*m+j  要求你重新排列 使得重新排列后每个数与原来相邻的数互不相邻 不存在则输出-1

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//next_permutation
ll mod = 1e9 + ;
int n, m;
int ans[];
int pop = ;
int now[];
int f[][];
int num[][];
int cur[][];
int flagf = ;
stack<int> s;
void dfs(int x, int y)
{
if (x == n * m + )
{
flagf = ;
for (int i = n; i >= ; i--)
{
for (int j = m; j >= ; j--)
{
s.push(cur[i][j]);
}
}
return ;
}
if (flagf)
{
return ;
}
int aimx = (x - ) / m + ;
int aimy = (x - ) % m + ;
for (int i = ; i <= n * m; i++)
{
if ((y & ( << i)) == )
{
if ((!num[cur[aimx - ][aimy]][i]) && (!num[cur[aimx][aimy - ]][i]))
{
int numcur = y | ( << i);
//cout << aimx << " " << aimy << " " << i << endl;
cur[aimx][aimy] = i;
dfs(x + , numcur);
}
}
}
}
void solve()
{
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
f[i][j] = (i - ) * m + j;
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
for (int k = ; k <= ; k++)
{
int dx = i + turn[k][];
int dy = j + turn[k][];
if (f[dx][dy] != )
{
num[f[i][j]][f[dx][dy]] = num[f[dx][dy]][f[i][j]] = ;
}
} }
}
dfs(, );
if (flagf)
{
cout << "YES" << endl;
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
cout << s.top() << " ";
s.pop();
}
cout << endl;
}
}
else
{
cout << "NO" << endl;
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out1.txt", "w", stdout);
while (cin >> n >> m)
{
if (n <= && m <= )
{
solve();
exit();
}
if (n < m)
{
printf("YES\n");
for (int i = ; i <= n; i++)
{
if (i & )
{
for (int j = (i - ) * m + ; j <= i * m; j += )
{
cout << j << " ";
}
for (int j = (i - ) * m + ; j <= i * m; j += )
{
cout << j << " ";
}
cout << endl;
}
else
{
for (int j = (i - ) * m + ; j <= i * m; j += )
{
cout << j << " ";
}
for (int j = (i - ) * m + ; j <= i * m; j += )
{
cout << j << " ";
}
cout << endl;
}
}
}
else
{
printf("YES\n");
for (int i = ; i <= m; i++)
{
if (i & )
{
now[i] = ;
}
else
{
now[i] = ;
}
}
for (int i = ; i <= n; i++)
{
for (int j = ; j <= m; j++)
{
ans[pop++] = (now[j] - ) * m + j;
now[j] += ;
if (now[j] > n)
{
now[j] = (j & ) + ;
}
//cout<<now[j]<<endl;
}
}
for (int i = ; i < pop; i++)
{
printf("%d", ans[i]);
if (i % m == )
{
printf("\n");
}
else
{
printf(" ");
}
}
}
}
}

E.状压DFS

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//next_permutation
ll mod = 1e9 + ;
int n, m;
int num[][];
stack<int> cur, ans;
int anser = ;
void dfs(int now)
{
if (cur.size() >= ans.size())
{
return ;
}
if (now == n)
{
for (int i = ; i < n; i++)
{
if (num[n][i] != ( << n) - )
{
return ;
}
}
ans = cur;
return ;
}
memcpy(num[now + ], num[now], sizeof(num[now]));
dfs(now + );
for (int i = ; i < n; i++)
{
if (( << i) & num[now][now])
{
num[now + ][i] |= num[now][now];
}
}
cur.push(now);
dfs(now + );
cur.pop();
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out1.txt", "w", stdout);
cin >> n >> m;
int pa, pb;
for (int i = ; i < n; i++)
{
num[][i] = << i;
//cout<<p[i]<<endl;
ans.push(i);
}
for (int i = ; i <= m; i++)
{
scanf("%d %d", &pa, &pb);
pa--, pb--;
num[][pa] |= << pb;
num[][pb] |= << pa;
}
//pf();
dfs();
cout << ans.size() << endl;
while (!ans.empty())
{
cout << ans.top() + << " ";
ans.pop();
}
cout << endl;
}

Codeforces 907 矩阵编号不相邻构造 团操作状压DFS的更多相关文章

  1. Xor-sequences CodeForces - 691E || 矩阵快速幂

    Xor-sequences CodeForces - 691E 题意:在有n个数的数列中选k个数(可以重复选,可以不按顺序)形成一个数列,使得任意相邻两个数异或的结果转换成二进制后其中1的个数是三的倍 ...

  2. Educational Codeforces Round 12 D. Simple Subset 最大团

    D. Simple Subset 题目连接: http://www.codeforces.com/contest/665/problem/D Description A tuple of positi ...

  3. Codeforces 610C:Harmony Analysis(构造)

    [题目链接] http://codeforces.com/problemset/problem/610/C [题目大意] 构造出2^n个由1和-1组成的串使得其两两点积为0 [题解] 我们可以构造这样 ...

  4. Codeforces 804E The same permutation(构造)

    [题目链接] http://codeforces.com/contest/804/problem/E [题目大意] 给出一个1到n的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出 ...

  5. Codeforces 1276C/1277F/1259F Beautiful Rectangle (构造)

    题目链接 http://codeforces.com/contest/1276/problem/C 题解 嗯,比赛结束前3min想到做法然后rush不出来了--比赛结束后又写了15min才过-- 以下 ...

  6. CodeForces 450B 矩阵

    A - Jzzhu and Sequences Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  7. codeforces 477B B. Dreamoon and Sets(构造)

    题目链接: B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input st ...

  8. Codeforces Gym 100187K K. Perpetuum Mobile 构造

    K. Perpetuum Mobile Time Limit: 2 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/pro ...

  9. Codeforces 906B. Seating of Students(构造+DFS)

    行和列>4的可以直接构造,只要交叉着放就好了,比如1 3 5 2 4和2 4 1 3 5,每一行和下一行用不同的方法就能保证没有邻居. 其他的可以用爆搜,每次暴力和后面的一个编号交换并判断可行性 ...

随机推荐

  1. Python的复制,浅拷贝和深拷贝

    https://www.cnblogs.com/xueli/p/4952063.html 如果给一个变量赋值一个对象,那么新变量和原对象变量将会是同一个引用,其中一方改变,另一方也会改变. 该问题可以 ...

  2. leetcode-mid-backtracking -78 Subsets

    mycode   86.06% class Solution(object): def subsets(self, nums): """ :type nums: List ...

  3. 十八、RF中selenium2library构造函数中参数解释

    def __init__(self,                  timeout=5.0,                  implicit_wait=0.0,                 ...

  4. robotframework之使用cookies登陆

    有的系统是使用cookies保持登陆的,而RF的Request库里面没有像Selenium2Library里面一样操作cookies的关键字,若接口需要登录则只能用UI自动化先登录,然后再将cooki ...

  5. Ubuntu vimrc 和 bashrc 配置

    先上效果图,把vimrc 和bashrc 备份一下.. vimrc: map <F9> :call SaveInputData()<CR> func! SaveInputDat ...

  6. Failure to find com.oracle:ojdbc6:jar:11.2.0.1.0

    报错原因:oracle的ojdbc.jar是收费的,maven的中央仓库是没有的,需要下载到本地,然后打包进maven仓库 1.下载ojdbc6-11.2.0.1.0.jar包 http://cent ...

  7. 操作Json对象的C#方法

    json对象长这样 { "UniqueName": { "Required": "true", , , "Regex": ...

  8. MySQL数据库的连接池问题

    3. sqlalchemy设置连接池数量上限设置 SQLALCHEMY_POOL_SIZE = 100 SQLALCHEMY_MAX_OVERFLOW = 0 # 超出连接池数量的连接后,最多可以连接 ...

  9. 八、Zabbix-应用集、监控项

    一.应用集 1.应用集一般配合监控项使用,它相当于多个同类型的监控项的分类目录 2.添加应用集 (1)配置—>模板—>需要调整的模板—>应用集 (2)添加应用集 (3) (4)查看应 ...

  10. UrlConnection发送http请求 中文乱码解决

    中文乱码 DataOutputStream dos = new DataOutputStream(httpConn.getOutputStream()); //dos.writeBytes(jsonD ...