2017 Chinese Multi-University Training, BeihangU Contest

Add More Zero

思路:log10(2^m) = m*log10(2)

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb emplace_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define puu pair<ULL, ULL>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head int n, cs = ;
int main() {
while(~scanf("%d", &n)) {
printf("Case #%d: %d\n", ++cs, (int)(n*log10(2.0)));
}
return ;
}

Balala Power!

思路:大数比较大小

代码:

#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define debug(x) cerr<<#x << " := " << x << endl;
#define bug cerr<<"-----------------------"<<endl;
#define FOR(a, b, c) for(int a = b; a <= c; ++ a)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll; const int inf = 0x3f3f3f3f; const int mod = 1e9+; /**********showtime************/
const int maxn = 1e5+;
char str[maxn];
string ss[maxn];
vector<pii>vec[];
int a[][maxn], mx[];
int id[], vis[];
bool cmp(int &x, int &y) {
if(mx[x] < mx[y]) return true;
else if(mx[x] > mx[y]) return false;
else {
for (int i = mx[x]-; i >= ; --i) {
if(a[x][i] > a[y][i]) return false;
else if(a[x][i] < a[y][i]) return true;
}
}
return false;
}
int main(){
int n, cas = ;
while(~scanf("%d", &n)) { for(int i=; i<; i++) vec[i].clear(), vis[i] = , mx[i] = ;
for(int i=; i<; i++) for(int j=; j<maxn; j++) a[i][j] = ;
for(int i=; i<=n; i++) {
scanf("%s", str);
ss[i] = string(str);
vis[str[] - 'a'] = ;
} for(int i=; i<=n; i++) {
int len = ss[i].length();
for(int j=; j<len; j++) {
a[ss[i][j] - 'a'][len - j - ] ++;
}
} for(int i=; i<; i++) {
int jin = ;
for(int j=; j<maxn-; j++) {
a[i][j] += jin;
jin = a[i][j] / ;
a[i][j] = a[i][j] % ;
if(a[i][j] > ) {
mx[i] = j+;
}
}
} for(int i=; i<; i++) id[i] = i; sort(id, id+, cmp); int pos = ;
while(vis[id[pos]]) pos++;
int pt = id[pos];
for(int i=pos; i>=; i--) id[i] = id[i-];
id[] = pt;
ll ans = ;
for(int i=; i<; i++) {
ll base = ;
for(int j=; j<maxn; j++) { ans = (ans + 1ll*i * base *a[id[i]][j] % mod)%mod;
base = 1ll * base * % mod;
}
}
++cas;
printf("Case #%d: %lld\n",cas, ans);
}
return ;
}

Colorful Tree

