A:二分答案,从左往右考虑每个人,选尽量靠左的钥匙即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define int long long
#define N 2010
#define M 2010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,p,a[N],b[M];
bool flag[M];
bool check(int k)
{
memset(flag,0,sizeof(flag));
for (int i=1;i<=n;i++)
{
bool f=0;
for (int j=1;j<=m;j++)
if (!flag[j]&&abs(a[i]-b[j])+abs(p-b[j])<=k)
{
flag[j]=1;
f=1;
break;
}
if (!f) return 0;
}
return 1;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read(),p=read();
for (int i=1;i<=n;i++) a[i]=read();
for (int i=1;i<=m;i++) b[i]=read();
sort(a+1,a+n+1);sort(b+1,b+m+1);
int l=0,r=2000000000,ans=0;
while (l<=r)
{
int mid=l+r>>1;
if (check(mid)) ans=mid,r=mid-1;
else l=mid+1;
}
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}

  B:暴力,每次找到下一张被扔出去的牌并累加距离(即翻几张牌后会翻到)即可,距离用树状数组维护。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N],id[N],tree[N];
ll ans;
bool cmp(const int&x,const int&y)
{
return a[x]<a[y]||a[x]==a[y]&&x<y;
}
void add(int k,int x){while (k<=n) tree[k]+=x,k+=k&-k;}
int query(int k){int s=0;while (k) s+=tree[k],k-=k&-k;return s;}
int dis(int x,int y)
{
if (x<=y) return query(y)-query(x);
else return query(n)+query(y)-query(x);
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) id[i]=i,a[i]=read();
sort(id+1,id+n+1,cmp);
for (int i=1;i<=n;i++) add(i,1);
int last=0;
for (int i=1;i<=n;i++)
{
int t=i;
while (t<n&&a[id[t+1]]==a[id[i]]) t++;
int p=i;
for (int j=i+1;j<=t;j++) if (dis(last,id[j])<dis(last,id[p])) p=j;
ans+=dis(last,id[p]),add(id[p],-1),last=id[p];
for (int j=p+1;j<=t;j++)
ans+=dis(last,id[j]),add(id[j],-1),last=id[j];
for (int j=i;j<p;j++)
ans+=dis(last,id[j]),add(id[j],-1),last=id[j];
i=t;
}
cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}

  C:不考虑d是某数因子的特殊情况的话,相当于要求nd-Σai mod d<=k,最大化d。而ai mod d=ai-⌊ai/d⌋*d,众所周知⌊ai/d⌋只有sqrt(ai)种取值。在所有⌊ai/d⌋都不变的一段区间内,最大的d可以很容易的算出来。于是暴力找出所有区间分割点(包括每个数的因数,因为不满足上述式子),对分割点暴力验证,区间内直接算出最大取值判一下是否合法即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 110
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N],t;
ll k,d,b[10000010];
void print(ll x){cout<<x;exit(0);}
bool check(ll x)
{
ll s=0;
for (int i=1;i<=n;i++)
if (a[i]%x) s+=x-a[i]%x;
return s<=k;
}
ll check(ll l,ll r)
{
if (l>r) return -1;
ll s=n,tot=0;
for (int i=1;i<=n;i++) s+=a[i]/l,tot+=a[i];
tot+=k;
if (tot/s>=l) return min(tot/s,r);
else return -1;
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
cin>>n>>k;
for (int i=1;i<=n;i++) cin>>a[i];
for (int i=1;i<=n;i++)
{
for (int j=1;j*j<=a[i];j++)
if (a[i]%j==0)
{
b[++t]=j;
if (j*j<a[i]) b[++t]=a[i]/j;
}
for (int j=1;j<=a[i];j++)
{
b[++t]=j;
j=a[i]/(a[i]/j);
}
}
sort(b+1,b+t+1);
t=unique(b+1,b+t+1)-b-1;b[++t]=1000000000000ll;
for (int i=t;i>=2;i--)
{
if (check(b[i])) print(b[i]);
if (check(b[i-1]+1,b[i]-1)>0) print(check(b[i-1]+1,b[i]-1));
}
cout<<1;
return 0;
//NOTICE LONG LONG!!!!!
}

  D:容易想到设f[i]为i层满二叉树的答案,由f[i-1]转移。但考虑一下容易发现无法处理由某子树走到根再走回该子树的情况。这个转移需要知道选两条不相交路径的方案数。要求出这个似乎又要知道选更多条不相交路径的方案数。

  那么自然的有设f[i][j]为i层满二叉树无序选j条不相交路径的方案数。看起来第二维状态是指数级别的,不过先不管这个。

  考虑转移。显然其中至多只有一条路径经过根。

  如果没有路径经过根,方案数为Σf[i-1][x]*f[i-1][j-x]。

  如果根是一个孤立路径,方案数为Σf[i-1][x]*f[i-1][j-x-1]。

  如果根是路径端点,方案数为Σf[i-1][x]*f[i-1][j-x]*2*j。

  如果根是由某子树走上去再走下来的,方案数为f[i-1][x]*f[i-1][j-x+1]*2*C(j+1,2)。

  和最开始的想法相同,求f[i][j]至多只会用到f[i-1][j+1]。最终我们要求f[n][1],我们中间需要用到的第二维状态并不会超过n。于是状态数n2,复杂度O(n3)。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 410
