A. Drinks Choosing

有 $n$ 个人,每个人各有一种最喜欢的饮料,但是买饮料的时候只能同一种的两个两个买(两个一对)

学校只打算卖 $\left \lceil \frac{n}{2} \right \rceil$ 对

这意味着有些学生喝不到最喜欢的饮料,求最多有多少学生能喝的最喜欢的饮料

人数和饮料种数均小于等于 $1000$

直接贪心,对于喜欢同一种饮料的学生中,如果人数为奇数,要么单独买一对,然后把另一个给不喜欢这种饮料的人

要么喝自己不喜欢的饮料,设喜欢某种饮料的学生人数为奇数的饮料种数为 $x$,那么显然答案就是 $\left \lfloor \frac{x}{2} \right \rfloor$

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ldb;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e5+;
int n,k,a[N],cnt[N],ans;
int main()
{
n=read(),k=read();
for(int i=;i<=n;i++) a[i]=read(),cnt[a[i]]++;
for(int i=;i<=k;i++)
if(cnt[i]&) ans++;
printf("%d\n",n-ans/);
}

A. Drinks Choosing

B. Sport Mafia

有个人,进行了 $n$ 此操作,每次操作分为两种,放一些糖到盒子里,并且放的数量比上一次多 $1$,或者如果盒子有糖也可以选择从盒子里拿一个糖吃掉

第一次操作固定是往盒子里放一个糖,已知操作次数 $n$ 和最后剩下的糖的数量 $k$

求 $ta$ 吃的糖数量,保证有解

直接设进行了 $x$ 次 $1$ 操作,那么剩下的操作都是吃糖,所以可以列出方程

$x(x+1)/2=k+(n-x)$

解一下方程答案的公式就出来了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ldb;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
ll n,k;
int main()
{
n=read(),k=read();
// p*(p+1)/2=k+n-p
// p^2+p=2k+2n-2p
// p^2+3p-(2k+2n)=0
// 9+8(n+k)
// (-3+sqrt(8(n+k)+9))/2
ll p=(sqrt((n+k)*+)-)/;
printf("%lld\n",p*(p+)/-k);
return ;
}

B. Sport Mafia

C. Basketball Exercise

两排长度为 $n$ 的数 $A,B$,从左到右每次可以选择 $A,B$ 中的一个或者不选,对于同一排不能选择相邻的数,求能得到的最大值

显然设 $F[i][0/1]$ 表示从左到右选到第 $i$ 个位置,当前位置选择的数是 $A/B$,转移显然,具体看代码

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef long long ll;
typedef long double ldb;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e6+;
int n,a[N][];
ll f[N][];
int main()
{
n=read();
for(int i=;i<=n;i++) a[i][]=read();
for(int i=;i<=n;i++) a[i][]=read();
f[][]=a[][]; f[][]=a[][];
for(int i=;i<=n;i++)
{
f[i][]=max(f[i-][]+a[i][],f[i-][]);
f[i][]=max(f[i-][]+a[i][],f[i-][]);
}
printf("%lld\n",max(f[n][],f[n][]));
return ;
}
 
 
 
 

C. Basketball Exercise

D1. Submarine in the Rybinsk Sea (easy edition)

对于两个数 $A,B$,它们从左到右每一位分别是 $A[1]A[2]...A[m],B[1]B[2]B[m]$

定义函数 $F(A,B)$ 表示把两个数错位插在一起的结果,即 $A[1]B[1]...A[m-1]B[m-1]A[m]B[m]$

(具体例子看原题面)

给定数列 $a[]$,求 $\sum_i\sum_jF(a[i],a[j])$,保证数列中每个数的长度相等

考虑每一个数对答案的贡献,发现当它(设为 $C$)被 $i$ 枚举到时的贡献总是 $C[1]0C[2]0C[3]0...C[m]0$,被 $j$ 枚举到时的贡献总是 $C[1]0C[2]...0C[m]$

显然被 $i,j$ 枚举到的次数都为 $n$,所以贡献可以一起算

