2016 ccpc 网络选拔赛 F. Robots
Robots
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 60 Accepted Submission(s): 13
Each robots can move K times. In one move,a robot at (x,y) can move to (x−1,y),(x,y+1),(x+1,y),(x,y−1).
After exactly K moves, she wants robots with same color to gather at the same postion and the robot on the i-th color gather at different postion with robots on (i-1)-th or (i+1)-th color.
Now she wants to know how many ways of moving these robots following to rules above.
Two ways are different if one of final postions of certain robot is different or there is at least one robot whose moving path is different.
The first line of each case contains three integer N(1≤N≤200),M(1≤M≤20),K(1≤K≤500), indicating the number of robots ,the number of color and the number of steps robots can move.
The second line,contains M integer mi, indicating the number of robots with the i-th color.
The robots numbered [1,m1] are on the 1st color.The robots numbered [m1+1,m1+m2] are one the 2nd color, ans so on.
The next N line,each contains two integers xi,yi, indicating the postion of i-th robots..
(0≤|xi,yi|≤250).
3 3 1
1 1 1
1 0
0 1
1 2
4 2 2
2 2
0 1
0 3
0 2
0 4
Case #2: 256
题意:
有n个机器人,共有m种颜色,分别分布在一个二维坐标平面上,每次移动可以向四联通的地方移动,多个机器人可以重合。
问所有机器人分别恰好走K步后,每种颜色的机器人聚集在一起,并且相邻两种颜色不聚集在一起的方案数。
题解:
一定不要读错题,这题只要求编号相邻的颜色的机器人不能聚集在一个点,于是难度锐减。
可以首先令坐标变化,x‘=x+y,y'=x-y。
如此,当(x,y)向四联通方格发生变化时,及变化量为(+-1,0)(0,+-1)时,(x',y')的变化为(+-1,+-1)。
无论原坐标如何改变,新坐标的两维都会发生改变。
在考虑到每个新坐标唯一确定了原坐标,这就给我们一个很好的性质:
新坐标两维可以分开考虑x'、y'无论如何分开分别变化K次,我们都可以在原坐标上解释这种变化,并且移动步数也为K。
可以如此,先令Gx[i][S]为第i种颜色的机器人的X坐标聚集在S的方案数,Gy[i][S]同理。
然后在令f[i]为前i种颜色的机器人合法的聚集的方案数,那么利用容斥就可以计算这个东西。
const int N = , M = , K = , SIZE = , MOD = 1e9 + ;
struct Point {
int x, y; inline void read() {
scanf("%d%d", &x, &y);
} inline void fix() {
int tx = x, ty = y;
x = tx + ty, y = tx - ty;
} inline int getCoor(int xy) const {
return xy ? y : x;
}
} arr[N];
int n, m, k, f[N];
int gather[][M][SIZE];
// coordinate -1500 ~ 1500
// real coordinate should be : i - 1501
// Size is SIZE
// 0 -> xcoordinate 1 -> y-coordinate
int dp[N], allAt[][SIZE]; inline int add(int x, int y) {
return (x + 0ll + MOD + 0ll + y) % MOD;
} inline int mul(int x, int y) {
return ((x * 1ll * y) % MOD + MOD) % MOD;
} int C[K][K];
inline void init() {
for(int i = ; i < K; ++i) C[i][] = ;
for(int i = ; i < K; ++i)
for(int j = ; j <= i; ++j)
C[i][j] = add(C[i - ][j - ], C[i - ][j]);
} inline int move(int st, int ed) {
int delta = abs(ed - st);
int freeMove = k - delta;
if(freeMove < || (freeMove & )) return ;
return C[k][freeMove / ];
} inline void solve() {
for(int i = ; i < m; ++i) f[i] += f[i - ];
for(int i = ; i < n; ++i) arr[i].fix(); for(int xy = ; xy < ; ++xy)
for(int i = ; i < m; ++i)
for(int w = ; w < SIZE; ++w) {
gather[xy][i][w] = ;
for(int j = i ? f[i - ] : ; j < f[i]; ++j)
gather[xy][i][w] = mul(gather[xy][i][w],
move(w - , arr[j].getCoor(xy)));
} for(int i = ; i < m; ++i) {
dp[i] = ; for(int xy = ; xy < ; ++xy)
for(int w = ; w < SIZE; ++w) allAt[xy][w] = ;
for(int j = i, coe = ; j >= ; --j, coe *= -) {
int allGather[] = {, };
for(int xy = ; xy < ; ++xy)
for(int w = ; w < SIZE; ++w) {
allAt[xy][w] = mul(allAt[xy][w], gather[xy][j][w]);
allGather[xy] = add(allGather[xy], allAt[xy][w]);
} int combine = mul(allGather[], allGather[]);
dp[i] = add(dp[i], mul(mul(coe, j ? dp[j - ] : ), combine));
}
} printf("%d\n", dp[m - ]);
} int main() {
freopen("f.in", "r", stdin);
init();
int testCase;
scanf("%d", &testCase);
for(int testIndex = ; testIndex <= testCase; ++testIndex) {
printf("Case #%d: ", testIndex);
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i < m; ++i) scanf("%d", &f[i]);
for(int i = ; i < n; ++i) arr[i].read();
solve();
}
return ;
}
2016 ccpc 网络选拔赛 F. Robots的更多相关文章
- 2016 CCPC网络选拔赛 部分题解
HDU 5832 - A water problem 题意:有两颗星球,一年的长度分别为37天和173天.问第n天时它们是否为新年的第一天. 思路:显然 n 同时被37和173整除时,两种历法都在新 ...
- HDU 5898 odd-even number(2016沈阳网络选拔赛 数位DP)
定义DP[pos][pre][odd][even],pos代表当前数位,pre代表前一位的数值,odd代表到前一位连续的奇数个数,even代表到前一位连续偶数个数. odd和even肯定至少有一个为0 ...
- hdoj6708 2019 CCPC网络选拔赛 1007 Windows Of CCPC
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; ch ...
- hdoj6703 2019 CCPC网络选拔赛 1002 array
题意 description You are given an array a1,a2,...,an(∀i∈[1,n],1≤ai≤n). Initially, each element of the ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 C. Magic boy Bi Luo with his excited tree
Magic boy Bi Luo with his excited tree Problem Description Bi Luo is a magic boy, he also has a migi ...
- 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛(8/11)
$$2019中国大学生程序设计竞赛(CCPC)\ -\ 网络选拔赛$$ \(A.\hat{} \& \hat{}\) 签到,只把AB都有的位给异或掉 //#pragma comment(lin ...
- [BFS,A*,k短路径] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 path (Problem - 6705)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6705 path Time Limit: 2000/2000 MS (Java/Others) Mem ...
- [贪心,dp] 2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛 Fishing Master (Problem - 6709)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=6709 Fishing Master Time Limit: 2000/1000 MS (Java/Othe ...
- 2016 CCPC 东北地区重现赛
1. 2016 CCPC 东北地区重现赛 2.总结:弱渣,只做出01.03.05水题 08 HDU5929 Basic Data Structure 模拟,双端队列 1.题意:模拟一个栈的操 ...
随机推荐
- asp.net mvc 通过T4模板生成框架
http://www.cnblogs.com/rdst/archive/2012/08/13/2637210.html http://www.kuqin.com/shuoit/20140716/341 ...
- Java创建对象的几种方法
有时候,也可能碰到这样面试题,如: Java创建对象有哪几种方法? 除了new之外,java创建对象还有哪几种方式? 本文结合例子,给出几种Java创建对象的方法,Here we go~~~~ 使用n ...
- (转)理解MySQL——索引与优化
参考资料:http://www.cnblogs.com/hustcat/archive/2009/10/28/1591648.html ———————————— 全文: 写在前面:索引对查询的速度有着 ...
- Node.js入门笔记(2):全局对象(1)
以下将以API文档为基础进行分析学习 global对象 这些对象在所有模块里都可用.有些对象不是在全局作用域而是在模块作用域里,这些情况下面文档都会标注出来. __filename--返回当前模块文件 ...
- Migrating an Existing Website from SQL Membership to ASP.NET Identity
Migrating an Existing Website from SQL Membership to ASP.NET Identity public class User : IdentityUs ...
- 大熊君大话NodeJS之------基于Connect中间件的小应用(Bigbear记事本应用之第一篇)
一,开篇分析 大家好哦,大熊君又来了,昨天因为有点个人的事没有写博客,今天又出来了一篇,这篇主要是写一个记事本的小应用,前面的文章, 我也介绍过“Connect”中间件的使用以及“Mongodb”的用 ...
- Pandas-数据选取
Pandas包对数据的常用数据切片功能 目录 [] where 布尔查找 isin query loc iloc ix map与lambda contains DataFrame的索引选取 [] 只能 ...
- win7提示“User Profile Service服务未能登录”
注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 最近,有个同事打电话告诉我说他的用户名无法登陆到系统,提示“User Profile Service服务未能登录,无法加载用户配置文 ...
- Windows操作技巧 之二(持续更新)
定时自动关机 shutdown -s -t 3600 shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f /m \\computer] ...
- Login Reference for PhotoSomething
Android Background Processing with Handlers and AsyncTask and Loaders - Tutorial http://www.vogella. ...