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.题意:模拟一个栈的操 ...
随机推荐
- vijos1250 最勇敢的机器人
背景 Wind设计了很多机器人.但是它们都认为自己是最强的,于是,一场比赛开始了~ 描述 机器人们都想知道谁是最勇敢的,于是它们比赛搬运一些物品. 它们到了一个仓库,里面有n个物品,每个物品都有一个价 ...
- 【荐】JavaScript编码风格
作者:阮一峰 Douglas Crockford是 JavaScript 权威,Json 格式就是他的发明. 去年 11 月他有一个演讲(Youtube),谈到了好的 JavaScript 编程风格是 ...
- MySQL SQL优化
一.优化数据库的一般步骤: (A) 通过 show status 命令了解各种SQL的执行频率. (B) 定位执行效率较低的SQL语句,方法两种: 事后查询定位:慢查询日志:--log-slow-qu ...
- Uva 2319
理解:区域覆盖.假设该点在勘测半圆的边缘,求出与该点可在一个半圆的坐标范围l,r,然后,for 一次判断 #include<cstdio> #include<algorithm> ...
- python多线程学习记录
1.多线程的创建 import threading t = t.theading.Thread(target, args--) t.SetDeamon(True)//设置为守护进程 t.start() ...
- ToolStripMenuItem
MenuStrip 类 为窗体提供菜单系统. 继承层次结构 System.Object System.MarshalByRefObject System.ComponentModel.Comp ...
- WebStrom快捷键
WebStorm 是 JetBrains 推出的一款商业的 JavaScript 开发工具 任何一个编辑器都需要保存(ctrl + s),这是所有win平台上编辑类软件的特点,但是webstorm编辑 ...
- 【安装MongoDB】CentOS7 下安装NodeJs+Express+MongoDB+Redis
MongoDB,V3.2版本,官网说的很详细,见链接:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/ 1.创建 ...
- oracle中根据当前记录查询前一条和后一条记录
select * from aa01_2014 where aaa001=(select c.p from (select aaa001,lag(aaa001,1,0) over (order by ...
- s:select下拉框validation验证
S:select下拉框验证: <td colspan="5"> <s:select name="vo.typeVO.corp" list=&q ...