您的位置:首页 > 大数据 > 人工智能

2017 Multi-University Training Contest - 1

2017-07-27 10:10 405 查看
hdu 6033

pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll __int64
#define mod 1000000007
using namespace std;
int  n;
int main()
{
int t=0;
while(scanf("%d",&n)!=EOF){
printf("Case #%d: %d\n",++t,(int)(n*(log(2)/log(10))));
}
return 0;
}


hdu 6034

#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll long long
#define mod 1000000007
using namespace std;
int n;
char a[100005];
map<char,int>mp;
int num[26][100005];
int ans[26];
struct node
{
char what;
int maxn;
} N[26];
bool cmp(struct node aa,struct node bb)
{
if(aa.maxn>bb.maxn)
return true;
else
{
if(aa.maxn==bb.maxn)
{
for(int j=aa.maxn-1; j>=0; j--)
{
if(num[aa.what-'a'][j]!=num[bb.what-'a'][j])
return num[aa.what-'a'][j]>num[bb.what-'a'][j];
}
}
}
return false;
}
int main()
{
int s=0;
while(scanf("%d",&n)!=EOF)
{
mp.clear();
for(int i=0; i<=25; i++)
{
memset(num[i],0,sizeof(num[i]));
N[i].what=i+'a';
N[i].maxn=0;
ans[i]=-1;
}
for(int i=1; i<=n; i++)
{
scanf("%s",a);
int lena=strlen(a);
if(lena>1)
mp[a[0]]=1;
for(int j=0; j<lena; j++)
{
num[a[j]-'a'][lena-1-j]+=1;
N[a[j]-'a'].maxn=max(N[a[j]-'a'].maxn,lena-1-j+1);
}
}
for(int i=0; i<=25; i++)
{
ll be=0;
for(int j=0; j<N[i].maxn; j++)
{
ll ok=(be+num[i][j])%26;
be=(be+num[i][j])/26;
num[i][j]=ok;
}
int jishu=N[i].maxn;
while(be>0)
{
num[i][jishu]=be%26;
be/=26;
jishu++;
}
N[i].maxn=jishu;
}

sort(N,N+26,cmp);
for(int i=25; i>=0; i--)
{
if(mp[N[i].what]==0)
{
ans[i]=0;
break;
}
}
int jishu=25;
for(int i=0; i<=25; i++)
{
if(ans[i]==-1)
{
ans[i]=jishu;
jishu--;
}
}
ll re=0;
for(int i=0; i<=25; i++)
{
if(ans[i]!=0)
{
ll gg=1;
for(int j=0; j<N[i].maxn; j++)
{
re=(re+gg*(num[N[i].what-'a'][j]*ans[i])%mod)%mod;
gg*=26;
gg%=mod;
}
}

}
cout<<"Case #"<<++s<<": "<<re<<endl;
}
return 0;
}


hdu 6035

#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll long long
#define mod 1000000007
using namespace std;
ll n;
ll pre[200005];
ll used[200005];
ll siz[200005];
ll sum[200005];
ll col[200005];
ll gg[200005];
struct node
{
ll to;;
ll pre;
} N[800005];
ll nedge=0;
ll ans=0;
void init()
{
for(int i=1; i<=n; i++){
pre[i]=0;
used[i]=0;
gg[i]=0;
sum[i]=0;
siz[i]=0;
col[i]=0;
}
nedge=0;
}
void add(ll st,ll ed)
{
nedge++;
N[nedge].to=ed;
N[nedge].pre=pre[st];
pre[st]=nedge;
}
void dfs(ll root)
{
used[root]=1;
siz[root]=1;
ll be=sum[col[root]];
ll ad=0;
for(int i=pre[root]; i; i=N[i].pre)
{
if(used[N[i].to]==0)
{
dfs(N[i].to);
siz[root]+=siz[N[i].to];
ll sonu=sum[col[root]]-be;
ll tmp=siz[N[i].to]-sonu;
ad+=sonu;
ans=ans-tmp*(tmp-1)/2;
be=sum[col[root]];
}

}
sum[col[root]]+=(siz[root]-ad);
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int t=0;
while(scanf("%lld",&n)!=EOF)
{
init();
ll jishu=0;
for(int i=1; i<=n; i++){
scanf("%lld",&col[i]);
if(gg[col[i]]==0){
jishu++;
gg[col[i]]=1;
}
}
ll a,b;
for(int i=1; i<n; i++)
{
scanf("%lld %lld",&a,&b);
add(a,b);
add(b,a);
}
ans=jishu*(n*(n-1)/2);
dfs(1);
for(int i=1;i<=n;i++){
if(sum[i]!=0){
ll res=n-sum[i];
ans=ans-(res-1)*res/2;
}
}
printf("Case #%d: %lld\n",++t,ans);
}
return 0;
}


hdu 6038

#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll long long
#define mod 1000000007
using namespace std;
int n,m;
int a[100005];
int b[100005];
vector<int> aa;
vector<int> bb;
map<int,int>mp;
int main()
{
int t=0;
while(scanf("%d %d",&n,&m)!=EOF)
{
aa.clear();
bb.clear();
mp.clear();
for(int i=0; i<n; i++)
scanf("%d",&a[i]);
for(int j=0; j<m; j++)
scanf("%d",&b[j]);
for(int i=0;i<n;i++)
{
if(mp[i]==0)
{
int now=1;
mp[i]=1;
int s=i;
while(mp[a[s]]==0){
now++;
mp[a[s]]=1;
s=a[s];
}
aa.push_back(now);
}
}
mp.clear();
for(int i=0;i<m;i++)
{
if(mp[i]==0)
{
int now=1;
mp[i]=1;
int s=i;
while(mp[b[s]]==0){
now++;
mp[b[s]]=1;
s=b[s];
}
bb.push_back(now);
}
}
ll ans=1;
for(int i=0;i<aa.size();i++){
ll temp=0;
for(int j=0;j<bb.size();j++){

if(aa[i]%bb[j]==0)
temp+=bb[j];
}
ans=(ans*temp)%mod;
}
printf("Case #%d: %lld\n",++t,ans);
}
return 0;
}


hdu 6043

#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <string>
#include <complex>
#define ll long long
#define mod 1000000007
using namespace std;
ll n,k;
int main()
{
int t=0;
while(scanf("%lld %lld",&n,&k)!=EOF){
if(k<=n)
printf("Case #%d: %lld\n",++t,k);
else
{
ll now;
ll which;
now=(k-n)/(n-1);
which=(k-n)%(n-1);
if(now%2==0)
{
if(which==0)
printf("Case #%d: %lld\n",++t,n);
else
printf("Case #%d: %lld\n",++t,which);
}
else
{
if(which==0)
printf("Case #%d: %lld\n",++t,n-1);
else
printf("Case #%d: %lld\n",++t,which);
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