考挂了。。

A - Definite Game

直接看代码吧。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std; typedef long long ll;
const int Maxn=610000;
const int inf=0x7fffffff; int main() {
int x;
scanf("%d",&x);
if(x==2) puts("2");
else puts("1");
return 0;
}

B - Farewell Party

直接模拟分组即可。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std; typedef long long ll;
const int Maxn=610000;
const ll mod=998244353;
const int inf=0x7fffffff; int n,a[Maxn],b[Maxn],c[Maxn]; int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
b[i]=n-a[i];
}
sort(b+1,b+n+1);b[n+1]=-1;
int temp=1;
while(temp<=n) {
int cnt=1;
while(b[temp]==b[temp+1]) temp++,cnt++;
if(cnt%b[temp]) {
puts("Impossible");
return 0;
}
temp++;
}
int cnt=0;memset(b,0,sizeof(b));
for(int i=1;i<=n;i++) {
int x=n-a[i];
if(b[x]==0)
c[x]=a[i]=++cnt;
b[x]=(b[x]+1)%x;
a[i]=c[x];
}
puts("Possible");
for(int i=1;i<=n;i++) printf("%d ",a[i]);
return 0;
}

C - Colorful Bricks

可以n方DP,具体请参考代码。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std; typedef long long ll;
const int Maxn=610000;
const ll mod=998244353;
const int inf=0x7fffffff; int f[2100][2100],n,m,k; int main() {
scanf("%d%d%d",&n,&m,&k);
f[1][0]=m;
for(int i=1;i<n;i++)
for(int j=0;j<=k;j++) {
f[i+1][j]=(f[i+1][j]+f[i][j])%mod;
f[i+1][j+1]=(f[i+1][j+1]+1ll*f[i][j]*(m-1)%mod)%mod;
}
printf("%d",f[n][k]);
return 0;
}

D - Maximum Distance

先求最小生成树,然后拓扑排序,有标记的k个点不能删,最后的答案全部一样,就是剩下的边里面的最大值。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std; typedef long long ll;
const int Maxn=610000;
const ll mod=998244353;
const int inf=0x7fffffff; int to[Maxn],nxt[Maxn],first[Maxn],tot=1,f[Maxn];
int w[Maxn],n,m,b[Maxn],ans,k,bj[Maxn],d[Maxn];
queue<int> q; struct node {
int u,v,wi;
}a[Maxn]; int cmp(node a,node b) {
return a.wi<b.wi;
} int find(int x) {
if(f[x]!=x) f[x]=find(f[x]);
return f[x];
} inline void add(int u,int v,int wi) {
to[tot]=v;
w[tot]=wi;
nxt[tot]=first[u];
first[u]=tot++;
to[tot]=u;
w[tot]=wi;
nxt[tot]=first[v];
first[v]=tot++;
} void dfs(int root,int fa) {
for(int i=first[root];i;i=nxt[i]) if(to[i]!=fa&&bj[to[i]]!=-1) {
ans=max(ans,w[i]);
dfs(to[i],root);
}
} int main() {
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++) f[i]=i;
for(int i=1;i<=k;i++) scanf("%d",&b[i]),bj[b[i]]=1;
for(int i=1;i<=m;i++)
scanf("%d%d%d",&a[i].u,&a[i].v,&a[i].wi);
sort(a+1,a+m+1,cmp);
for(int i=1;i<=m;i++)
if(find(a[i].u)!=find(a[i].v)) {
add(a[i].u,a[i].v,a[i].wi);
f[f[a[i].u]]=f[a[i].v];
d[a[i].u]++;
d[a[i].v]++;
}
for(int i=1;i<=n;i++)
if(d[i]==1&&!bj[i])
q.push(i),bj[i]=-1;
while(!q.empty()) {
int now=q.front();q.pop();
for(int i=first[now];i;i=nxt[i]) {
d[to[i]]--;
if(d[to[i]]==1&&!bj[to[i]]) {
q.push(to[i]);
bj[to[i]]=-1;
}
}
}
dfs(b[1],b[1]);
for(int i=1;i<=k;i++) printf("%d ",ans);
return 0;
}

