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,但是很多 ...
随机推荐
- django-cms 代码研究(七)杂七杂八
实体关系图 核心对象: cms_page/cms_placeholder/cms_cmsplugin. page模型类继承关系图 CMSPlugin&Placeholder模型类继承关系图 = ...
- NOIP 2011 Day 1 部分题解 (Prob#1 and Prob#2)
Problem 1: 铺地毯 乍一看吓cry,地毯覆盖...好像是2-dims 线段树,刚开头就这么难,再一看,只要求求出一个点,果断水题,模拟即可.(注意从标号大的往小的枚举,只要有一块地毯符合要求 ...
- dell idrac8 部署操作系统的方法
1,打开虚拟控制台 2,“虚拟介质”->“连接虚拟介质”->“映射虚拟介质到CD”->(选择要安装的镜像文件)->“Map device” 3, “next boot”-> ...
- 局域网所有机器都能连接MySQL数据库的设置命令
Sql代码: grant all privileges on *.* to root@"%" identified by 'abc' with grant option; flus ...
- ios7技巧:你需要掌握的19个iOS7使用技巧
从右往左滑动屏幕,可看到信息收到的时间. 指南针应用还可以用作水平仪,滑动屏幕即可. 被苹果称作Spotlight的搜索功能有所改变.在屏幕中间向下滑动即可打开该项功能,你可以搜索文本.邮件.应用.歌 ...
- 通过Java反射来理解泛型的本质
集合框架中经常会使用泛型指定集合中所存放元素的类型,保证集合的统一性,从集合中取出元素的时候也避免了类型强制转换的操作,所以我们使用常规的方式来往集合中存放元素的时候,如果指定泛型,那么我们只能向集合 ...
- java将白色背景图片转换成无色
package com.cxf.dao; import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.Buffer ...
- 原始套接字(SOCK_RAW)
本文转载:http://www.cnblogs.com/duzouzhe/archive/2009/06/19/1506699.html,在此感谢 原始套接字(SOCK_RAW). 应用原始套接字,我 ...
- navicat使用跳板机连接数据库-ssh
1. 目标数据库的域名/IP,端口,用户名,密码:如图1 2. 这时候不要点OK!选择SSH这个tab 3. 选中User SSH Tunnel:填写跳板机域名/IP,用户名,密码(注意:端口22不要 ...
- 查询MYSQL和查询HBASE速度比较
上一篇文章:我要上谷歌 Mysql,关系型数据库: HBase,NoSql数据库. 查询Mysql和查询HBase,到底哪个速度快呢? 与一些真正的大牛讨论时,他们说HBase写入速度,可以达到每秒1 ...