Avito Cool Challenge 2018(div1+2)
A. Definite Game:
题意:输入N,输出最小的结果N-x,其中x不少N的因子。
思路:N=2时,输出2;其他情况输出1;因为N>2时,N-1不会是N的因子。
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int a[maxn];
int main()
{
int N; cin>>N;
if(N==) puts("");
else puts("");
return ;
}
B. Farewell Party
题意:有N个人,有N中帽子,N个数,表示多少人与他的帽子不同。
思路:把问题转维有多少个人帽子和他相同,然后数字相同的分到同一组,而且人数是数字的倍数,因为同一组的还要均分。
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int a[maxn],ans[maxn],vis[maxn],cnt,num[maxn];
int main()
{
int N; cin>>N; bool F=true;
rep(i,,N) scanf("%d",&a[i]),a[i]=N-a[i];
rep(i,,N) num[a[i]]++;
rep(i,,N) if(num[i]%i!=) {F=false; break;}
rep(i,,N){
if(num[a[i]]%a[i]==) vis[a[i]]=++cnt;
ans[i]=vis[a[i]];
num[a[i]]--;
}
if(!F) puts("Impossible");
else {
puts("Possible");
rep(i,,N) printf("%d ",ans[i]);
}
return ;
}
C. Colorful Bricks
题意:有N个地板,有M种颜色,有K个地板与左边的不相同。
思路:数据量不难写出二维DP,方程为,dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*(M-1);(也可以用组合数来做,不过这个数据没必要想太多
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
const int Mod=;
int dp[maxn][maxn];
int main()
{
int N,M,K;
scanf("%d%d%d",&N,&M,&K);
dp[][]=M;
rep(i,,N) {
rep(j,,i-){
if(j==) dp[i][j]=dp[i-][j];
else dp[i][j]=(dp[i-][j]+1LL*dp[i-][j-]*(M-)%Mod)%Mod;
}
}
printf("%d\n",dp[N][K]);
return ;
}
D. Maximum Distance
题意:题意很搅,这里的距离表示最小的路径最大值,就是让你求一个最小生成树(满足路径最大值最小),在生成树上有K个关键点,你的任务是对于每个关键点,找离他最远的关键点,输出距离。
思路:K个点的虚树,是所有两两路径经过的边集并,我们求这个边集并的最大值就是结果,因为我们可以保证他过这条边。其他写法容易挂,具体为什么暂时不知道。(虚树可以换成并查集?)
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int maxn=;
int a[maxn],Laxt[maxn],Next[maxn],To[maxn],Len[maxn],cnt,ans;
struct in{
int u,v,len;
friend bool operator <(in a,in b){ return a.len<b.len; }
}s[maxn];
int in[maxn],fa[maxn][],dep[maxn],vis[maxn],times,fcy[maxn];
bool cmp(int x,int y) { return in[x]<in[y]; }
void add(int u,int v,int c) { Next[++cnt]=Laxt[u]; Laxt[u]=cnt; To[cnt]=v;Len[cnt]=c;}
void dfs(int u,int f)
{
in[u]=++times; fa[u][]=f; dep[u]=dep[f]+;
for(int i=Laxt[u];i;i=Next[i]){
if(To[i]!=f) fcy[To[i]]=Len[i],dfs(To[i],u);
}
}
int LCA(int u,int v)
{
if(dep[u]<dep[v]) swap(u,v);
for(int i=;i>=;i--) if(dep[fa[u][i]]>=dep[v]) u=fa[u][i];
if(u==v) return u;
for(int i=;i>=;i--) if(fa[u][i]!=fa[v][i]) u=fa[u][i],v=fa[v][i];
return fa[u][];
}
int ac[maxn];
int find(int x){
if(ac[x]!=x) return ac[x]=find(ac[x]); return x;
}
int main()
{
int N,M,K;
scanf("%d%d%d",&N,&M,&K);
rep(i,,K) scanf("%d",&a[i]);
rep(i,,M){
scanf("%d%d%d",&s[i].u,&s[i].v,&s[i].len);
}
sort(s+,s+M+);
rep(i,,N) ac[i]=i;
rep(i,,M){
int fau=find(s[i].u);
int fav=find(s[i].v);
if(fau!=fav) {
ac[fau]=fav;
add(s[i].u,s[i].v,s[i].len);
add(s[i].v,s[i].u,s[i].len);
}
}
dfs(,);
sort(a+,a+K+,cmp);
int tot=K;
rep(i,,K) a[++tot]=LCA(a[i-],a[i]);
sort(a+,a+tot+,cmp);
tot=unique(a+,a+tot+)-(a+);
rep(i,,tot) vis[a[i]]=; //得到关键点
rep(i,,tot){ //关键点之间连边得到新树
int u=a[i];
while(true){
if(u==a[]) break;
ans=max(fcy[u],ans); u=fa[u][];
if(vis[u]||u==) break;
}
}
rep(i,,K) printf("%d ",ans);
return ;
}
E. Missing Numbers
题意:一个偶数N的序列,我们给出了偶数位置的数,让你填补奇数位置的数,满足所有前缀和的完全平方数。
思路:因为都是完全平方数,注意到完全平方数的相邻差值递增,我们可以利用这个单调性来搜索,或者单调队列什么的。我是二分写的,好像有点丑。 过了就行。。。
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
using namespace std;
const int maxn=;
const ll inf=1e13;
ll p[maxn],a[maxn],b[maxn],ans[maxn],cnt,N; //
int main()
{
for(ll i=;;i++){
if(i*i>inf) break;
p[++cnt]=i*i;
}
bool F=true;
scanf("%lld",&N);
rep(i,,N/){
scanf("%lld",&a[i]);
}
if(!F) return puts("No"),;
ll BG=-1LL;
rep(i,,cnt){
ll pos=lower_bound(p+,p+cnt+,p[i]+a[])-p;
if(pos>=&&p[pos]==p[i]+a[]){
ans[]=p[pos]-a[];
ll kk=lower_bound(p+,p+cnt+,ans[])-p;
if(p[kk]==ans[]){ BG=pos; break;}
}
}
if(BG==-1LL) return puts("No"),;
ans[]=a[]; ll fcy=BG;
for(ll i=;i<=N/&&fcy<=cnt;i++){
while(fcy<=cnt){
ll pos=lower_bound(p+,p+cnt+,p[fcy]+a[i])-p;
if(pos>=BG+&&p[pos]==p[fcy]+a[i]){
ll tmp=p[pos]-a[i];
ll hhh=lower_bound(p+,p+cnt+,tmp)-p;
if(p[hhh]==tmp) {ans[i*]=a[i]; ans[i*-]=p[pos]-p[BG]-a[i]; BG=pos; fcy=BG; break;}
else fcy++;
}
else fcy++;
}
}
rep(i,,N) if(ans[i]<1LL||ans[i]>inf) return puts("No"),;
puts("Yes");
rep(i,,N) printf("%lld ",ans[i]);
return ;
}
Avito Cool Challenge 2018(div1+2)的更多相关文章
- Codeforces Avito Code Challenge 2018 D. Bookshelves
Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...
- Avito Cool Challenge 2018
考挂了.. A - Definite Game 直接看代码吧. #include<cstdio> #include<cstring> #include<algorithm ...
- Avito Code Challenge 2018
第一次打CF,很菜,A了三道水题,第四题好像是是数位DP,直接放弃了.rateing从初始的1500变成了1499,还是绿名,这就很尴尬.之后觉得后面的题目也没有想象的那么难(看通过人数)过两天吧剩下 ...
- Avito Cool Challenge 2018 自闭记
A:n==2?2:1. #include<iostream> #include<cstdio> #include<cmath> #include<cstdli ...
- Avito Cool Challenge 2018 Solution
A. Definite Game 签. #include <bits/stdc++.h> using namespace std; int main() { int a; while (s ...
- Avito Cool Challenge 2018 E. Missing Numbers 【枚举】
传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...
- Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】
传送门:http://codeforces.com/contest/1081/problem/C C. Colorful Bricks time limit per test 2 seconds me ...
- Avito Cool Challenge 2018 B. Farewell Party 【YY】
传送门:http://codeforces.com/contest/1081/problem/B B. Farewell Party time limit per test 1 second memo ...
- Avito Cool Challenge 2018:D. Maximum Distance (最小生成树)
题目链接 题意 : 给出一个联通图和一些特殊的点,现在定义cost(u,v)为一条从u到v的路径上面边权的最大值 , 定义dis(u,v) 为从u到v 路径上面cost 的最小值 然后求所有特殊点到其 ...
随机推荐
- Android蓝牙通信功能开发
1. 概述 Bluetooth 是几乎现在每部手机标准配备的功能,多用于耳机 mic 等设备与手机的连接,除此之外,还可以多部手机之间建立 bluetooth 通信,本文就通过 SDK 中带的一个聊天 ...
- 【转】cs231n学习笔记-CNN-目标检测、定位、分割
原文链接:http://blog.csdn.net/myarrow/article/details/51878004 1. 基本概念 1)CNN:Convolutional Neural Networ ...
- Codeforces D - High Load
D - High Load 因为要出口节点距离最小,所以除了根节点(根节点连接k个儿子)其他节点的儿子只能有一个,其他情况下的距离都比这个长,因为如果不是这样,那么根节点连接的子树数量就小与k,那么每 ...
- angular5 ng-bootstrap和ngx-bootstrap区别
https://angular.cn/resources ngx-bootstrap 安装: npm install ngx-bootstrap --save 再引入css <link href ...
- HDU1789时间贪心
Doing Homework again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- xhost + 的作用
xhost 是用来控制X server访问权限的. 通常当你从hostA登陆到hostB上运行hostB上的应用程序时, 做为应用程序来说,hostA是client,但是作为图形来说, 是在hostA ...
- shell里的/dev/null 2>&1详解
shell中可能经常能看到: >/dev/null 2>&1 命令意思是:标准输出stdout 和标准错误输出stderr 也重定向到空设备文件,即不显示输出信息 分解这个组合:“ ...
- transition多个属性同时渐变(width,height,background)
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head> < ...
- OC 构造方法(对象初始化)
一.构造方法 (一)构造方法的调用 完整的创建一个可用的对象:Person *p=[Person new]; New方法的内部会分别调用两个方法来完成2件事情,1)使用alloc方法来分配存储空间(返 ...
- navicat安装步骤
Navicat安装