题目链接: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. Android入门(四):链接接口组件和程序代码

    编写好layout中的接口组件之后,下一步就是编写控制接口组件的程序代码.上一章,我们使用了三种接口组件,在使用者输入性别和年龄之后点击“健康建议按钮”,程序会读取用户所填入的性别和年龄,然后显示判断 ...

  2. 单元测试地二蛋 先弄个两个原生模块1个原始的一个jq插件

    放羊测试测完了再测这两个瞎搞的下拉列表组建 看看从单元测试模块化的角度组建会写成啥样 1:ajax请求 简单文本     2:1个页面多个实例     3:复杂展示+自定义点击+自定义处理函数     ...

  3. ZeroMQ接口函数之 :zmq_send – 在一个socket上发送一个消息帧

    ZeroMQ 官方地址 :http://api.zeromq.org/4-1:zmq-send zmq_send(3)              ØMQ Manual - ØMQ/4.1.0 Name ...

  4. ffmpeg(2.6) rockplayer android 下编译 小记.

    最近因为一些需求,开始学习 ffmgeg 在android 上使用. 使用的环境: 1,VMware V8 虚似机 安装的 FedoraV18 系统.(下载地址,请baidu),虚似机,最好有20-3 ...

  5. 【PostgreSQL】PostGreSQL数据库,时间数据类型

    ---"17:10:13.236"time without time zone:时:分:秒.毫秒 ---"17:10:13.236+08"time with t ...

  6. Unity学习疑问记录之图片画质

    http://blog.csdn.net/candycat1992/article/details/22794773

  7. myBatis oracle 与mysql自增问题

    mysql <insert id="insert" parameterType="Person" useGeneratedKeys="true& ...

  8. virtualenv

    问题:python开发过程中,需要安装各类依赖 逐个安装依赖,操作复杂,并可能会出现版本不一致的问题 解决:virtualenv可以有效解决上述问题 使用方法: 安装: pip install vir ...

  9. Unity中使用WebView

    Unity中使用WebView @(设计) 需求,最近游戏中需要引入H5直播页面和更新比较频繁的赛事页面,需求包括:加密传参数.和Unity交互,在Unity框架下其实有几种方案: 内置函数Appli ...

  10. Codeforces554 C Kyoya and Colored Balls

    C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d ...