Google Kick Start Round G 2019
Google Kick Start Round G 2019
Book Reading
暴力,没啥好说的
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int n,m,q,p[maxn],r[maxn];
int cnt[maxn];
int main()
{
int T,Case=1;
scanf("%d",&T);
while(T--){
scanf("%d %d %d",&n,&m,&q);
for(int i=1;i<=n;i++)cnt[i]=0;
for(int i=1;i<=m;i++){
scanf("%d",&p[i]);
int ub=sqrt(p[i]);
for(int j=1;j<=ub;j++){
if(p[i]%j==0){
++cnt[j];
if(j*j!=p[i])++cnt[p[i]/j];
}
}
}
ll ans=0;
for(int i=1;i<=q;i++){
scanf("%d",&r[i]);
ans=ans+n/r[i]-cnt[r[i]];
}
printf("Case #%d: %lld\n",Case++,ans);
}
return 0;
}
The Equation
题意
给定数组A和整数M\((0 \leq A_i \leq 10^{15},0 \leq M \leq 10^{15})\),求使得\(\sum_{i=1}^n(A_i xor k) \leq M\)成立的k的最大值。
解题思路
从k的二进制高位开始贪心,尽可能的选1,选1的条件是目前为止的高位和,加上之后低位和的最小值小于\(M\)。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=70;
int n,cnt[N];
ll m,sum[N],s;
ll a[1005];
int main()
{
int T,Case=1;
scanf("%d",&T);
while(T--){
for(int i=0;i<=62;i++)cnt[i]=0;
s=0;
scanf("%d %lld",&n,&m);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]),s+=a[i];
for(int i=1;i<=n;i++)
for(int j=0;j<=62;j++)
if(a[i]&(1ll<<j))cnt[j]++;
for(int i=0;i<=62;i++){
if((1ll<<i)>2e15)break;
sum[i]=(i-1>=0?sum[i-1]:0)+(1ll<<i)*min(cnt[i],n-cnt[i]);
}
ll k=0,cur=0;
for(int i=62;i>=0;i--){
if((1ll<<i)>2e15)continue;
ll d=(n-cnt[i])*(1ll<<i);
if(cur+(i-1>=0?sum[i-1]:0)+d<=m){
k+=(1ll<<i);
cur+=(n-cnt[i])*(1ll<<i);
}
else{
cur+=cnt[i]*(1ll<<i);
}
}
if(k==0)k=(s<=m?0:-1);
printf("Case #%d: %lld\n",Case++,k);
}
return 0;
}
Shifts
题意
给定长度为\(n(n \leq 20)\)的数组A和B,对于每个下标\(i\),至少选取\(A_i\)和\(B_i\)中的一个,问有多少种选法使得选中的\(A_i\)的和以及\(B_i\)的和都大于给定整数\(h\)。
解题思路
将n等分为两份,分别dfs求出所有可能得到的和,问题就转化为了二维偏序,离散化后树状数组即可求解。复杂度\(O(3^{10}log3^{10})\)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
const int maxl=1e5+5;
int n,n1,n2;
ll h,ans;
int a[30],b[30];
struct node{ll x,y;int t;};
bool cmp(node p,node q){
if(p.x!=q.x)return p.x>q.x;
if(p.y!=q.y)return p.y>q.y;
return p.t<q.t;
}
node p[maxl<<1];
int cnt;
ll t[maxl<<2],m;
//BIT
ll c[maxl<<2];
ll lb(ll x){return x&(-x);}
void add(ll x,ll d){for(;x<m;x+=lb(x))c[x]+=d;}
ll getsum(ll x){ll r=0;for(;x;x-=lb(x))r+=c[x];return r;}
void dfs1(int x,ll sa,ll sb){
if(x==n1+1){
p[++cnt]=(node){sa,sb,0};
t[++m]=sa;t[++m]=sb;
return;
}
dfs1(x+1,sa+a[x],sb);
dfs1(x+1,sa,sb+b[x]);
dfs1(x+1,sa+a[x],sb+b[x]);
}
void dfs2(int x,ll sa,ll sb){
if(x==n+1){
p[++cnt]=(node){h-sa,h-sb-1,1};
t[++m]=h-sa;t[++m]=h-sb-1;
return;
}
dfs2(x+1,sa+a[x],sb);
dfs2(x+1,sa,sb+b[x]);
dfs2(x+1,sa+a[x],sb+b[x]);
}
int main()
{
//#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin);
//#endif
int T,Case=1;
scanf("%d",&T);
while(T--){
cnt=0; m=0; ans=0;
scanf("%d %lld",&n,&h);
n1=n/2; n2=n-n1;
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
for(int i=1;i<=n;++i)scanf("%d",&b[i]);
dfs1(1,0,0);
dfs2(n1+1,0,0);
sort(t+1,t+1+m);
m=unique(t+1,t+1+m)-(t+1);
vector<int>op;
ll count=0;
sort(p+1,p+1+cnt,cmp);
for(int i=1;i<=cnt;i++){
if(p[i].t){
int id=lower_bound(t+1,t+1+m,p[i].y)-t;
ans+=(count-getsum(id));
}
else{
int id=lower_bound(t+1,t+1+m,p[i].y)-t;
add(id,1);
op.push_back(id);
count++;
}
}
printf("Case #%d: %lld\n",Case++,ans);
for(int id:op)add(id,-1);
}
return 0;
}
Google Kick Start Round G 2019的更多相关文章
- Google Kick Start 2019 C轮 第一题 Wiggle Walk 题解
Google Kick Start 2019 C轮 第一题 Wiggle Walk 题解 题目地址:https://codingcompetitions.withgoogle.com/kickstar ...
- Google kickstart 2022 Round A题解
Speed Typing 题意概述 给出两个字符串I和P,问能否通过删除P中若干个字符得到I?如果能的话,需要删除字符的个数是多少? 数据规模 \[1≤|I|,|P|≤10^5 \] 双指针 设置两个 ...
- google Kickstart Round G 2017 三道题题解
A题:给定A,N,P,计算A的N!次幂对P取模的结果. 数据范围: T次测试,1 ≤ T ≤ 100 1<=A,N,P<=105 快速幂一下就好了.O(nlogn). AC代码: #inc ...
- Google Kick Start 2020 Round C
ac代码 A. Countdown for循环跑一跑,没啥好说的. B. Stable Wall 如果\(s_{i,j} \ne s_{i+1,j}\),那么说明\(s_{i+1,j}\)必须在\(s ...
- Google Kick Start 2020 Round B T4 Wandering Robot
题意 一个\(n \times m\)的矩形空间,起点是\((1,1)\),终点是\((n,m)\). 假设当前位于\((x,y)\): 如果当前位于最后一行,那么下一步只能走向\((x,y+1)\) ...
- Google Kick Start 2020 Round B T1-3
这场题目除了最后一题稍微难了点,其他都是1眼题. T1 Bike Tour 没啥好说的,一个循环解决. T2 Bus Routes 没啥好说的,从第\(n\)的车站开始贪心取最晚的. T3 Robot ...
- Google Code Jam Round 1A 2015 解题报告
题目链接:https://code.google.com/codejam/contest/4224486/ Problem A. Mushroom Monster 这题题意就是,有N个时间点,每个时间 ...
- 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树
G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...
- [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 ...
随机推荐
- Android 的重要控件 ListView (听说是最难最常用的控件)
这个打字有点慢了,左手受伤了,不过很幸运,左手小拇指没事(这就可以愉快地使用快捷键啦!),虽然有伤,但还是得坚持总结,不只是为自己,还为未来的你们铺路,希望我写的,对你们有帮助. 提前给自己一个祝福: ...
- C调用C++代码
有时C程序里需要用到C++的类,但是C语言又不能直接调用类,这时需要把C++的类使用C接口封装后,再调用, 可以将封装后的C++代码编译成库文件,供C语言调用: 需要注意的是,封装的C++代码库文件是 ...
- 家庭记账本APP开发准备(二)
今天学习了选项卡,为记账本的分类做了准备.主登录界面进行了优化,但仍未实现各个组件之间的跳转. 选项卡 activity_main.xml <?xml version="1.0&quo ...
- Android后台数据接口交互实现注册功能
首先,在ecplise里面新建一个叫做TestServices的web工程.在WebContent--WEB-INF--libs文件夹下导入两个jar包:mysql-connector-java-6. ...
- 仅需1秒!搞定100万行数据:超强Python数据分析利器
前言 使用Python进行大数据分析变得越来越流行.这一切都要从NumPy开始,它也是今天我们在推文介绍工具背后支持的模块之一. 2 Vaex Vaex是 一种更快.更安全.总体上更方便的方法,可以使 ...
- Hive: Reflect UDF
Reflect UDF JAVA类和方法通常用于处理用户希望在hive中使用的确切的函数.相比与封装一个UDF然后调用这个方法,这些 方法主要通过反射UDF去调用.Reflect使用Java反射去实例 ...
- 常哥带你认识NoSQL和Redis的强大
各位朋友,这篇文章是针对Redis快速了解的内容,为了学好Redis在这里首先跟大家聊聊NoSQL相关内容,有了概念和方向后,我们再学习Redis大家会感觉得心应手. [公众号dotNet工控上位机: ...
- Docker容器网络-实现篇
通常,Linux容器的网络是被隔离在它自己的Network Namespace中,其中就包括:网卡(Network Interface).回环设备(Loopback Device).路由表(Routi ...
- C#LeetCode刷题之#258-各位相加(Add Digits)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3860 访问. 给定一个非负整数 num,反复将各个位上的数字相加 ...
- C#LeetCode刷题之#448-找到所有数组中消失的数字(Find All Numbers Disappeared in an Array)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3712 访问. 给定一个范围在 1 ≤ a[i] ≤ n ( n ...