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 的最小值 然后求所有特殊点到其 ...
随机推荐
- 【深入理解javascript】原型
1.一切都是对象 一切(引用类型)都是对象,对象是属性的集合 typeof函数输出的一共有几种类型,在此列出: function show(x) { console.log(typeof(x)); / ...
- Spark2.x学习笔记:Spark SQL的SQL
Spark SQL所支持的SQL语法 select [distinct] [column names]|[wildcard] from tableName [join clause tableName ...
- [LeetCode] 821. Shortest Distance to a Character_Easy tag: BFS
Given a string S and a character C, return an array of integers representing the shortest distance f ...
- Jmeter接口测试自动化 (三)(数据驱动测试)
本文转载至http://www.cnblogs.com/chengtch/p/6105532.html 当我研究要通过用例优先级控制用例是否执行时,我发现了用"如果(if)控制器" ...
- PostgreSQL远程连接配置
postgresql默认情况下,远程访问不能成功,如果需要允许远程访问,需要修改两个配置文件,说明如下: 1.postgresql.conf 将该文件中的listen_addresses项值设定为“* ...
- Quick Look at the Air Jordan 32
A color with 25 years of history in the Air Jordan line will once again leave its mark on the Air Jo ...
- linux文件系统软链接硬链接
引子 目前,UNIX的文件系统有很多种实现,例如UFS(基于BSD的UNIX文件系统).ext3.ext4.ZFS和Reiserfs等等. 不论哪一种文件系统,总是需要存储数据.硬盘的最小存储单位是扇 ...
- Qt下QString转char*
Qt下面,字符串都用QString,确实给开发者提供了方便,想想VC里面定义的各种变量类型,而且函数参数类型五花八门,经常需要今年新那个类型转换 Qt再使用第三方开源库时,由于库的类型基本上都是标准的 ...
- js数组之可变函数
在js的数组中有两个方法为数组添加元素:1.push();2.unshift(),push函数是将元素添加到数组的末尾,现在不用说大家估计也能猜出来,unshift这个函数就是把元素添加到数组的开头的 ...
- 摘自(http://www.ruanyifeng.com/blog/2011/07/linux_load_average_explained.html)
理解Linux系统负荷 作者: 阮一峰 一.查看系统负荷 如果你的电脑很慢,你或许想查看一下,它的工作量是否太大了. 在Linux系统中,我们一般使用uptime命令查看(w命令和top命令也行) ...