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. 31-关键字:final

    final:最终的 1.可以用来修饰:类.方法.变量 2.具体的: 2.1 final 用来修饰一个类:此类不能被其他类所继承. * 比如:String类.System类.StringBuffer类 ...

  2. vue中模块局部刷新

    父组件: 一. 父组件中引入子组件           data中定义变量 二. 定义provide函数 三.写reload方法 需要刷新的那个子组件: 一.引入                   ...

  3. R入门-图表

    画直方图:hist(x$x1)  //参数为向量,x为表图 画散点图:plot(x1,x2) // plot(x$x1,x$x2) // 列联表分析: 列联函数table() // table(x$x ...

  4. 自身写Android组合多个布局的经历

    今天不总结课程了,留着有时间补上. 今天的是ExpandListView,就是可以扩展的列表视图. 今天我做了个总结,然后模仿了扣扣的聊天界面,仅仅写了三个页面而已,用到的xml和活动就不下于10个, ...

  5. 她娇羞道“不用这样细致认真的说啊~~”———详细图解在Linux环境中创建运行C程序

    她娇羞说,不用这样细致认真的说啊———详细图解在Linux环境中创建运行C程序“不,这是对学习的负责”我认真说到 叮叮叮,停车,让我们看看如何在Linux虚拟机环境中,创建运行C程序 详细图解在Lin ...

  6. Qt编译出现cc1plus.exe: out of memory allocating 65536 bytes问题

    今天编译Qt程序,出现这个问题: cc1plus.exe: out of memory allocating 65536 bytes 这个还没有遇到过,上网查了下.问题原因是资源文件过大. qt的资源 ...

  7. 微信公众号怎么添加附件?比如word文档,pdf文件等

    微信公众号怎么添加附件?比如word文档,pdf文件等   我们都知道创建一个微信公众号,在公众号中发布一些文章是非常简单的,但公众号添加附件下载的功能却被限制,如今可以使用小程序“微附件”进行在公众 ...

  8. 解决drf_yasg中的SwaggerAPI无法正确分组问题

    swagger是后台开发中很好用的交互式文档,Django原本的Django-Swagger已经停止维护了,现在一般用drf_yasg这个包来实现文档,它里面支持swagger和redoc两种,red ...

  9. Ubuntu用户都应该了解的快捷键

    无论我们使用什么操作系统还是什么软件,快捷键都是非常有用的,因为可以在启动应用程序或跳转到所需窗口,可以快速进行很多操作,而无需动鼠标到处点,节省时间和精力,提高效率. 就像在Windows中一样,U ...

  10. Java—面向对象、类与对象、封装

    理解什么是面向过程.面向对象 面向过程与面向对象都是我们编程中,编写程序的一种思维方式. 面向过程的程序设计方式,是遇到一件事时,思考“我该怎么做”,然后一步步实现的过程. 面向对象的程序设计方式,是 ...