思路:容斥,考虑对于每种颜色删去后,分成的块中的点两两之间对于这种颜色没有贡献

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head const int N = 2e5 + ;
vector<int> g[N], stk[N];
int n, u, v, c[N], sz[N], blo[N], top[N];
bool vis[N];
void dfs(int u, int o) {
sz[u] = ;
for (int v : g[u]) {
if(v != o) {
dfs(v, u);
sz[u] += sz[v];
}
}
blo[u] = sz[u];
}
void DFS(int u, int o) {
if(stk[c[u]].empty()) top[c[u]] -= sz[u];
else blo[stk[c[u]].back()] -= sz[u];
for (int v : g[u]){
if(v != o) {
stk[c[u]].pb(v);
DFS(v, u);
stk[c[u]].pop_back();
}
}
}
int cs = ;
int main() {
while(~scanf("%d", &n)) {
for (int i = ; i <= n; ++i) scanf("%d", &c[i]), vis[c[i]] = true;
for (int i = ; i < n; ++i) scanf("%d %d", &u, &v), g[u].pb(v), g[v].pb(u);
dfs(, );
int cc = ;
for (int i = ; i <= n; ++i) if(vis[i]) top[i] = n, ++cc; else top[i] = ;
DFS(, );
LL ans = n*1LL*(n-)/*cc;
for (int i = ; i <= n; ++i) ans -= blo[i]*1LL*(blo[i]-)/;
for (int i = ; i <= n; ++i) ans -= top[i]*1LL*(top[i]-)/;
printf("Case #%d: %lld\n", ++cs, ans);
for (int i = ; i <= n; ++i) g[i].clear(), vis[i] = false;
}
return ;
}

Division Game

Expectation of Division

Function

思路:a的某个长度为x环可以和b中长度为x因子的环构成函数

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head const int N = 1e5 + ;
const int MOD = 1e9 + ;
int n, m, a[N], b[N], ca[N], cb[N];
LL ans[N];
bool vis[N], vv[N];
LL q_pow(LL n, LL k) {
LL res = ;
while(k) {
if(k&) res = (res * n) % MOD;
n = (n * n) % MOD;
k >>= ;
}
return res;
}
int main() {
int cs = ;
while(~scanf("%d %d", &n, &m)) {
for (int i = ; i < n; ++i) vis[i] = false, ca[i+] = , ans[i+] = ;
for (int i = ; i < m; ++i) vv[i] = false, cb[i+] = ;
for (int i = ; i < n; ++i) scanf("%d", &a[i]);
for (int i = ; i < m; ++i) scanf("%d", &b[i]);
for (int i = ; i < n; ++i) {
if(!vis[i]) {
int now = i, cc = ;
while(!vis[now]) {
vis[now] = true;
now = a[now];
++cc;
}
ca[cc]++;
}
}
for (int i = ; i < m; ++i) {
if(!vv[i]) {
int now = i, cc = ;
while(!vv[now]) {
vv[now] = true;
now = b[now];
++cc;
}
cb[cc] ++;
}
}
LL res = ;
for (int i = ; i <= m; ++i) {
cb[i] = (cb[i]*1LL*i)%MOD;
for (int j = i; j <= n; j += i) {
ans[j] = (ans[j] + cb[i]) % MOD;
}
}
for (int j = ; j <= n; ++j) {
if(ca[j]) {
res = (res * q_pow(ans[j], ca[j])) % MOD;
}
}
printf("Case #%d: %lld\n", ++cs, res);
}
return ;
}

Gear Up

Hints of sd0061

思路:nth_element

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head
 
const int N = 1e7 + ;
unsigned x, A, y, B, z, C;
int n, m, b[], id[];
unsigned a[N], ans[N];
inline unsigned rng61() {
unsigned t;
x = x ^ (x << );
x = x ^ (x >> );
x = x ^ (x << );
t = x;
x = y;
y = z;
z = (t ^ x) ^ y;
return z;
}
int cs = ;
int main() {
while(~scanf("%d %d %u %u %u", &n, &m, &A, &B, &C)) {
for (int i = ; i <= m; ++i) scanf("%d", &b[i]);
x = A, y = B, z = C;
for (int i = ; i <= n; ++i) a[i] = rng61();
printf("Case #%d: ", ++cs);
for (int i = ; i <= m; ++i) id[i] = i;
sort(id+, id++m, [](int x, int y){
return b[x] < b[y];
});
nth_element(a+, a+b[id[m]]+, a+n+);
ans[id[m]] = a[b[id[m]]+];
for (int i = m-; i >= ; --i) {
nth_element(a+, a+b[id[i]]+, a+b[id[i+]]+);
ans[id[i]] = a[b[id[i]]+];
}
for (int i = ; i <= m; ++i) printf("%u%c", ans[i], " \n"[i==m]);
}
return ;
}

I Curse Myself

Journey with Knapsack

KazaQ's Socks

思路:打表找规律

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb emplace_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<int, pii>
#define puu pair<ULL, ULL>
#define pdd pair<long double, long double>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head
 
LL n, k;
int main() {
int cs = ;
while(~scanf("%lld %lld", &n, &k)) {
LL res;
if(n == ) res = k% == ? : ;
else if(k <= n-) res = k;
else {
if(k%(n-) == ) {
--k;
if((k/(n-))%) res = n;
else res = n-;
}
else {
res = k%(n-);
if(res == ) res = n-;
--res;
}
}
printf("Case #%d: %lld\n", ++cs, res);
}
return ;
}

Limited Permutation

2017 Chinese Multi-University Training, BeihangU Contest的更多相关文章

  1. 2016 Al-Baath University Training Camp Contest-1

    2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...

  2. Codeforces Gym101606 A.Alien Sunset (2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017))

    2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017) 寒假第一次组队训练赛,和学长一起训练,题目难度是3颗星,我和猪队友写 ...

  3. 2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest)

    2014-2015 Petrozavodsk Winter Training Camp, Contest.58 (Makoto rng_58 Soejima contest) Problem A. M ...

  4. keras使用多GPU并行训练模型 | keras multi gpu training

    本文首发于个人博客https://kezunlin.me/post/95370db7/,欢迎阅读最新内容! keras multi gpu training Guide multi_gpu_model ...

  5. 2016 Al-Baath University Training Camp Contest-1 E

    Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...

  6. 2016 Al-Baath University Training Camp Contest-1 A

    Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...

  7. 2016 Al-Baath University Training Camp Contest-1 J

    Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...

  8. 2016 Al-Baath University Training Camp Contest-1 I

    Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...

  9. 2016 Al-Baath University Training Camp Contest-1 H

     Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...

随机推荐

  1. MySql中的count、NULL和空串的区别

    **1.count (1).count (*) 与 count (列名) 的区别** 表 count(1) count(*) count (列名) 作用 统计表中的所有的记录数 会统计表中的所有的记录 ...

  2. 使用js加载器动态加载外部js、css文件

    let MiniSite = new Object(); /** * 判断浏览器 */ MiniSite.Browser = { ie: /msie/.test(window.navigator.us ...

  3. Linux下运行《UNIX环境高级编程》undefined reference to `err_quit 编译出错的处理方法

    错误信息: : undefined reference to `err_quit': undefined reference to `err_sys' 解决方法: 因为err_quit跟err_sys ...

  4. Fourier serie

    你眼中看似落叶纷飞变化无常的世界,实际只是躺在上帝怀中一份早已谱好的乐章. 时域和频域就像观察一个物体一样,一个是主视图的,一个是侧视图. 1.在有限区间上由任意图形定义的任意函数都可以表示为单纯的正 ...

  5. [转帖]关于USB3.0以及type-C

    忘记来源页面了.. 但是昨天晚上 usb 4.0 发布了 跟雷电C 安全一样的标准 双向40gb 的带宽. 而且 以后只有usb type-C的接口了. 我们办公机器上面的 typeC 同事用 ngf ...

  6. Linux Crontab格式说明

    Crontab基本格式: * * * * * command 分 时 日 月 周 命令 第1列表示分钟1-59 每分钟用 */1表示 第2列表示小时1-23(0表示0点) 第3列表示日期1-31 第4 ...

  7. System memory 259522560 must be at least 4.718592

    [学习笔记] /*没有下面的话, 会报一个错误,java.lang.IllegalArgumentException: System memory 259522560 must be at least ...

  8. LeetCode 第 164 场周赛

    访问所有点的最小时间 不难看出,从点(x1,y1) 到 (x2,y2) 的步数需要 min(dx,dy),其中 dx = abs(x1-x2),dy = abs(y1-y2) class Soluti ...

  9. Core dump文件和ECFS

    core dump文件 core dump核心转储文件,一些信号的处理方式,会生成一个elf格式的文件,用来分析进程崩溃情况. 总结一下,core dump核心转储文件就是将所有的vma都映射成一个e ...

  10. 监控 Kubernetes 集群应用

    Prometheus的数据指标是通过一个公开的 HTTP(S) 数据接口获取到的,我们不需要单独安装监控的 agent,只需要暴露一个 metrics 接口,Prometheus 就会定期去拉取数据: ...