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的更多相关文章

  1. Google Kick Start 2019 C轮 第一题 Wiggle Walk 题解

    Google Kick Start 2019 C轮 第一题 Wiggle Walk 题解 题目地址:https://codingcompetitions.withgoogle.com/kickstar ...

  2. Google kickstart 2022 Round A题解

    Speed Typing 题意概述 给出两个字符串I和P,问能否通过删除P中若干个字符得到I?如果能的话,需要删除字符的个数是多少? 数据规模 \[1≤|I|,|P|≤10^5 \] 双指针 设置两个 ...

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

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

  5. Google Kick Start 2020 Round B T4 Wandering Robot

    题意 一个\(n \times m\)的矩形空间,起点是\((1,1)\),终点是\((n,m)\). 假设当前位于\((x,y)\): 如果当前位于最后一行,那么下一步只能走向\((x,y+1)\) ...

  6. Google Kick Start 2020 Round B T1-3

    这场题目除了最后一题稍微难了点,其他都是1眼题. T1 Bike Tour 没啥好说的,一个循环解决. T2 Bus Routes 没啥好说的,从第\(n\)的车站开始贪心取最晚的. T3 Robot ...

  7. Google Code Jam Round 1A 2015 解题报告

    题目链接:https://code.google.com/codejam/contest/4224486/ Problem A. Mushroom Monster 这题题意就是,有N个时间点,每个时间 ...

  8. 8VC Venture Cup 2016 - Elimination Round G. Raffles 线段树

    G. Raffles 题目连接: http://www.codeforces.com/contest/626/problem/G Description Johnny is at a carnival ...

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

随机推荐

  1. Codechef May Challenge 2020 Division 1 记录

    目录 Triple Sort Sorting Vases Buying a New String Chef and Bitwise Product Binary Land Not a Real Wor ...

  2. 2020-06-07:mysql中varchar类型的id,where id=1,会用到索引吗?int 类型的id,where id="1",会用到索引吗?为什么?

    福哥答案2020-06-07: 答案来自群员:对于int类型id,查询的varchar 类型 ‘1’会隐式转换成 1,‘1’和 1都能正常走索引:对于varchar类型id,查询的int 类型 1不会 ...

  3. C#LeetCode刷题之#374-猜数字大小(Guess Number Higher or Lower)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3993 访问. 我们正在玩一个猜数字游戏. 游戏规则如下: 我从 ...

  4. 自己动手编写一个Mybatis插件:Mybatis脱敏插件

    1. 前言 在日常开发中,身份证号.手机号.卡号.客户号等个人信息都需要进行数据脱敏.否则容易造成个人隐私泄露,客户资料泄露,给不法分子可乘之机.但是数据脱敏不是把敏感信息隐藏起来,而是看起来像真的一 ...

  5. Mybatis-07-多对一和一对多处理

    多对一处理 如, 多个学生,对应一个老师 多个学生关联一个老师(多对一) 一个老师有很多学生(一对多) SQL: create table `teacher`( `id` int(10) not nu ...

  6. C++指针变量的基本写法

    指针变量与应用——动态数组 在C++中,有一种神奇的变量,它不可以表示一个值,但是可以表示某个元素的地址,通过地址来访问这个元素. 打个比方:你有一张地图和一个坐标,你就可以通过访问这个坐标来达到你访 ...

  7. Newbe.Claptrap 框架如何实现在多种框架之上运行?

    Newbe.Claptrap 框架如何实现在多种框架之上运行?最近整理了一下项目的术语表.今天就谈谈什么是 Claptrap Box. 特别感谢 kotone 为本文提供的校对建议! Newbe.Cl ...

  8. Flutter简介

    Flutter简介 Flutter 是 Google推出并开源的移动应用开发框架,主打跨平台.高保真.高性能.开发者可以通过 Dart语言开发 App,一套代码同时运行在 iOS 和 Android平 ...

  9. C#/VB.NET 比较两个Word文档差异

    本文以C#和VB.NET代码为例,来介绍如何对比两个Word文档差异.程序中使用最新版的Spire.Doc for .NET 版本8.8.2.编辑代码前,先在VS程序中添加引用Spire.Doc.dl ...

  10. extJS--尚

    ExtJS依赖JavaScript,JavaScript推荐两本书:<JavaScript高级程序设计>初阶阶段, <JavaScript设计模式>中级阶段 fun1();// ...