Google Code Jam 2010 Round 1B Problem B. Picking Up Chicks
Problem
A flock of chickens are running east along a straight, narrow road. Each one is running with its own constant speed. Whenever a chick catches up to the one in front of it, it has to slow down and follow at the speed of the other chick. You are in a mobile crane behind the flock, chasing the chicks towards the barn at the end of the road. The arm of the crane allows you to pick up any chick momentarily, let the chick behind it pass underneath and place the picked up chick back down. This operation takes no time and can only be performed on a pair of chicks that are immediately next to each other, even if 3 or more chicks are in a row, one after the other.
Given the initial locations (Xi) at time 0 and natural speeds (Vi) of the chicks, as well as the location of the barn (B), what is the minimum number of swaps you need to perform with your crane in order to have at least K of the N chicks arrive at the barn no later than time T?
You may think of the chicks as points moving along a line. Even if 3 or more chicks are at the same location, next to each other, picking up one of them will only let one of the other two pass through. Any swap is instantaneous, which means that you may perform multiple swaps at the same time, but each one will count as a separate swap.
Input
The first line of the input gives the number of test cases, C. C test cases follow. Each test case starts with 4 integers on a line -- N, K, B and T. The next line contains the Ndifferent integers Xi, in increasing order. The line after that contains the N integers Vi. All distances are in meters; all speeds are in meters per second; all times are in seconds.
Output
For each test case, output one line containing "Case #x: S", where x is the case number (starting from 1) and S is the smallest number of required swaps, or the word "IMPOSSIBLE".
Limits
1 ≤ C ≤ 100;
1 ≤ B ≤ 1,000,000,000;
1 ≤ T ≤ 1,000;
0 ≤ Xi < B;
1 ≤ Vi ≤ 100;
All the Xi's will be distinct and in increasing order.
Small dataset
1 ≤ N ≤ 10;
0 ≤ K ≤ min(3, N);
Large dataset
1 ≤ N ≤ 50;
0 ≤ K ≤ N;
Sample
Input |
Output |
3 |
Case #1: 0 |
Solution
vector<int>X;
vector<int>V;
vector<pair<int, int>>ck; int solve(int N, int K, int B, int T1)
{
int sw = ;
int slow = ;
for (int i = N - ; i >= ; i--) {
if (ck[i].first + T1 * ck[i].second >= B) {
K--;
sw += slow; if (!K)
break; } else {
slow++;
}
} if (K)
return -; return sw;
} int main()
{
freopen("in.in", "r", stdin);
if (WRITE_OUT_FILE)
freopen("out.out", "w", stdout); int T;
scanf("%d\n", &T);
if (!T) {
cerr << "Check input!" << endl;
exit();
} for (int t = ; t <= T; t++) {
if (WRITE_OUT_FILE)
cerr << "Solving: #" << t << " / " << T << endl; int N, K, B, T1;
scanf("%d %d %d %d\n", &N, &K, &B, &T1); X.clear();
V.clear();
ck.clear(); for (int i = ; i < N; i++) {
int x;
scanf("%d", &x); X.push_back(x);
} for (int i = ; i < N; i++) {
int v;
scanf("%d", &v); V.push_back(v);
} for (int i = ; i < N; i++) {
ck.push_back(pair<int, int>(X[i], V[i]));
} sort(ck.begin(), ck.end()); auto result = solve(N, K, B, T1); if (result >= ) {
printf("Case #%d: %d\n", t, result);
} else {
printf("Case #%d: IMPOSSIBLE\n", t);
} } fclose(stdin);
if (WRITE_OUT_FILE)
fclose(stdout); return ;
}
Google Code Jam 2010 Round 1B Problem B. Picking Up Chicks的更多相关文章
- Google Code Jam 2010 Round 1B Problem A. File Fix-it
https://code.google.com/codejam/contest/635101/dashboard#s=p0 Problem On Unix computers, data is s ...
- Google Code Jam 2010 Round 1C Problem A. Rope Intranet
Google Code Jam 2010 Round 1C Problem A. Rope Intranet https://code.google.com/codejam/contest/61910 ...
- Google Code Jam 2010 Round 1C Problem B. Load Testing
https://code.google.com/codejam/contest/619102/dashboard#s=p1&a=1 Problem Now that you have won ...
- Google Code Jam 2010 Round 1A Problem A. Rotate
https://code.google.com/codejam/contest/544101/dashboard#s=p0 Problem In the exciting game of Jo ...
- Google Code Jam 2016 Round 1B Problem C. Technobabble
题目链接:https://code.google.com/codejam/contest/11254486/dashboard#s=p2 大意是教授的学生每个人在纸条上写一个自己的topic,每个to ...
- Google Code Jam 2014 Round 1B Problem B
二进制数位DP,涉及到数字的按位与操作. 查看官方解题报告 #include <cstdio> #include <cstdlib> #include <cstring& ...
- dp - Google Code jam Qualification Round 2015 --- Problem B. Infinite House of Pancakes
Problem B. Infinite House of Pancakes Problem's Link: https://code.google.com/codejam/contest/6224 ...
- Google Code jam Qualification Round 2015 --- Problem A. Standing Ovation
Problem A. Standing Ovation Problem's Link: https://code.google.com/codejam/contest/6224486/dashbo ...
- Google Code Jam 2016 Round 1B B
题意:给出两个数字位数相同,分别中间有若干位不知道,用问号表示.现在要求补全这两个数字,使得差值的绝对值最小,多解则取第一个数字的值最小的,再多解就取第二个数字最小的. 分析: 类似数位dp,但是很多 ...
随机推荐
- String是引用类型
关于String为值类型还是引用类型的讨论一直没有平息,最近一直在研究性能方面的问题,今天再次将此问题进行一次明确.希望能给大家带来点帮助. 如果有错误请指出. 来看下面例子: //值类型 ; int ...
- outlook.office365.com传参
string m_html = string.Empty; m_html += "<script>"; m_html += string.Format("wi ...
- MyBatis3: There is no getter for property named 'code' in 'class java.lang.String'
mybatis3 : mysql文如下,传入参数为string类型时‘preCode’,运行报错为:There is no getter for property named 'preCode' i ...
- Android 调用浏览器和嵌入网页
Android App开发时由于布局相对麻烦,很多时候一个App通常是由html5和原生控件相结合而成.简单的网页应用可以直接内嵌html5页面即可,对于需要调用复杂的底层功能时则采用原生控件的方式进 ...
- Codebook model 视频抠像 xp sp3 + vs2005 + OpenCV 2.3.1
Codebook model 视频抠像 xp sp3 + vs2005 + OpenCV 2.3.1 源码及详细文档下载 svn checkout http://cvg02.googlecode.co ...
- CodeForces - 416A (判断大于小于等于 模拟题)
Guess a number! Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Sub ...
- Hadoop学习:
文件名称 格式 描述 hadoop-env.sh BaSh 脚本 记 录 脚 本 要 用 的 环 境 变 , 以 运 行Hadoop core-site.xml HadooP配XML Hadoop C ...
- Android之ExpandableListView
ExpandableListView可以用来表现多层级的listView,本文主要是ExpandableListView的一个简单实现 布局文件 <LinearLayout xmlns:andr ...
- SRAM的读写操作
自己写的SRAM的程序,主要在于实用性,适应工作的工程需要.使用芯片为: 芯片时序图为: 代码: /********************************Copyright********* ...
- Rational Rose2007(v7.0)下载地址、安装及激活详解教程(图)
http://blog.csdn.net/skl_tz/article/details/8925152 最近需要画uml图,之前用的是Rose 2003版的,由于好久没进去了,结果发现原来的激活又失效 ...