E - Missing Numbers

大概就是前几个数的和为完全平方数,而这个数当然越小越好,因为奇数位置可以随意指定,那么前面的和小,一定不会更劣。

然而我当时没开long long ,还过了pretest,所以就愉快地。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<cctype>
using namespace std; typedef long long ll;
const int Maxn=610000;
const ll mod=998244353;
const int inf=0x7fffffff; bool check(ll x) {
ll y=sqrt(x);
return y*y==x;
} int n;
ll a[Maxn],b[Maxn],tot; int main() {
scanf("%d",&n);
for(int i=1;i<=n/2;i++) scanf("%I64d",&a[i]);
ll temp=1;
while(!check(temp*temp+a[1])&&temp<1100000) temp++;
if(temp==1100000) {
puts("No");
return 0;
}
b[++tot]=temp*temp;b[++tot]=a[1];temp=sqrt(temp*temp+a[1]);
for(int i=2;i<=n/2;i++) {
if(temp==1100000) break;ll sxz=temp;temp++;
while(!check(temp*temp+a[i])&&temp<1100000) temp++;
b[++tot]=temp*temp-sxz*sxz;
b[++tot]=a[i];
temp=sqrt(temp*temp+a[i]);
}
if(temp==1100000) {
puts("No");
return 0;
}
puts("Yes");
for(int i=1;i<=n;i++) printf("%I64d ",b[i]);
return 0;
}

于是在打了三场之后,我的rating又回到了原点。。。

Avito Cool Challenge 2018的更多相关文章

  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(div1+2)

    A. Definite Game: 题意:输入N,输出最小的结果N-x,其中x不少N的因子. 思路:N=2时,输出2:其他情况输出1:因为N>2时,N-1不会是N的因子. #include< ...

  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. css 常用的属性

    box-shadow: 10px 10px 5px #000000;  //给元素添加阴影 使用伪元素after要注意加上content属性 例如:.log:after{ content:" ...

  2. Vue 数据绑定语法

    数据绑定语法 Vue.js 的模板是基于 DOM 实现的.这意味着所有的 Vue.js 模板都是可解析的有效的 HTML,且通过一些特殊的特性做了增强.Vue 模板因而从根本上不同于基于字符串的模板, ...

  3. 纯代码实现WordPress上传图片自动重命名的方法

    在我们使用 WordPress 发布文章时,经常都需要添加图片.多媒体什么的.然而,大家都知道 WordPress 是舶来物,对于中文用户来说,我们都会把图片命名为中文的,由于 WordPress 机 ...

  4. PAT Spell It Right [非常简单]

    1005 Spell It Right (20)(20 分) Given a non-negative integer N, your task is to compute the sum of al ...

  5. 转载人家写的CURSOR

    转自:http://blog.csdn.net/rdarda/article/details/7881648 1.游标的作用及属性 游标的作用就是用于对查询数据库所返回的记录进行遍历,以便进行相应的操 ...

  6. sql server中批量插入与更新两种解决方案分享(存储过程)

    转自http://www.shangxueba.com/jingyan/1940447.html 1.游标方式 SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONG ...

  7. STA分析(四) lib model

    library中的一个cell可以是一个standard cell,IO buffer,或者一个complex IP.其中包含area,functionality,timing,power等相关的信息 ...

  8. 排序的hashmap(guava)

    1.mvnrepository上搜索 guava.并引用其jar包 类似compile "com.google.guava:guava:18.0" 测试代码 Builder< ...

  9. hdu6000 Wash ccpc-20162017-finals B Wash

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6000 题目: Wash Time Limit: 20000/10000 MS (Java/Ot ...

  10. python 字符串的I/O 操作

    想使用操作类文件对象的程序来操作文本或二进制字符串 使用io.StringIO() 和io.BytesIO() 类来创建类文件对象操作字符串数据 >>> s = io.StringI ...