#define P 1000000007
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,f[N][N];
void inc(int &x,int y){x+=y;if (x>=P) x-=P;}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
f[1][0]=1;f[1][1]=1;
for (int i=2;i<=n;i++)
for (int j=0;j<=n;j++)
for (int x=0;x<=j+1;x++)
{
if (j>=x) inc(f[i][j],1ll*(2*j+1)*f[i-1][x]%P*f[i-1][j-x]%P%P);
if (j>x) inc(f[i][j],1ll*f[i-1][x]*f[i-1][j-x-1]%P);
inc(f[i][j],1ll*f[i-1][x]*f[i-1][j-x+1]%P*(j+1)%P*j%P);
}
cout<<f[n][1];
return 0;
//NOTICE LONG LONG!!!!!
}

  

Codeforces Round #424 Div. 1的更多相关文章

  1. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)

    http://codeforces.com/contest/831 A. Unimodal Array time limit per test 1 second memory limit per te ...

  2. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals)A,B,C

    A:链接:http://codeforces.com/contest/831/problem/A 解题思路: 从前往后分别统计递增,相等,递减序列的长度,如果最后长度和原序列长度相等那么就输出yes: ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem F (Codeforces 831F) - 数论 - 暴力

    题目传送门 传送门I 传送门II 传送门III 题目大意 求一个满足$d\sum_{i = 1}^{n} \left \lceil \frac{a_i}{d} \right \rceil - \sum ...

  4. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  5. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 831E) - 线段树 - 树状数组

    Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this int ...

  6. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 831C) - 暴力 - 二分法

    Polycarp watched TV-show where k jury members one by one rated a participant by adding him a certain ...

  7. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem A - B

    Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is cons ...

  8. 【Codeforces Round #424 (Div. 2) A】Unimodal Array

    [Link]:http://codeforces.com/contest/831/problem/A [Description] 让你判断一个数列是不是这样一个数列: 一开始是严格上升 然后开始全都是 ...

  9. 【Codeforces Round #424 (Div. 2) B】Keyboard Layouts

    [Link]:http://codeforces.com/contest/831/problem/B [Description] 两个键盘的字母的位置不一样; 数字键的位置一样; 告诉你第一个键盘按某 ...

  10. 【Codeforces Round #424 (Div. 2) C】Jury Marks

    [Link]:http://codeforces.com/contest/831/problem/C [Description] 有一个人参加一个比赛; 他一开始有一个初始分数x; 有k个评委要依次对 ...

随机推荐

  1. My ajaxwrapper tool

    Until recently, when I write ajax call, always write like below: $.ajax({ type: "post", da ...

  2. iOS开发简记(9):APPStore审核

    "觅知音"这个APP的第一个版本从提交审核到上架,历时三个星期,其中遇到一些审核上的问题,它的处理或许能帮助到遇到同样问题的小伙伴们,所以这里列举出来,这三个星期如何跟苹果的审核团 ...

  3. Java基础之数据比较Integer、Short、int、short

    基础很重要,基础很重要,基础很重要.重要的事情说三遍,. 今天聊一聊Java的数据比较,这个范围比较大,基础类型的比较.引用类型的比较. 前提: 1.Java和c#都提供自动装箱和自动拆箱操作,何为自 ...

  4. Filebeat简介

    原文地址:http://blog.51cto.com/seekerwolf/2110174 收集日志的目的是有效的利用日志,有效利用日志的前提是日志经过格式化符合我们的要求,这样才能真正的高效利用收集 ...

  5. 爬虫(二)之scrapy框架

    01-scrapy介绍 02-项目的目录结构: scrapy.cfg 项目的主配置信息.(真正爬虫相关的配置信息在settings.py 文件中) items.py 设置数据存储模板,用于结构化数据, ...

  6. UITableView加载数据,没有数据,没有网络界面处理

    https://blog.csdn.net/chmod_r_755/article/details/53231461 俗话说的好,傻逼的APP都是相似的,牛逼的APP各有各的牛逼...但是UITabl ...

  7. Python之列表

    一.列表的特点 列表也是一种数据类型 列表元素是有序的,有编号的 列表元素的下标从0开始 列表中的每一个值叫一个元素,编号叫下标(索引/角标): stu_name=['崔海龙','杨帆','lrx', ...

  8. centos安装bundle文件

    centos安装VMware-Workstation-Full-*.bundle那点事 | 鳗鱼是条狗https://kinggoo.com/centos-vmware.htm Linux 下 VMW ...

  9. C#设计模式之1:策略模式

    首先需要说明的是该系列的所有内容都是基于headfirst设计模式来描述的.因为我之前也看过不少关于设计模式的书,还是发现这本最好,因为这本书里面给出的例子是最贴切实际的.不说了,开始这个系列吧! 策 ...

  10. jvm 虚拟机内存模型

    来源:https://blog.csdn.net/A_zhenzhen/article/details/77917991?locationNum=8&fps=1    https://blog ...