2017 Multi-University Training Contest - Team 1 (5/12)
官方题解
1001. Add More Zero
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; int main()
{
int n,cas=;
while(~scanf("%d",&n))
{
double x=1.0*log()/log()*n;
int ans=int(x);
printf("Case #%d: %d\n",cas++,ans);
}
return ;
}
1001
1002. Balala Power!
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define LL long long
#define pi (4*atan(1.0))
#define eps 1e-8
#define bug(x) cout<<"bug"<<x<<endl;
const int N=1e5+,M=1e6+,inf=1e9+;
const LL INF=1e18+,mod=1e9+; char a[N];
int num[N][],flag[];
struct is
{
string x;
int pos;
bool operator <(const is &p)const
{
if(x.size()==p.x.size())
return x<p.x;
return x.size()<p.x.size();
}
}c[]; int main()
{
int n,cas=;
while(~scanf("%d",&n))
{
memset(num,,sizeof(num));
memset(flag,,sizeof(flag));
for(int i=;i<=n;i++)
{
scanf("%s",a);
int len=strlen(a);
if(len>)flag[a[]-'a']=;
for(int j=len-,k=;j>=;j--,k++)
{
num[k][a[j]-'a']++;
}
}
for(int j=;j<;j++)
for(int i=;i<=;i++)
{
if(num[i][j]>=)
{
num[i+][j]+=num[i][j]/;
num[i][j]%=;
}
}
for(int i=;i<;i++)
{
c[i].x="";
c[i].pos=i;
for(int j=;j>=;j--)
{
if(num[j][i]!=)
{
for(int k=j;k>=;k--)
c[i].x+=(char)(num[k][i]+'');
break;
}
}
}
sort(c,c+);
LL fuck=;
LL ans=;
int now=-;
for(int i=;i<=;i++)
if(flag[c[i].pos]==)
{
now=i;
break;
}
for(int i=;i<=;i++,fuck++)
{
if(i==now){
fuck--;
continue;
}
LL base=,out=;
for(int j=;j<=;j++)
{
out=(out+(1LL*num[j][c[i].pos])*base)%mod;
base=(1LL*base*)%mod;
}
ans=(ans+out*fuck)%mod;
}
printf("Case #%d: %lld\n",cas++,ans);
}
return ;
}
1003. Colorful Tree
树分治写法
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
typedef unsigned long long ULL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 2e5+, M = 1e3+,inf = 2e9,mod = ; int head[N],vis[N],f[N],siz[N],n,t = ,allnode,root;
struct edge{int to,next;}e[N * ];
void add(int u,int v) {e[t].next=head[u];e[t].to=v;head[u]=t++;}
void getroot(int u,int fa) {
f[u] = ;
siz[u] = ;
for(int i = head[u]; i; i = e[i].next) {
int to = e[i].to;
if(vis[to] || to == fa) continue;
getroot(to,u);
siz[u] += siz[to];
f[u] = max(f[u],siz[to]);
}
f[u] = max(f[u], allnode - siz[u]);
if(f[u] < f[root]) root = u;
}
int cnt[N],c[N],best[N],dep[N];
int vis2[N],fuck,vis3[N],cnt3[N];
LL ans = ;
inline void dfs3(int u,int f) {
vis2[c[u]] = ;
vis3[c[u]] = ;
cnt3[c[u]] = ;
for(int i = head[u]; i; i = e[i].next) {
int to = e[i].to;
if(vis[to] || to == f) continue;
dfs3(to,u);
}
}
inline LL dfs2(int u,int f,int now) {
LL ret = ;
if((!vis2[c[u]]) && fuck!=c[u])
ret += 1LL*siz[u] * (allnode - now - cnt[c[u]]),
cnt3[c[u]] += siz[u];
vis2[c[u]]++;
for(int i = head[u]; i; i = e[i].next) {
int to = e[i].to;
if(vis[to] || to == f) continue;
ret += dfs2(to,u,now);
}
vis2[c[u]]--;
return ret;
}
inline void make_fail(int u,int f) {
if(!vis3[c[u]])
cnt[c[u]] += cnt3[c[u]],
vis3[c[u]] = ;
for(int i = head[u]; i; i = e[i].next) {
int to = e[i].to;
if(vis[to] || to == f) continue;
make_fail(to,u);
}
}
inline LL cal(int u) {
LL ret = ;
LL ahv = ;
fuck = c[u];
dep[u] = ;
for(int i = head[u]; i; i = e[i].next) {
int to = e[i].to;
if(vis[to]) continue;
dfs3(to,u);
ret += dfs2(to,u,siz[to]);
make_fail(to,u);
ret += 1LL*(allnode - ahv - siz[to])*siz[to];
ahv += siz[to];
}
return ret;
}
void getdeep(int u,int f) {
siz[u] = ;
cnt[c[u]] = ;
dep[u] = dep[f] + ;
for(int i = head[u]; i; i = e[i].next) {
int to = e[i].to;
if(vis[to] || to == f) continue;
getdeep(to,u);
siz[u] += siz[to];
}
}
void work(int u) {
vis[u] = ;
getdeep(u,);
ans += cal(u);
for(int i = head[u]; i; i = e[i].next) {
int to = e[i].to;
if(vis[to]) continue;
allnode = siz[to];
root = ;
getroot(to,);
work(root);
}
}
void init() {
t = ;
for(int i = ; i <= n; ++i)
head[i] = ,vis[i] = ,cnt[i] = ;
}
int main() {
int cas = ;
while(scanf("%d",&n)!=EOF) {
init();
for(int i = ; i <= n; ++i) scanf("%d",&c[i]);
for(int i = ; i < n; ++i) {
int x,y;
scanf("%d%d",&x,&y);
add(x,y);
add(y,x);
}
ans = ;
f[] = inf;
allnode = n,root = ;
getroot(,);
work(root);
printf("Case #%d: %lld\n",cas++,ans);
}
return ;
}
1006. Function
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
typedef unsigned long long ULL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 5e5+, M = 1e3+,inf = 2e9,mod = ; int cnt,vis[N];
int n,m,a[N],b[N];
vector<int> G[N],E[N];
vector<LL > ret;
LL fi[N],ff[N];
void init() {
for(int i = ; i <= max(n,m); ++i) {
fi[i] = ;vis[i] = ;
ff[i] = ;
}
for(int i = ; i <= max(n,m); ++i) G[i].clear(),E[i].clear();
ret.clear();
}
void dfs(int u) {
cnt++;
vis[u] = ;
for(int i = ; i < G[u].size(); ++i) {
if(!vis[G[u][i]])dfs(G[u][i]);
}
}
void dfs2(int u) {
cnt++;
vis[u] = ;
for(int i = ; i < E[u].size(); ++i) {
if(!vis[E[u][i]]) dfs2(E[u][i]);
}
}
int main() {
int cas= ;
while(scanf("%d%d",&n,&m)!=EOF) {
init();
for(int i = ; i < n; ++i) {
scanf("%d",&a[i]);
G[i].push_back(a[i]);
}
for(int i = ; i < m; ++i) {
scanf("%d",&b[i]);
E[i].push_back(b[i]);
}
for(int i = ; i < n; ++i) {
if(!vis[i]) {
cnt = ;
dfs(i);
ret.push_back(cnt);
}
}
for(int i = ; i < m; ++i) vis[i] = ;
for(int i = ; i < m; ++i) {
if(!vis[i]) {
cnt = ;
dfs2(i);
fi[cnt]++;
}
}
for(int i = ; i <= m; ++i) {
for(int j = i; j <= n; j += i) {
ff[j] += fi[i]*i;
}
}
LL ans = ;
for(int i = ; i < ret.size(); ++i) {
if(ret[i] != )
ans = (ans * (fi[] + ff[ret[i]]))%mod;
else ans = (ans * (fi[]))%mod;
}
printf("Case #%d: %lld\n",cas++,ans);
}
return ;
}
1011. KazaQ's Socks
找规律
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
typedef unsigned long long ULL;
const long long INF = 1e18+1LL;
const double pi = acos(-1.0);
const int N = 2e5+, M = 1e3+,inf = 2e9; LL k,n;
int main() {
int cas = ;
while(scanf("%lld%lld",&n,&k)!=EOF) {
printf("Case #%d: ",cas++);
if(k <= n) {
printf("%lld\n",k);
}
else {
k -= n;
LL tmp = k - k/(n-)*(n-);
if(tmp == ) tmp = n-;
if((k/(n-))%) {
if(tmp <= n-) printf("%lld\n",tmp);
else printf("%lld\n",n-);
}
else {
if(tmp <= n-) printf("%lld\n",tmp);
else printf("%lld\n",n);
} }
}
return ;
}
2017 Multi-University Training Contest - Team 1 (5/12)的更多相关文章
- 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】
FFF at Valentine Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】
Dying Light Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】
CSGO Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】
Ch’s gift Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】
Big binary tree Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】
Colorful Tree Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】
Function Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】
Balala Power! Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】
KazaQ's Socks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
随机推荐
- shell-001
for: shell_test #!/bin/bash var= var=$var+ echo $var mkdir only_a_joke shell_joke #!/bin/bash ./shel ...
- JAVA如何解压缩ZIP文档
代码片段: package org.yu.units; import java.io.Closeable; import java.io.File; import java.io.FileInputS ...
- 开源中国+soucetree
参考链接:http://www.cocoachina.com/programmer/20151012/13682.html 1.创建一个工程
- 手写数字0-9的识别代码(SVM支持向量机)
帮一个贴吧的朋友改的一段代码,源代码来自<机器学习实战> 原代码的功能是识别0和9两个数字 经过改动之后可以识别0~9,并且将分类器的产生和测试部分分开来写,免得每次测试数据都要重新生成分 ...
- websql使用实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- linux虚拟机无法上网 Network is unreachable
系统centos 安装ftp时报错 Couldn't resolve host 'mirrorlist.centos.org [root@wulihua bin]# yum install vsft ...
- Codeforces Round #288 (Div. 2) E. Arthur and Brackets [dp 贪心]
E. Arthur and Brackets time limit per test 2 seconds memory limit per test 128 megabytes input stand ...
- msp430项目编程56
msp430综合项目---扩展项目六56 1.电路工作原理 2.代码(显示部分) 3.代码(功能实现) 4.项目总结
- GridView动态删除Item
activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...
- CODEVS_2144 砝码称重 2 折半搜索+二分查找+哈希
#include<iostream> #include<algorithm> #include<cstring> #include<map> #incl ...