Avito Cool Challenge 2018
考挂了。。
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的更多相关文章
- Codeforces Avito Code Challenge 2018 D. Bookshelves
Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...
- Avito Cool Challenge 2018(div1+2)
A. Definite Game: 题意:输入N,输出最小的结果N-x,其中x不少N的因子. 思路:N=2时,输出2:其他情况输出1:因为N>2时,N-1不会是N的因子. #include< ...
- 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 的最小值 然后求所有特殊点到其 ...
随机推荐
- 【PHP】PHP初学者的学习线路
先来看下PHP初学者的学习线路: (1) 熟悉HTML/CSS/JS等网页基本元素,完成阶段可自行制作简单的网页,对元素属性相对熟悉. (2) 理解动态语言的概念和运做机制,熟悉基本的PHP语法. ( ...
- mysql 数据类型 目录
mysql 数据类型 mysql 整数类型 数值类型 tinyint mysql int 整数类型 解释显示宽度 和 存储宽度 mysql float 浮点型 mysql 日期类型 mysql 字符串 ...
- 为帝国cms模板添加站内搜索小教程
由于客户的需要,最近都在整帝国cms,很多东西还是不熟悉,特别是帝国cms模板,以前用的那些网站模板一般是保存在ftp文件中,而帝国cms模板是直接保存在数据库中,修改是在网站后台的模板管理,得慢慢适 ...
- Lodash入门介绍
原文额地址 http://www.w3cplus.com/javascript/lodash-intro.html 有多年开发经验的工程师,往往都会有自己的一套工具库,称为 utils.helper ...
- openstack 部署笔记--neutron控制节点
控制节点 配置neutron用户及服务 $ . admin-openrc $ openstack user create --domain default --password-prompt neut ...
- AngularJS 表达式 对象和数组
AngularJS 使用 表达式 把数据绑定到 HTML. AngularJS 表达式 AngularJS 表达式写在双大括号内:{{ expression }}. AngularJS 表达式把数据绑 ...
- Word Add-in 函数调用顺序
这个图表明的函数的调用顺序,主要代码如下: // MyAddin.cpp : Implementation of DLL Exports. // Note: Proxy/Stub Informatio ...
- OS X 下动态库的引用
foo.c #include <stdio.h> void foo(void) { printf("foo.\n"); } main.c #include <st ...
- Python 迭代器切片
函数itertools.islice() 正好适用于在迭代器和生成器上做切片操作 >>> def count(n): ... while True: ... yield n ... ...
- Linux基础命令---ziinfo
zipinfo 在不解压的情况下,获取zip压缩文件的的详细信息.zipinfo列出了ZIP档案中有关文件的技术信息,最常见的是在MS-DOS系统上.这些信息包括文件访问权限.加密状态.压缩类型.版本 ...