官方题解

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)的更多相关文章

  1. 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) ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. IntelliJ IDEA 代码提示快捷键

    1.写代码时用Alt-Insert(Code|Generate…)可以创建类里面任何字段的getter与setter方法. mac版 是ctrl+enter 2.CodeCompletion(代码完成 ...

  2. AFNetWorking出现code=-1016错误解决办法

    报错类似: 2015-12-09 15:58:03.062 Carloans[14328:2300485] Error Domain=com.alamofire.error.serialization ...

  3. 【bzoj4240】有趣的家庭菜园 贪心+树状数组

    题目描述 对家庭菜园有兴趣的JOI君每年在自家的田地中种植一种叫做IOI草的植物.JOI君的田地沿东西方向被划分为N个区域,由西到东标号为1~N.IOI草一共有N株,每个区域种植着一株.在第i个区域种 ...

  4. 【bzoj4826】[Hnoi2017]影魔 单调栈+可持久化线段树

    题目描述 影魔,奈文摩尔,据说有着一个诗人的灵魂.事实上,他吞噬的诗人灵魂早已成千上万.千百年来,他收集了各式各样的灵魂,包括诗人.牧师.帝王.乞丐.奴隶.罪人,当然,还有英雄.每一个灵魂,都有着自己 ...

  5. Spring JdbcTemplate操作小结

    Spring 提供了JdbcTemplate 来封装数据库jdbc操作细节: 包括: 数据库连接[打开/关闭] ,异常转义 ,SQL执行 ,查询结果的转换 使用模板方式封装 jdbc数据库操作-固定流 ...

  6. phoenixframework集成了所有自动化测试的思想的平台。mark一下。

    phoenixframework http://www.cewan.la/

  7. day02-菜单处理

    解决力度到按钮的级别 ----------------------------------------------------------------------------------------- ...

  8. Java Interface 是常量存放的最佳地点吗?(转帖学习,非原创)

    Java Interface 是常量存放的最佳地点吗?(转帖学习,非原创) 由于java interface中声明的字段在编译时会自动加上static final的修饰符,即声明为常量.因而inter ...

  9. 垃圾收集器与内存分配策略 (深入理解JVM二)

    1.概述 垃圾收集(Garbage Collection,GC). 当需要排查各种内存溢出.内存泄露问题时,当垃圾收集成为系统达到更高并发量的瓶颈时,我们就需要对这些“自动化”的技术实施必要的监控和调 ...

  10. msp430项目编程42

    msp430综合项目---无线通信直流电机调速系统42