A. Definite Game

签.

 #include <bits/stdc++.h>
using namespace std; int main()
{
int a;
while (scanf("%d", &a) != EOF)
{
[](int x)
{
for (int i = x - ; i >= ; --i) if (x % i)
{
printf("%d\n", x - i);
return;
}
printf("%d\n", x);
}(a);
}
return ;
}

B. Farewell Party

签。

 #include <bits/stdc++.h>
using namespace std; #define N 100010
int n, a[N], b[N], cnt[N];
vector <int> v[N];
int ans[N]; bool ok()
{
for (int i = ; i <= n; ++i) if (!v[i].empty() && v[i].size() != i)
return false;
return true;
}
void solve()
{
int cnt = ;
for (int i = ; i <= n; ++i) v[i].clear();
for (int i = ; i <= n; ++i)
{
int id = n - a[i];
if (v[id].size() == id)
{
++cnt;
for (auto it : v[id]) ans[it] = cnt;
v[id].clear();
}
v[id].push_back(i);
}
if (!ok())
{
puts("Impossible");
return;
}
else
{
for (int i = ; i <= n; ++i) if (!v[i].empty())
{
++cnt;
for (auto it : v[i])
ans[it] = cnt;
}
puts("Possible");
for (int i = ; i <= n; ++i) printf("%d%c", ans[i], " \n"[i == n]);
}
} int main()
{
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; ++i) scanf("%d", a + i);
solve();
}
return ;
}

C. Colorful Bricks

Upsolved.

题意:

有$一行n个方格,m种颜色,恰好有k个方块与它左边方块的颜色不同$

求方案数

思路:

$dp[i][j] 表示到第i个方格,有j个方块与左边方块颜色不同的方案数$

转移有

$dp[i + 1][j] += dp[i][j]$

$dp[i + 1][j + 1] += dp[i][j] * (m - 1)$

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 2010
const ll MOD = (ll);
int n, m, k;
ll f[N][N]; int main()
{
while (scanf("%d%d%d", &n, &m, &k) != EOF)
{
memset(f, , sizeof f);
f[][] = m;
for (int i = ; i <= n; ++i)
{
for (int j = ; j <= min(i - , k); ++j)
{
f[i][j] = (f[i][j] + f[i - ][j]) % MOD;
f[i][j + ] = (f[i][j + ] + f[i - ][j] * (m - ) % MOD) % MOD;
}
}
printf("%lld\n", f[n][k]);
}
return ;
}

D. Maximum Distance

Upsolved.

题意:

有一张图

定义一条路径的长度的路径上边权最大值

定义两点距离为两点之间最短路径

有一些特殊点,要对所有特殊点求离它最远的特殊点

思路:

我们考虑一条边所连接的两个连通块里,如果这两个连通块里都有特殊点

那么这条边的权值就可以用于更新特殊点的答案

其实就是一个求最小生成树的过程,先按边权排序

要注意的是不是求整个图的最小生成树,而是所有特殊点的最小生成树

其实是最小瓶颈生成树.

 #include <bits/stdc++.h>
using namespace std; #define N 100010
int n, m, k;
struct node
{
int u, v, w;
void scan() { scanf("%d%d%d", &u, &v, &w); }
bool operator < (const node &other) const { return w < other.w; }
}edge[N]; int pre[N], cnt[N];
int find(int x) { return pre[x] == ? x : pre[x] = find(pre[x]); }
int Kruskal()
{
sort(edge + , edge + + m);
for (int i = ; i <= m; ++i)
{
int u = edge[i].u, v = edge[i].v, w = edge[i].w;
int fu = find(u), fv = find(v);
if (fu == fv) continue;
cnt[fv] += cnt[fu];
pre[fu] = fv;
if (cnt[fv] == k) return w;
}
} int main()
{
while (scanf("%d%d%d", &n, &m, &k) != EOF)
{
memset(pre, , sizeof pre);
memset(cnt, , sizeof cnt);
for (int i = , x; i <= k; ++i) scanf("%d", &x), cnt[x] = ;
for (int i = ; i <= m; ++i) edge[i].scan();
int res = Kruskal();
for (int i = ; i <= k; ++i) printf("%d%c", res, " \n"[i == k]);
}
return ;
}

E. Missing Numbers

Upsolved.

题意:

