考挂了。。

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. C++三大特性之多态

    原文地址:https://qunxinghu.github.io/2016/09/08/C++%20%E4%B8%89%E5%A4%A7%E7%89%B9%E6%80%A7%E4%B9%8B%E5%A ...

  2. on条件与where条件的区别(转)

    add by zhj: 以为一直以为on和where是等价于,直到看到这篇文章,并亲自测试,才知道原来他们的功能不一样. 可以这样理解:on是在生成连接表的起作用的,where是生成连接表之后对连接表 ...

  3. 给sql server2005打补丁报错:无法安装Windows Installer MSP文件

    给sql server2005打补丁报错:无法安装Windows Installer MSP文件 在我们安装完SQL2005数据库后,需要安装SP4补丁时,会出错:无法安装Windows Instal ...

  4. mysql 数据操作 多表查询 子查询 带IN关键字的子查询

    1 带IN关键字的子查询 #查询平均年龄在25岁以上的部门名关键点部门名 以查询员工表的dep_id的结果 当作另外一条sql语句查询条件使用 in (sql语句) mysql ; +-------- ...

  5. 【深入理解javascript】原型

    1.一切都是对象 一切(引用类型)都是对象,对象是属性的集合 typeof函数输出的一共有几种类型,在此列出: function show(x) { console.log(typeof(x)); / ...

  6. Spark Core(四)用LogQuery的例子来说明Executor是如何运算RDD的算子(转载)

    1. 究竟是怎么运行的? 很多的博客里大量的讲了什么是RDD, Dependency, Shuffle.......但是究竟那些Executor是怎么运行你提交的代码段的? 下面是一个日志分析的例子, ...

  7. CloudFlare防护下的破绽:寻找真实IP的几条途径

    本文仅代表作者独立观点,本文提及的技术仅供安全研究和渗透测试用途 看Twitter发现CloudFlare总裁什么的最近很高调,北京.香港的跑着参加会议.发表演说什么的,CloudFlare似乎也没那 ...

  8. LeetCode--Two_Sum

    Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...

  9. java中Integer 和String 之间的转换

    java中Integer 和String 之间的转换 将数组转换成字符串:char[] array = {'a','b','c','d','e'};String str = new String(ar ...

  10. Javascript-逻辑判断或(&&)练习

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...