具体操作起来写个函数把数转化一下就行了,我的写法要注意 $unsigned\ long\ long$

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef unsigned long long ll;
typedef long double ldb;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e6+,mo=;
ll n,a[N],f[],ans;
int p[];
ll F(ll x,int type)//把数转换成插入一堆0的结果
{
int len=; for(ll t=x;t;t/=) p[++len]=t%;
ll res=; for(int i=;i<=len;i++) res+=p[i]*f[i*+type];
return res%mo;
}
int main()
{
n=read();
for(int i=;i<=n;i++) a[i]=read();
f[]=; for(int i=;i<=;i++) f[i]=f[i-]*;
for(int i=;i<=n;i++)
ans=(ans+F(a[i],))%mo,ans=(ans+F(a[i],-))%mo;
printf("%lld\n",ans*n%mo);
return ;
}

D1. Submarine in the Rybinsk Sea (easy edition)

D2. Submarine in the Rybinsk Sea (hard edition)

题目同上,唯一的区别就是数列 $a[]$ 中每个数的长度不一定相等

同样考虑每个数的贡献,发现一个数 $C$ 被 $i$ 枚举到时的贡献只和此时被 $j$ 枚举到的数的长度有关,被 $j$ 枚举到时的贡献也同理

所以记录一下长度为 $k$ 的数有多少个,把相同的贡献一起计算就好了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef unsigned long long ll;
typedef long double ldb;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=1e6+,mo=;
ll n,a[N],f[],ans;
int p[],cnt[];
int Len(ll x) { int res=; while(x) res++,x/=; return res; }
ll F(ll x,int type,int num)
{
int len=; for(ll t=x;t;t/=) p[++len]=t%;
ll res=;
for(int i=;i<=min(len,num);i++) res+=p[i]*f[i*+type];
for(int i=num+;i<=len;i++) res+=p[i]*f[num+i];
// cout<<x<<" "<<num<<" "<<res<<endl;
return res%mo;
}
int main()
{
n=read();
for(int i=;i<=n;i++) a[i]=read();
f[]=; for(int i=;i<=;i++) f[i]=f[i-]*;
for(int i=;i<=n;i++) cnt[Len(a[i])]++;
for(int i=;i<=n;i++)
{
// cout<<a[i]<<endl;
// for(int j=1;j<=10;j++) F(a[i],0,j);
// for(int j=1;j<=10;j++) F(a[i],-1,j);
for(int j=;j<=;j++) ans=(ans+F(a[i],,j)*cnt[j]%mo)%mo;
for(int j=;j<=;j++) ans=(ans+F(a[i],-,j)*cnt[j]%mo)%mo;
}
printf("%lld\n",ans);
return ;
}

D2. Submarine in the Rybinsk Sea (hard edition)

E. OpenStreetMap

给一个 $n*m$ 的矩阵,求其中所有 $a*b$ 的子矩阵的元素最小值之和

$n,m<=1000$

和这一题同样的思路:[HAOI2007]理想的正方形

直接单调队列横着竖着扫一遍就好了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
typedef unsigned long long ll;
typedef long double ldb;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=;
int n,m,a,b,h[N][N];
int F[N][N],G[N][N],Q[N];
ll g[N*N],x,y,z,ans;
int main()
{
n=read(),m=read(),a=read(),b=read();
int tot=;
g[]=read(),x=read(),y=read(),z=read();
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
{
h[i][j]=g[tot];
tot++; g[tot]=(g[tot-]*x+y)%z;
}
for(int i=;i<=n;i++)
{
int L=,R=;
for(int j=;j<=m;j++)
{
while(L<=R&&Q[L]<=j-b ) L++;
while(L<=R&&h[i][j]<=h[i][Q[R]]) R--;
Q[++R]=j; F[i][j]=h[i][Q[L]];
// cout<<F[i][j]<<" ";
}
}
for(int j=;j<=m;j++)
{
int L=,R=;
for(int i=;i<=n;i++)
{
while(L<=R&&Q[L]<=i-a) L++;
while(L<=R&&F[i][j]<=F[Q[R]][j]) R--;
Q[++R]=i; G[i][j]=F[Q[L]][j];
// cout<<G[i][j]<<" ";
if(i>=a&&j>=b) ans+=G[i][j];
}
}
printf("%lld\n",ans);
return ;
}

E - OpenStreetMap

