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. C/C++笔试基础知识

    1. int *a[10] :指向int类型的指针数组a[10] int (*a)[10]:指向有10个int类型数组的指针a int (*a)(int):函数指针,指向有一个参数并且返回类型均为in ...

  2. 【ARM-Linux开发】Linux下查看机器的CPU负载

    负载(load)是Linux机器的一个重要指标,直观了反应了机器当前的状态.如果机器负载过高,那么对机器的操作将难以进行. Linux的负载高,主要是由于CPU使用.内存使用.IO消耗三部分构成.任意 ...

  3. matlab imread函数全说明

    imread Read image from graphics file  Syntax A = imread(filename, fmt) [X, map] = imread(...) [...] ...

  4. poj1797(dijstra变形,求最小边的最大值)

    题目链接:https://vjudge.net/problem/POJ-1797 题意:n个点,m条带权边,求点1到点n的所有路径中最小边的最大值. 思路: 和poj2253一样,只不过那题n< ...

  5. [LuoguP2164][SHOI2007]交通网络_拓扑排序_概率期望

    交通网络 题目链接:https://www.luogu.org/problemnew/solution/P2164 数据范围:略. 题解: 直接算不好算,我们考虑建反图然后$Toposort$. 这样 ...

  6. HTML5 & CSS初学者教程(详细、通俗易懂)

    前端语言基础:HTML5 & CSS (一) HTML5:超文本标记语言 (1) 基本概念 是由一系列成对出现的元素标签(标记)嵌套组合而成 ( XML也是标签构成的 ) 这些标签以的形式出现 ...

  7. IDEA插件之JProfiler

    1.是什么?来用干嘛的? 一个商业授权的Java剖析工具. 用来剖析程序内存.CPU使用情况,找到性能瓶颈,快速定位问题所在. 2.IDEA安装JProfiler插件 (1)File -> Se ...

  8. (九)springMvc 的 post 提交乱码

    #post 提交乱码 在 web.xml 配置下 过滤器 : <!--解决 post 乱码问题,--> <filter> <filter-name>characte ...

  9. 数据结构:BF算法

    贴上源代码: #include<iostream> using namespace std; int BF(char S[],char T[]) { int i,j; i = j = 0; ...

  10. PHP学习之PHP编码习惯

    命名的注意事项: 命名要有实际含义 命名风格保持一致 不用拼音命名 不用语言关键字 适当的使用注释 好的代码应该是自描述的 难以理解的地方加上注释 函数的功能加上注释说明 类的功能和使用方法加注释 多 ...