题目链接:https://code.google.com/codejam/contest/4224486/

Problem A. Mushroom Monster

这题题意就是,有N个时间点,每个时间点,Kaylin可以吃掉一定数量的mushroom,Bartholomew可以放入任意数量的mushroom。

现在给出N个时间点分别有多少mushroom。

问:若Kaylin每个时间点可以吃任意数量的mushroom,那为了配合每个时间点的mushroom,Kaylin最少要吃掉多少蘑菇。

问:若Kaylin已恒定速度吃mushroom(即在每个时间点间吃的数量相同,若盘子空了则暂停进食),那为了配合每个时间点的mushroom,Kaylin最少要吃掉多少蘑菇。

看懂题目就是水题,第一问,只要吃掉下一个时间点相对于当前时间点减少的mushroom数量。

第二问,只要保证吃的速度要大于等于所有时间点mushroom减少的数量,即取需求速度最大值。

代码:

 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <numeric>
#include <queue>
using namespace std; const int MAXN = ;
const int INF = 0x3f3f3f3f; int a[MAXN], maxr[MAXN];
int T, n; int solve1() {
int res = ;
for(int i = ; i < n - ; ++i)
res += max(, a[i] - a[i + ]);
return res;
} int solve2() {
int spd = ;
for(int i = ; i < n - ; ++i)
spd = max(spd, a[i] - a[i + ]);
int res = ;
for(int i = ; i < n - ; ++i)
res += min(a[i], spd);
return res;
} int main() {
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
scanf("%d", &T);
for(int t = ; t <= T; ++t) {
scanf("%d", &n);
for(int i = ; i < n; ++i)
scanf("%d", &a[i]);
maxr[n] = ;
for(int i = n - ; i >= ; --i)
maxr[i] = max(maxr[i + ], a[i]);
printf("Case #%d: %d %d\n", t, solve1(), solve2());
}
}

Problem B. Haircut

题目大意:已知有B个理发师,和B个理发师给任意一个人理发所需要的时间。现在有N个人在排队,若处于队首,会找当前不是正在理发的编号最小的理发师理发。

问:处于队列第N个的人会找第几个理发师。

思路:二分时间 time,计算在time个单位时间里,有sum人已经或正在理发,又有cnt个理发师恰好没有正在理发的人。

那么,若sum + cnt ≥ N,那么第N个人在前 time 个单位时间里,一定有机会开始理发。

如此二分可以得到第N个人开始理发的时间,再由上述的sum、cnt可以得到第N个人让第几个理发师理发。

代码:

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL; const int MAXN = ; int a[MAXN];
int T, n, b; bool check(LL k) {
LL sum = , cnt = ;
for(int i = ; i < b; ++i) {
cnt += (k % a[i] == );
sum += (k - ) / a[i] + ;
}
return sum + cnt >= n;
} int solve() {
LL l = , r = LL(n) * *max_element(a, a + b);//1000000;//
while(l < r) {
LL mid = (l + r) >> ;
if(!check(mid)) l = mid + ;
else r = mid;
}
LL sum = , p = ;
for(int i = ; i < b; ++i)
sum += (l - ) / a[i] + ;
for(int i = ; i < b; ++i)
if(l % a[i] == && sum + ++p == n) return i + ;
return -;
} int main() {
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
scanf("%d", &T);
for(int t = ; t <= T; ++t) {
scanf("%d%d", &b, &n);
for(int i = ; i < b; ++i)
scanf("%d", &a[i]);
printf("Case #%d: %d\n", t, solve());
}
}

Problem C. Logging

给N个点,分别问对于每个点来说,至少删掉多少个点,能使该点在剩下的点的凸包的边上。

思路1:因为凸包的边的性质是:对于一条边,每个点都在其同侧。那么,O(n^2)枚举所有边,O(n)枚举所有点,看要删掉那些点。复杂度O(n^3),可以跑过小数据,牛叉的电脑可以过大数据(RMB玩家与贫民玩家的区别就体现在这里了!)

代码:

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long LL; const int MAXN = ; struct Point {
int x, y, id;
Point() {}
Point(int x, int y): x(x), y(y) {}
void read(int i) {
id = i;
scanf("%d%d", &x, &y);
}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
bool operator < (const Point &rhs) const {
if(y != rhs.y) return y < rhs.y;
return x < rhs.x;
}
}; LL cross(const Point &a, const Point &b) {
return (LL)a.x * b.y - (LL)a.y * b.x;
}
//ret >= 0 means turn right
LL cross(const Point &op, const Point &sp, const Point &ed) {
return cross(sp - op, ed - op);
} Point p[MAXN];
int ans[MAXN];
int n, top, T; void update_min(int &a, int b) {
if(a > b) a = b;
} void solve() {
for(int i = ; i < n; ++i) for(int j = i + ; j < n; ++j) {
int lsum = , rsum = ;
for(int k = ; k < n; ++k) {
LL t = cross(p[i], p[j], p[k]);
if(t > ) lsum++;
if(t < ) rsum++;
}
update_min(ans[i], min(lsum, rsum));
update_min(ans[j], min(lsum, rsum));
}
} int main() {
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
scanf("%d", &T);
for(int t = ; t <= T; ++t) {
scanf("%d", &n);
for(int i = ; i < n; ++i)
p[i].read(i), ans[i] = n - ;
solve();
printf("Case #%d:\n", t);
for(int i = ; i < n; ++i)
printf("%d\n", ans[i]);
}
}

