2013 ACM/ICPC 亚洲区 杭州站
题目链接 2013杭州区域赛
Problem A
Problem B
这题我用的是SPFA+ mask dp
首先跑5次SPFA:
1次是求出每个起点和其他所有点的最短距离
4次是求出每个输入的点和其他所有点的最短距离
然后就是dp
设dp[mask][i]为,mask状态下,以i为终点的最优方案
然后做一遍状压DP即可。
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) const int N = 103;
const int M = 1e4 + 10;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1}; bool inqueue[M], fl;
int c[N][N], f[6][6], a[M], d[M], dp[101][6];
char s[N][N];
int cnt, n, m, k;
vector <int> v[M]; inline void addedge(int x, int y){
v[x].push_back(y);
v[y].push_back(x);
} void SPFA(int s){
memset(inqueue, false, sizeof inqueue);
rep(i, 1, cnt) d[i] = 1 << 29;
d[s] = 0;
queue <int> q;
q.push(s); while (!q.empty()){
int x = q.front();
q.pop();
inqueue[x] = false;
for (auto u : v[x]){
if (d[u] > d[x] + 1){
d[u] = d[x] + 1;
if (!inqueue[u]){
inqueue[u] = true;
q.push(u);
}
}
}
}
} int main(){ while (~scanf("%d%d", &n, &m), n + m){
rep(i, 1, n) scanf("%s", s[i] + 1);
cnt = 0;
rep(i, 1, n) rep(j, 1, m) c[i][j] = ++cnt; scanf("%d", &k);
rep(i, 1, n) rep(j, 1, m) if (s[i][j] == '@'){
a[k] = c[i][j];
s[i][j] = '.';
break;
} rep(i, 0, k - 1){
int x, y;
scanf("%d%d", &x, &y);
a[i] = c[x][y];
} rep(i, 0, n * m + 1) v[i].clear(); rep(i, 1, n){
rep(j, 1, m) if (s[i][j] == '.'){
rep(k, 0, 3){
int x = i + dx[k], y = j + dy[k];
if (s[x][y] == '.'){
addedge(c[i][j], c[x][y]);
}
}
}
} SPFA(a[k]); rep(i, 0, k) rep(j, 0, k) f[i][j] = 1 << 29;
rep(i, 0, k){
SPFA(a[i]);
rep(j, 0, k) if (i == j) f[i][j] = 0;
else f[i][j] = d[a[j]];
} rep(i, 0, 53) rep(j, 0, 5) dp[i][j] = 1 << 29;
rep(i, 0, k - 1) dp[1 << i][i] = f[i][k]; rep(i, 1, ((1 << k) - 1)){
if (__builtin_popcount(i) != 1){
rep(j, 0, k - 1) if ((i >> j) & 1){
rep(l, 0, k - 1) if (((i >> l) & 1) && (j != l)){
dp[i][j] = min(dp[i][j], dp[i ^ (1 << j)][l] + f[j][l]);
}
}
}
} int ans = 1 << 30;
rep(i, 0, k - 1) ans = min(ans, dp[(1 << k) - 1][i]);
printf("%d\n", ans < 1e6 ? ans : -1);
} return 0;
}
Problem C
跟着题意模拟一遍
关键是那个旋转要一次性写对
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i(a); i <= (b); ++i)
#define dec(i, a, b) for (int i(a); i >= (b); --i) const int N = 41; int a[N][N], b[N][N];
int n;
int ans; void solve(){
int c[N][N]; memset(c, 0, sizeof c);
rep(i, 1, n) rep(j, 1, n) c[i][j] = a[j][n - i + 1];
rep(i, 1, n) rep(j, 1, n) a[i][j] = c[i][j];
} int main(){ while (~scanf("%d", &n), n){
rep(i, 1, n) rep(j, 1, n) scanf("%d", &a[i][j]);
rep(i, 1, n) rep(j, 1, n) scanf("%d", &b[i][j]); ans = 0;
rep(p, 1, 4){
solve();
int now = 0;
rep(i, 1, n) rep(j, 1, n) if (a[i][j] == b[i][j]) ++now;
ans = max(ans, now);
} printf("%d\n", ans);
} return 0;
}
Problem D
Problem E
Problem F
Problem G
Problem H
Problem I
Problem J
Problem K
2013 ACM/ICPC 亚洲区 杭州站的更多相关文章
- 2016 ACM/ICPC亚洲区青岛站现场赛(部分题解)
摘要 本文主要列举并求解了2016 ACM/ICPC亚洲区青岛站现场赛的部分真题,着重介绍了各个题目的解题思路,结合详细的AC代码,意在熟悉青岛赛区的出题策略,以备战2018青岛站现场赛. HDU 5 ...
- 2016 ACM/ICPC亚洲区大连站-重现赛 解题报告
任意门:http://acm.hdu.edu.cn/showproblem.php?pid=5979 按AC顺序: I - Convex Time limit 1000 ms Memory li ...
- 2016 ACM/ICPC亚洲区大连站 F - Detachment 【维护前缀积、前缀和、二分搜索优化】
F - Detachment In a highly developed alien society, the habitats are almost infinite dimensional spa ...
- 2012 ACM/ICPC 亚洲区 金华站
题目链接 2012金华区域赛 Problem A 按a/b从小到大的顺序排队进行体检即可 #include<iostream> #include<cstdio> #inclu ...
- 2016 ACM/ICPC亚洲区青岛站
A B C D E F G H I J K L M O O O O $\varnothing$ $\varnothing$ $\varnothing$ $\varnothing$ ...
- 2016 ACM/ICPC亚洲区沈阳站
A B C D E F G H I J K L M O O O $\varnothing$ $\varnothing$ $\varnothing$ $\varnothing$ $\varnothi ...
- (HDU 5558) 2015ACM/ICPC亚洲区合肥站---Alice's Classified Message(后缀数组)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5558 Problem Description Alice wants to send a classi ...
- 2013ACM/ICPC亚洲区南京站现场赛---Poor Warehouse Keeper(贪心)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4803 Problem Description Jenny is a warehouse keeper. ...
- HDU 5950 Recursive sequence 【递推+矩阵快速幂】 (2016ACM/ICPC亚洲区沈阳站)
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
随机推荐
- MIP启发式算法:Variable neighborhood search
*本文主要记录和分享学习到的知识,算不上原创. *参考文章见链接. 本文主要讲述启发式算法中的变邻域搜索(Variable neighborhood search).变邻域搜索的特色在于邻域结构的可变 ...
- JAVA 基础--开发环境Sublime Text 3 搭建
方法一 打开Sublime Text 3,依次点击Preference, Browse Packages,在打开的窗口中双击User文件夹,新建文件JavaC.sublime-build,用记事本打 ...
- loj2031 「SDOI2016」数字配对
跑最大费用最大流,注意到每次 spfa 出来的 cost 一定是越来越少的,啥时小于 \(0\) 了就停了吧. #include <iostream> #include <cstri ...
- luogu2754 星际转移问题
源向地球连 月球向汇连 每一天往下一天连 飞船上一天与这一天连 枚举答案 #include <iostream> #include <cstring> #include < ...
- BIT+DP
2018CCPC网络赛 J - YJJ's Salesman HDU - 6447 YJJ is a salesman who has traveled through western country ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it
链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...
- 关于 __int128
__int128 是 GCC 提供的扩展(extension),可以当作 128 位整数使用. 关于 __int128 和 __int128_t Normally, _t suffix means a ...
- volatile的用法
在再有人问你Java内存模型是什么,就把这篇文章发给他中我们曾经介绍过,Java语言为了解决并发编程中存在的原子性.可见性和有序性问题,提供了一系列和并发处理相关的关键字,比如synchronized ...
- P1023 税收与补贴问题 (模拟)
题目链接 Solution 比较恶心的模拟题(主要是难看懂题意其实) 题意戳这里 然后根据一些简单的数学常识,可以知道这是一个二次函数. 所以我们每次枚举一个值,然后判定政府给出的价格是否是顶点即可. ...
- Problem b(bzoj 2301)
Description 对于给出的n个询问,每次求有多少个数对(x,y),满足a≤x≤b,c≤y≤d,且gcd(x,y) = k,gcd(x,y)函数为x和y的最大公约数. Input 第一行一个整数 ...