hdu 6033
1 pragma comment(linker, "/STACK:102400000,102400000") 2 #include <cstdio> 3 #include <iostream> 4 #include <cstdlib> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 #include <cctype> 9 #include <map> 10 #include <set> 11 #include <queue> 12 #include <bitset> 13 #include <string> 14 #include <complex> 15 #define ll __int64 16 #define mod 1000000007 17 using namespace std; 18 int n; 19 int main() 20 { 21 int t=0; 22 while(scanf("%d",&n)!=EOF){ 23 printf("Case #%d: %d ",++t,(int)(n*(log(2)/log(10)))); 24 } 25 return 0; 26 }
hdu 6034
1 #pragma comment(linker, "/STACK:102400000,102400000") 2 #include <cstdio> 3 #include <iostream> 4 #include <cstdlib> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 #include <cctype> 9 #include <map> 10 #include <set> 11 #include <queue> 12 #include <bitset> 13 #include <string> 14 #include <complex> 15 #define ll long long 16 #define mod 1000000007 17 using namespace std; 18 int n; 19 char a[100005]; 20 map<char,int>mp; 21 int num[26][100005]; 22 int ans[26]; 23 struct node 24 { 25 char what; 26 int maxn; 27 } N[26]; 28 bool cmp(struct node aa,struct node bb) 29 { 30 if(aa.maxn>bb.maxn) 31 return true; 32 else 33 { 34 if(aa.maxn==bb.maxn) 35 { 36 for(int j=aa.maxn-1; j>=0; j--) 37 { 38 if(num[aa.what-'a'][j]!=num[bb.what-'a'][j]) 39 return num[aa.what-'a'][j]>num[bb.what-'a'][j]; 40 } 41 } 42 } 43 return false; 44 } 45 int main() 46 { 47 int s=0; 48 while(scanf("%d",&n)!=EOF) 49 { 50 mp.clear(); 51 for(int i=0; i<=25; i++) 52 { 53 memset(num[i],0,sizeof(num[i])); 54 N[i].what=i+'a'; 55 N[i].maxn=0; 56 ans[i]=-1; 57 } 58 for(int i=1; i<=n; i++) 59 { 60 scanf("%s",a); 61 int lena=strlen(a); 62 if(lena>1) 63 mp[a[0]]=1; 64 for(int j=0; j<lena; j++) 65 { 66 num[a[j]-'a'][lena-1-j]+=1; 67 N[a[j]-'a'].maxn=max(N[a[j]-'a'].maxn,lena-1-j+1); 68 } 69 } 70 for(int i=0; i<=25; i++) 71 { 72 ll be=0; 73 for(int j=0; j<N[i].maxn; j++) 74 { 75 ll ok=(be+num[i][j])%26; 76 be=(be+num[i][j])/26; 77 num[i][j]=ok; 78 } 79 int jishu=N[i].maxn; 80 while(be>0) 81 { 82 num[i][jishu]=be%26; 83 be/=26; 84 jishu++; 85 } 86 N[i].maxn=jishu; 87 } 88 89 sort(N,N+26,cmp); 90 for(int i=25; i>=0; i--) 91 { 92 if(mp[N[i].what]==0) 93 { 94 ans[i]=0; 95 break; 96 } 97 } 98 int jishu=25; 99 for(int i=0; i<=25; i++) 100 { 101 if(ans[i]==-1) 102 { 103 ans[i]=jishu; 104 jishu--; 105 } 106 } 107 ll re=0; 108 for(int i=0; i<=25; i++) 109 { 110 if(ans[i]!=0) 111 { 112 ll gg=1; 113 for(int j=0; j<N[i].maxn; j++) 114 { 115 re=(re+gg*(num[N[i].what-'a'][j]*ans[i])%mod)%mod; 116 gg*=26; 117 gg%=mod; 118 } 119 } 120 121 } 122 cout<<"Case #"<<++s<<": "<<re<<endl; 123 } 124 return 0; 125 }
hdu 6035
1 #pragma comment(linker, "/STACK:102400000,102400000") 2 #include <cstdio> 3 #include <iostream> 4 #include <cstdlib> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 #include <cctype> 9 #include <map> 10 #include <set> 11 #include <queue> 12 #include <bitset> 13 #include <string> 14 #include <complex> 15 #define ll long long 16 #define mod 1000000007 17 using namespace std; 18 ll n; 19 ll pre[200005]; 20 ll used[200005]; 21 ll siz[200005]; 22 ll sum[200005]; 23 ll col[200005]; 24 ll gg[200005]; 25 struct node 26 { 27 ll to;; 28 ll pre; 29 } N[800005]; 30 ll nedge=0; 31 ll ans=0; 32 void init() 33 { 34 for(int i=1; i<=n; i++){ 35 pre[i]=0; 36 used[i]=0; 37 gg[i]=0; 38 sum[i]=0; 39 siz[i]=0; 40 col[i]=0; 41 } 42 nedge=0; 43 } 44 void add(ll st,ll ed) 45 { 46 nedge++; 47 N[nedge].to=ed; 48 N[nedge].pre=pre[st]; 49 pre[st]=nedge; 50 } 51 void dfs(ll root) 52 { 53 used[root]=1; 54 siz[root]=1; 55 ll be=sum[col[root]]; 56 ll ad=0; 57 for(int i=pre[root]; i; i=N[i].pre) 58 { 59 if(used[N[i].to]==0) 60 { 61 dfs(N[i].to); 62 siz[root]+=siz[N[i].to]; 63 ll sonu=sum[col[root]]-be; 64 ll tmp=siz[N[i].to]-sonu; 65 ad+=sonu; 66 ans=ans-tmp*(tmp-1)/2; 67 be=sum[col[root]]; 68 } 69 70 } 71 sum[col[root]]+=(siz[root]-ad); 72 } 73 int main() 74 { 75 //freopen("input.txt","r",stdin); 76 //freopen("output.txt","w",stdout); 77 int t=0; 78 while(scanf("%lld",&n)!=EOF) 79 { 80 init(); 81 ll jishu=0; 82 for(int i=1; i<=n; i++){ 83 scanf("%lld",&col[i]); 84 if(gg[col[i]]==0){ 85 jishu++; 86 gg[col[i]]=1; 87 } 88 } 89 ll a,b; 90 for(int i=1; i<n; i++) 91 { 92 scanf("%lld %lld",&a,&b); 93 add(a,b); 94 add(b,a); 95 } 96 ans=jishu*(n*(n-1)/2); 97 dfs(1); 98 for(int i=1;i<=n;i++){ 99 if(sum[i]!=0){ 100 ll res=n-sum[i]; 101 ans=ans-(res-1)*res/2; 102 } 103 } 104 printf("Case #%d: %lld ",++t,ans); 105 } 106 return 0; 107 }
hdu 6038
1 #pragma comment(linker, "/STACK:102400000,102400000") 2 #include <cstdio> 3 #include <iostream> 4 #include <cstdlib> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 #include <cctype> 9 #include <map> 10 #include <set> 11 #include <queue> 12 #include <bitset> 13 #include <string> 14 #include <complex> 15 #define ll long long 16 #define mod 1000000007 17 using namespace std; 18 int n,m; 19 int a[100005]; 20 int b[100005]; 21 vector<int> aa; 22 vector<int> bb; 23 map<int,int>mp; 24 int main() 25 { 26 int t=0; 27 while(scanf("%d %d",&n,&m)!=EOF) 28 { 29 aa.clear(); 30 bb.clear(); 31 mp.clear(); 32 for(int i=0; i<n; i++) 33 scanf("%d",&a[i]); 34 for(int j=0; j<m; j++) 35 scanf("%d",&b[j]); 36 for(int i=0;i<n;i++) 37 { 38 if(mp[i]==0) 39 { 40 int now=1; 41 mp[i]=1; 42 int s=i; 43 while(mp[a[s]]==0){ 44 now++; 45 mp[a[s]]=1; 46 s=a[s]; 47 } 48 aa.push_back(now); 49 } 50 } 51 mp.clear(); 52 for(int i=0;i<m;i++) 53 { 54 if(mp[i]==0) 55 { 56 int now=1; 57 mp[i]=1; 58 int s=i; 59 while(mp[b[s]]==0){ 60 now++; 61 mp[b[s]]=1; 62 s=b[s]; 63 } 64 bb.push_back(now); 65 } 66 } 67 ll ans=1; 68 for(int i=0;i<aa.size();i++){ 69 ll temp=0; 70 for(int j=0;j<bb.size();j++){ 71 72 if(aa[i]%bb[j]==0) 73 temp+=bb[j]; 74 } 75 ans=(ans*temp)%mod; 76 } 77 printf("Case #%d: %lld ",++t,ans); 78 } 79 return 0; 80 }
hdu 6043
1 #pragma comment(linker, "/STACK:102400000,102400000") 2 #include <cstdio> 3 #include <iostream> 4 #include <cstdlib> 5 #include <cstring> 6 #include <algorithm> 7 #include <cmath> 8 #include <cctype> 9 #include <map> 10 #include <set> 11 #include <queue> 12 #include <bitset> 13 #include <string> 14 #include <complex> 15 #define ll long long 16 #define mod 1000000007 17 using namespace std; 18 ll n,k; 19 int main() 20 { 21 int t=0; 22 while(scanf("%lld %lld",&n,&k)!=EOF){ 23 if(k<=n) 24 printf("Case #%d: %lld ",++t,k); 25 else 26 { 27 ll now; 28 ll which; 29 now=(k-n)/(n-1); 30 which=(k-n)%(n-1); 31 if(now%2==0) 32 { 33 if(which==0) 34 printf("Case #%d: %lld ",++t,n); 35 else 36 printf("Case #%d: %lld ",++t,which); 37 } 38 else 39 { 40 if(which==0) 41 printf("Case #%d: %lld ",++t,n-1); 42 else 43 printf("Case #%d: %lld ",++t,which); 44 } 45 } 46 } 47 return 0; 48 }