思路2:枚举每一个点,其他点绕枚举点排序,用一条过枚举点的直线旋转,计算要删掉的最少点。复杂度O(n^2logn)。

代码:

 #include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL; struct Point {
int x, y;
Point() {}
Point(int x, int y): x(x), y(y) {}
Point operator - (const Point &rhs) const {
return Point(x - rhs.x, y - rhs.y);
}
double ang() const {
return atan2(y, x);
}
bool type() const {
if(y != ) return y > ;
return x < ;
}
}; LL cross(const Point &a, const Point &b) {
return (LL)a.x * b.y - (LL)a.y * b.x;
} const int MAXN = ; Point p[MAXN], v[MAXN << ];
int n, T; bool cmp(const Point &a, const Point &b) {
if(a.type() != b.type()) return a.type() < b.type();
return cross(a, b) > ;
} void solve(int n) {
for(int i = ; i < n; ++i)
v[i - ] = p[i] - p[];
n--;
sort(v, v + n, cmp);
copy(v, v + n, v + n);
int res = ;
for(int i = , j = ; i < n; ++i) {
if(i == j) j++;
while(j < i + n && cross(v[i], v[j]) >= ) ++j;
res = max(res, j - i);
}
printf("%d\n", n - res);
} int main() {
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
scanf("%d", &T);
for(int t = ; t <= T; ++t) {
scanf("%d", &n);
for(int i = ; i < n; ++i)
scanf("%d%d", &p[i].x, &p[i].y);
printf("Case #%d:\n", t);
for(int i = ; i < n; ++i) {
swap(p[], p[i]);
solve(n);
swap(p[], p[i]);
}
}
}

Google Code Jam Round 1A 2015 解题报告的更多相关文章

  1. Google Code Jam Round 1A 2015 Problem B. Haircut 二分

    Problem You are waiting in a long line to get a haircut at a trendy barber shop. The shop has B barb ...

  2. Google Code Jam Round 1C 2015 Problem A. Brattleship

    Problem You're about to play a simplified "battleship" game with your little brother. The ...

  3. [Google Code Jam (Round 1A 2008) ] A. Minimum Scalar Product

    Problem A. Minimum Scalar Product   This contest is open for practice. You can try every problem as ...

  4. 【二分答案】Google Code Jam Round 1A 2018

    题意:有R个机器人,去买B件商品,有C个收银员,每个收银员有能处理的商品数量上限mi,处理单件商品所需的时间si,以及最后的装袋时间pi. 每个收银员最多只能对应一个机器人,每个机器人也最多只能对应一 ...

  5. 【贪心】Google Code Jam Round 1A 2018 Waffle Choppers

    题意:给你一个矩阵,有些点是黑的,让你横切h刀,纵切v刀,问你是否能让切出的所有子矩阵的黑点数量相等. 设黑点总数为sum,sum必须能整除(h+1),进而sum/(h+1)必须能整除(v+1). 先 ...

  6. [C++]Store Credit——Google Code Jam Qualification Round Africa 2010

    Google Code Jam Qualification Round Africa 2010 的第一题,很简单. Problem You receive a credit C at a local ...

  7. Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words

    Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...

  8. Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit

    Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit https://code.google.com/code ...

  9. 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 ...

随机推荐

  1. HDU5288 OO’s Sequence

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  2. Leetcode Valid Palindrome

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  3. Working in Singapore

    这篇blog主要是想说说最近以及将来一年的时间需要在Singapore工作的感受.你可能以及猜到了,我现在写这篇blog是在Singapore的Office里面. 在一个月之前还在成都工作,每天9:0 ...

  4. jQuery插件入门

    一:导言 有些WEB开发者,会引用一个JQuery类库,然后在网页上写一写("#"),("#"),("."),写了几年就对别人说非常熟悉JQ ...

  5. *HDU 2108 计算几何

    Shape of HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. tomcat配置https

    1.开启使用https协议 编辑tomcat目录下的conf/server.xml文件 <Connector port="443" protocol="HTTP/1 ...

  7. Select Option

    jQuery获取Select元素,并选择的Text和Value: 1. $("#select_id").change(function(){//code...}); //为Sele ...

  8. css 温故而知新 slideDown/slideUp 新思路

    默认设置高度为0; -webkit-transition:.3s all ease;transition:.3s all ease;opacity:0;height:0; 需要时添加高度即可 heig ...

  9. ajax跨域通过 Cors跨域资源共享 进行GetPost请求

    using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Ne ...

  10. SQL Server中事务、锁定和阻塞

    事务是什么 在SQL Server中事务是构成一个工作逻辑单元的一系列任务,也就说多个任务放在一起执行,这些任务要么全部执行成功,要么全部执行失败. 通过事务我们可以保证数据的完整性,例如:用户A给用 ...