有$n个数,给出a_2, a_4 \cdots a_n$

$n是偶数,提供a_1, a_3 \cdots a_{n - 1}$

使得

$所有前缀和都是平方数$

思路:

考虑$n = 2的时候$

$我们令b^2 = a_1 + a_2$

$a^2 = a_1$

那么有

$b^2 - a^2 = (b + a) \cdot (b - a) = a_2$

$我们将a_2 拆成 p \cdot q 的形式$

$令p >= q$

$那么有  b + a = p, b - a = q$

$解方程有 b = \frac{p + q}{2}$

$发现一限制条件 p, q的奇偶性要相同$

$那么a_1 = (\frac{p + q}{2})^2 - a_2$

那么如果有多解 我们取$a_1最小的$

$因为当n >= 2的情况也可以同样这样推下去,会发现前面的项越小越好$

 #include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 100010
int n;
ll x[N];
vector <int> vec[N << ]; void init()
{
for (int i = ; i <= ; ++i)
for (int j = i * i; j <= ; j += i)
vec[j].push_back(i);
} int main()
{
init();
while (scanf("%d", &n) != EOF)
{
for (int i = ; i <= n; i += ) scanf("%lld", x + i);
bool flag = true;
ll base = ;
for (int i = ; i <= n; i += )
{
base += x[i + ];
int limit = sqrt(x[i + ]);
ll res = (ll)1e18;
ll p, q;
for (auto j : vec[x[i + ]])
if ((j % ) == ((x[i + ] / j) % ))
{
p = j, q = (x[i + ] / j);
ll tot = (p + q) / ;
tot *= tot;
if (tot > base)
res = min(res, tot - base);
}
if (res <= (ll)1e13)
{
x[i] = res;
base += res;
}
else
{
flag = false;
break;
}
}
if (!flag) puts("No");
else
{
puts("Yes");
for (int i = ; i <= n; ++i)
printf("%lld%c", x[i], " \n"[i == n]);
}
}
return ;
}

Avito Cool Challenge 2018 Solution的更多相关文章

  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 B. Farewell Party 【YY】

    传送门:http://codeforces.com/contest/1081/problem/B B. Farewell Party time limit per test 1 second memo ...

  3. Avito Cool Challenge 2018

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

  4. Avito Cool Challenge 2018(div1+2)

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

  5. Avito Code Challenge 2018

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

  6. Avito Cool Challenge 2018 自闭记

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

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

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

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

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

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

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

随机推荐

  1. docker run 详解

    docker run 用于把镜像启动为容器,语法如下: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] 常见用法: [root@localhost ~]$ ...

  2. 高性能LAMP程序设计

    高性能LAMP程序设计 原文地址: http://www.infoq.com/cn/presentations/fcq-high-performance-lamp-programming 演讲稿: h ...

  3. JS-缓冲运动-对联型悬浮框

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  4. Java初学者笔记二:关于类的常见知识点汇总

    一.Java的类: Java的类是Java的基本概念了,基本的定义语法我就不提了,自己也不会忘了的,下面分成几个模块介绍: 1.Java的类定义时候的修饰符 2.Java的类的继承与派生 二.Java ...

  5. .net asp [转载]ASP:循环滚动图片的代码+解释

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. mobiscroll的例子

    官网:https://docs.mobiscroll.com/4-3-2/jquery/datetime#options ............. <!DOCTYPE html>< ...

  7. Swift - 点击箭头旋转

    let arrowImage = UIImageView(image: UIImage(named: "Machine_arrow")!.imageWithRenderingMod ...

  8. Linux系列-Xshell连接本地VMware安装的Linux虚拟机

    一.安装VMwareWorkstation并安装RedHat虚拟机,这里安装步骤省略,网络的资料很多,大侠们不如百度或者谷歌一下,大把的资料. 二.打开本地电脑的“网络连接”,你会发现多出了2个网络适 ...

  9. 常用meta标签及说明

    1.charset   定义文档的字符编码 例如: <meta charset="UTF-8"> 2. name  把 content 属性关联到一个名称,其属性有   ...

  10. 不走标准路的微软:少一个斜杠的URI Path

    今天又被微软不按标准的做法折腾了一下,写篇博文抱怨一下. 我们先来看一下IETF(Internet Engineering Task Force)对URI结构的标准定义(链接): 注意上面的path部 ...