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

  1. Codeforces Avito Code Challenge 2018 D. Bookshelves

    Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...

  2. Avito Cool Challenge 2018

    考挂了.. A - Definite Game 直接看代码吧. #include<cstdio> #include<cstring> #include<algorithm ...

  3. Avito Code Challenge 2018

    第一次打CF,很菜,A了三道水题,第四题好像是是数位DP,直接放弃了.rateing从初始的1500变成了1499,还是绿名,这就很尴尬.之后觉得后面的题目也没有想象的那么难(看通过人数)过两天吧剩下 ...

  4. Avito Cool Challenge 2018 自闭记

    A:n==2?2:1. #include<iostream> #include<cstdio> #include<cmath> #include<cstdli ...

  5. Avito Cool Challenge 2018 Solution

    A. Definite Game 签. #include <bits/stdc++.h> using namespace std; int main() { int a; while (s ...

  6. Avito Cool Challenge 2018 E. Missing Numbers 【枚举】

    传送门:http://codeforces.com/contest/1081/problem/E E. Missing Numbers time limit per test 2 seconds me ...

  7. Avito Cool Challenge 2018 C. Colorful Bricks 【排列组合】

    传送门:http://codeforces.com/contest/1081/problem/C C. Colorful Bricks time limit per test 2 seconds me ...

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

  9. Avito Cool Challenge 2018:D. Maximum Distance (最小生成树)

    题目链接 题意 : 给出一个联通图和一些特殊的点,现在定义cost(u,v)为一条从u到v的路径上面边权的最大值 , 定义dis(u,v) 为从u到v 路径上面cost 的最小值 然后求所有特殊点到其 ...

随机推荐

  1. thinkphp5开发的网站出现”No input file specified”(php版本5.6.27)

    thinkphp5开发的网站出现”No input file specified”(php版本5.6.27) 一.总结 一句话总结:搜索引擎一定要用google,比百度节约时间一万倍,google啊, ...

  2. CSS实现和选择器

    CSS实现和选择器 本课内容: 一.实现CSS四种方式 1,每个html标签中都有一个style样式属性,该属性的值就是css代码.(针对一个标签)2,使用style标签的方式. 一般都定义在head ...

  3. Mac下使用源码编译安装TensorFlow CPU版本

    1.安装必要的软件 1.1.安装JDK 8 (1)JDK 8 can be downloaded from Oracle's JDK Page: http://www.oracle.com/techn ...

  4. English trip -- Review Unit6 Time 时间

    It's at seven o'clock   整点   7点整 It's at half past seven  or  It's seven-thirty7点30 It's at seven fi ...

  5. Rspec: everyday-rspec实操。5:controller test(了解基础)

    第 5 章 控制器测试 5.1基础 rails generate rspec:controller home RSpec.describe HomeController, type: :control ...

  6. codeforces 55d//Beautiful numbers// Codeforces Beta Round #51

    题意:一个数能整除它所有的位上的数字(除了0),统计这样数的个数. 注意离散化,为了速度更快需存入数组查找. 不要每次memset,记录下已有的长度下符合条件的个数. 数位dp肯定是从高位到低位. 记 ...

  7. Leetcode 89

    回溯写到自闭:不想就删了: class Solution { public: vector<int> grayCode(int n) { vector<vector<int&g ...

  8. OAF页面集成条形码或者二维码

    OAF页面集成条形码 OAF生成条形码 OAF页面集成二维码跟这个类似,生成二维码需要以下jar包,zxing-core.jar, zxing-javase.jar,可自行去maven下载. 代码如下 ...

  9. ShardedJedis的使用

    假定有2个 redis 服务实例(A和B)在运行,在客户端进行 set 操作: set a0 xxx set a1 xxx set a2 xxx set a3 xxx 我们希望a0, a1, a2, ...

  10. Intel DAAL AI加速——神经网络

    # file: neural_net_dense_batch.py #================================================================= ...