Codeforces Round #574 (Div. 2) A~E Solution的更多相关文章

  1. Codeforces Round #574 (Div. 2)——C. Basketball Exercise(简单DP)

    题目传送门 题意: 输入n,给出两组均为 n个数字的数组a和b,轮流从a和b数组中取出一个数字,要求严格按照当前所选数字的数组下标比上一个所选数字的数组下标更大,计算能够取出的数字加起来的总和最大能为 ...

  2. Codeforces Round #574 (Div. 2)题解

    比赛链接 传送门 A题 题意 \(n\)个人每个人都有自己喜欢喝的\(vechorka\)口味,现在给你\(\lceil n/2\rceil\)箱\(vechorka\),每箱有两瓶,问最多能有多少个 ...

  3. Codeforces Round #574 (Div. 2)

    目录 Contest Info Solutions A. Drinks Choosing B. Sport Mafia C. Basketball Exercise D1. Submarine in ...

  4. Codeforces Round #574 (Div. 2)补题

    A. Drinks Choosing 统计每种酒有多少人偏爱他们. ki 为每种酒的偏爱人数. 输出ans = (n + 1)/2 >  Σki / 2 ? (n + 1)/2 - Σki / ...

  5. Codeforces Round #574 (Div. 2) E.OpenStreetMap

    题目链接 题目的意思就是给你一个矩阵你要求给定子矩阵的最小值的和 单调队列扫两边即可 #include <bits/stdc++.h> #define ll long long #defi ...

  6. Codeforces Round #574 (Div. 2) E. OpenStreetMap 【单调队列】

    一.题目 OpenStreetMap 二.分析 对于二维空间找区间最小值,那么一维的很多好用的都无法用了,这里可以用单调队列进行查找. 先固定一个坐标,然后进行一维的单调队列操作,维护一个区间长度为$ ...

  7. Codeforces Round #574 (Div. 2) D2. Submarine in the Rybinsk Sea (hard edition) 【计算贡献】

    一.题目 D2. Submarine in the Rybinsk Sea (hard edition) 二.分析 相比于简单版本,它的复杂地方在于对于不同长度,可能对每个点的贡献可能是有差异的. 但 ...

  8. Codeforces Round #574 (Div. 2) D1. Submarine in the Rybinsk Sea (easy edition) 【计算贡献】

    一.题目 D1. Submarine in the Rybinsk Sea (easy edition) 二.分析 简单版本的话,因为给定的a的长度都是定的,那么我们就无需去考虑其他的,只用计算ai的 ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. R语言抽样的问题

    基本抽样函数sample sample(x,size,replace=F/T) x是数据集, size规定了从对象中抽出多少个数 replace 为F时候,表示每次​抽取后的数就不能在下一次被抽取:T ...

  2. 记一次在mac上源码编译curl,使其支持NSS的过程

    一.背景 在一次学习https原理的过程中,希望客户端指定特定的cipher suites来抓包分析SSL/TLS的握手过程,就想到了使用curl工具,而不是使用浏览器. 接下来使用man curl找 ...

  3. 模块(os模块)

    一.模块 一个python文件就是一个模块. 模块可分为: 1.标准模块:python自带的模块是标准模块,可以直接import进行使用的. eg:import json.import random. ...

  4. c# tcp 服务客户端

    session connection protobuf-net

  5. 【LeetCode】哈希表 hash_table(共88题)

    [1]Two Sum (2018年11月9日,k-sum专题,算法群衍生题) 给了一个数组 nums, 和一个 target 数字,要求返回一个下标的 pair, 使得这两个元素相加等于 target ...

  6. Vue 组件间的传值(通讯)

    组件之间的通讯分为三种 父给子传 子给父传 兄弟组件之间的通讯 1 父组件给子组件传值 子组件嵌套在父组件内部,父组件给子组件传递一个标识,在子组件内部用props接收,子组件在模板里可以通过{{}} ...

  7. Python操作cx_Oracle笔记

    参考文章: http://cx-oracle.readthedocs.io/en/latest/cursor.html # 创建数据库连接 ordb = Oracle.connect("{0 ...

  8. Python3及Pycharm安装

    1.首先去python官网下载相应版本的Python安装包.如下: 2.下载完成后解压,双击exe文件进行安装,看到如下界面:Install Now表示默认安装:Customize installat ...

  9. YottaChain主网全面上线预示商业应用的落地区块链云存储不一样的云

    Yottachain存储网12月24日平安夜全面启动,意味着全球首个可商用的区块链存储公链全面落地.对于数据存储来说,小到我们个人的照片文档,大到政企机构数据库资料,都是互联网生活中如影随形的标配. ...

  10. jquery常用用法

    1.$("prve + next" )                          选择紧接着在perve后的next元素2.$("#div1 > *&quo ...