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. 【DSP开发】CMD文件

    DSP的存储器的地址范围,CMD是主要是根据那个来编的. CMD 它是用来分配rom和ram空间用的,告诉链接程序怎样计算地址和分配空间. 所以不同的芯片就有不同大小的rom和ram.放用户程序的地方 ...

  2. bat命令教程

    转自:https://www.jb51.net/article/151923.htm 第一章 批处理基础 第一节 常用批处理内部命令简介 批处理定义:顾名思义,批处理文件是将一系列命令按一定的顺序集合 ...

  3. 将一个整数数组先按照因子数量排序,再按照数字大小排序,输出第k个数

    同小米OJ比赛题:现在有 n 个数,需要用因子个数的多少进行排序,因子个数多的排在后面,因子个数少的排在前面,如果因子个数相同那么就比较这个数的大小,数大的放在后面,数小的放在前面.现在让你说出排序之 ...

  4. Python 解leetcode:48. Rotate Image

    题目描述:把一个二维数组顺时针旋转90度: 思路: 对于数组每一圈进行旋转,使用m控制圈数: 每一圈的四个元素顺时针替换,可以直接使用Python的解包,使用k控制每一圈的具体元素: class So ...

  5. Python学习2——使用字符串(完整版)

    """ 在C语言入门的时候字符串没有好好学习,导致后期语言根本没有入门, 更导致之后大量的codeing时间浪费,效率低下. 因此,借助这次Python入门,好好地将字符 ...

  6. LeetCode 2——两数相加(JAVA)

    给出两个 非空 的链表用来表示两个非负的整数.其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个节点只能存储 一位 数字. 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和 ...

  7. S02_CH16 等精度频率计实验

    S02_CH16 等精度频率计实验 在了解了AXI总线之后,今天我们自己动手设计一个带AXI4-Lite总线的IP,来完成频率计的实验. 频率计虽然小,但是也算五脏俱全,涉及到zynq的方方面面,比如 ...

  8. Python算法题(三)——经典函数题

    题目一(统计字符串中指定类型字符的个数): 假设所有字符分为三类:字母,数字及其他字符.‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‮‬‪‬‪‬‪‬‪‬ ...

  9. python之random库的使用以及程序的异常处理

    1.random库的使用: random库是使用随机数的Python标准库从概率论角度来说,随机数是随机产生的数据(比如抛硬币),但时计算机是不可能产生随机值,真正的随机数也是在特定条件下产生的确定值 ...

  10. Stanford NLP 课程笔记之计算字符串距离

    在自然语言处理任务中,有时候需要计算两个字符串之间的相似度,也可以称作是两者之间的距离,用最小编辑距离表示. 最小编辑距离用{Insertion,Deletion,Substitution}这三种操作 ...