diff --git a/HDOJ/1051_autoAC.cpp b/HDOJ/1051_autoAC.cpp new file mode 100644 index 0000000..163c62e --- /dev/null +++ b/HDOJ/1051_autoAC.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +#include +#include +#include +#include +#define MAXINT 99999999 +#define MININT -1 +using namespace std; +struct Node{ + int l; + int w; + }node[5000+4]; +int vis[5000+4]; +bool cmp(Node x,Node y) +{if(x.l=node[pre].w) + {vis[j]=1;pre=j;} + } + } + } + cout< +#include +using std::sort; +int cmp( int a, int b ) +{ + if( a < b ) return true; + return false; +} +int main() +{ + int t[1005], k[1005], n, i, j, c; + while( scanf( "%d", &n ), n ) + { + c = 0; + for( i = 0; i < n; i ++ ) + scanf( "%d", &t[i] ); + sort( t, t+n, cmp ); + for( i = 0; i < n; i ++ ) + scanf( "%d", &k[i] ); + sort( k, k + n, cmp ); + i= j = 0; + int flag1= n-1, flag2 = n-1; + while( i <= flag1 ) + { + if( t[flag1] > k[flag2] ) + { + ++c; + --flag1; + --flag2; + } + else if( t[flag1] == k[flag2] ) + { + if( t[i]>k[j] ) + { + ++c; + ++i; + ++j; + } + else if( t[i] == k[j] ) + { + if( t[i] < k[flag2] ) --c; + ++i; + --flag2; + } + else if( t[i] < k[j] ) + { + --c; + ++i; + --flag2; + } + } + else + { + --c; + ++i; + --flag2; + } + } + printf( "%d\n", c*200 ); + } +} diff --git a/HDOJ/1053_autoAC.cpp b/HDOJ/1053_autoAC.cpp new file mode 100644 index 0000000..8821e22 --- /dev/null +++ b/HDOJ/1053_autoAC.cpp @@ -0,0 +1,104 @@ +#include +#include +#include +#include +using namespace std; +int cmp(const void *a, const void *b) +{ + return *(char*)a - *(char*)b; +} +class TreeNode +{ +public: + char ch; + int count; + int depth; + TreeNode *leftChild, *rightChild; + TreeNode() + { + ch = '\0'; + count = 0; + depth = 0; + leftChild = NULL; + rightChild = NULL; + } + friend bool operator<(const TreeNode &a, const TreeNode &b) + { + return a.count > b.count; + } +}; +priority_queue que; +queue q; +int res; +void hoffman() +{ + TreeNode *root, *a, *b, *c, newNode; + while(que.size() > 1){ + a = new TreeNode; + *a = que.top(); + que.pop(); + b = new TreeNode; + *b = que.top(); + que.pop(); + c = new TreeNode; + c->count = a->count + b->count; + c->leftChild = a; + c->rightChild = b; + que.push(*c); + } + root = new TreeNode; + *root = que.top(); + root->depth = 0; + que.pop(); + q.push(*root); + while(!q.empty()){ + newNode = q.front(); + q.pop(); + if(newNode.leftChild){ + newNode.leftChild->depth = newNode.depth + 1; + q.push(*newNode.leftChild); + } + if(newNode.rightChild){ + newNode.rightChild->depth = newNode.depth + 1; + q.push(*newNode.rightChild); + } + if(!newNode.leftChild && !newNode.rightChild){ + res += newNode.depth * newNode.count; + } + } +} +int main() +{ + int i, j, len, count; + char str[1005]; + while(scanf("%s", str)!=EOF && strcmp("END", str)!=0){ + len = strlen(str); + qsort(str, len, sizeof(char), cmp); + TreeNode t; + count = 1; + t.ch = str[0]; + for(i=1; i +#include +#include +using namespace std; +bool used[1510]; +int con[1510]; +vector edges[1510]; +bool find(int x) +{ + for (int i = 0; i < edges[x].size(); i++) + { + if (!used[edges[x][i]]) + { + used[edges[x][i]] = true; + if (con[edges[x][i]] == -1 || find(con[edges[x][i]])) + { + con[edges[x][i]] = x; + return true; + } + } + } + return false; +} +int match(int n) +{ + int res = 0; + memset(con, -1, sizeof(con)); + for (int i = 0; i < n; i++) + { + memset(used, false, sizeof(used)); + if (find(i)) + res++; + } + return res; +} +int main() +{ + int n; + while (cin >> n) + { + memset(used, false, sizeof(used)); + for (int i = 0; i < n; i++) + edges[i].clear(); + for (int i = 0; i < n; i++) + { + int no; + cin >> no; + char c; + cin >> c >> c; + int en; + cin >> en >> c; + for (int j = 0; j < en; j++) + { + int p; + cin >> p; + edges[no].push_back(p); + edges[p].push_back(no); + } + } + cout << (match(n)/2) << endl; + } + return 0; +} diff --git a/HDOJ/1055_autoAC.cpp b/HDOJ/1055_autoAC.cpp new file mode 100644 index 0000000..236569b --- /dev/null +++ b/HDOJ/1055_autoAC.cpp @@ -0,0 +1,43 @@ +#include "stdio.h" +#include "string" +#define maxn 1001 +struct H{ + int val; + int cost; + int time; + void clear() { + val = cost = time = 0; + } +}hh[maxn]; +int father[maxn]; +int main() { + int n,r,i; + while(scanf("%d%d",&n,&r),n+r) { + for(i =1 ; i <= n ; i ++) { + scanf("%d",&hh[i].cost); + hh[i].val = hh[i].cost; + hh[i].time = 1; + } + for(i = 1; i < n ; i ++) { + int a,b; + scanf("%d%d",&a,&b); + father[b] = a; + } + while(true) { + int idx = 0; + for(i = 1 ; i <= n ; i ++) { + if(i != r && hh[i].time && (idx == 0 || hh[idx].val * hh[i].time < hh[i].val * hh[idx].time)) { + idx = i; + } + } + if(idx == 0) break; + int f = father[idx]; + hh[f].cost += hh[idx].cost + hh[idx].val * hh[f].time; + hh[f].val += hh[idx].val; + hh[f].time += hh[idx].time; + hh[idx].clear(); + } + printf("%d\n",hh[r].cost); + } + return 0; +} diff --git a/HDOJ/1056_autoAC.cpp b/HDOJ/1056_autoAC.cpp new file mode 100644 index 0000000..746ca83 --- /dev/null +++ b/HDOJ/1056_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +using namespace std; +int main() +{ + double examples[300],enter; + int numDenominator=3,circleA; + examples[0]=1.0/2.0; + for(circleA=1;circleA<280;circleA++){ + examples[circleA]=examples[circleA-1]+1.0/(double)(numDenominator++); + } + while(cin>>enter){ + if(0.00==enter){ + break; + } + for(circleA=0;circleA<280;circleA++){ + if(examples[circleA]>=enter){ + cout< +using namespace std; +const int Dir[][2]={{-1,0},{1,0},{0,-1},{0,1}}; +const char density[]=".!X#"; +int D[16]; +int Map[20][20],tmp[20][20]; +int main() +{ + int T,day,i,j,k,d,x,y,index; + cin>>T; + for(int t=1;t<=T;++t) + { + cin>>day; + for(i=0;i<16;++i) cin>>D[i]; + for(i=0;i<20;++i) + for(j=0;j<20;++j) + cin>>Map[i][j]; + for(k=0;k=0&&x<20&&y>=0&&y<20) + index += Map[x][y]; + } + tmp[i][j] = Map[i][j]+D[index]; + if(tmp[i][j]>3) tmp[i][j]=3; + else if(tmp[i][j]<0) tmp[i][j]=0; + } + for(i=0;i<20;++i) + for(j=0;j<20;++j) + Map[i][j] = tmp[i][j]; + } + for(i=0;i<20;++i) + { + for(j=0;j<20;++j) + cout< +#include +#include +using namespace std; +int min(int a,int b) +{ + if(a>b) return b; + else return a; +} +int main() +{ + long int a[5888]; + long int s1,s2,s3,s4,t,n; + s1 = s2 = s3 = s4 =1; + a[1] = 1; + for(int i=2;i<5888;i++) + { + t = min(min(min(a[s1]*2,a[s2]*3),a[s3]*5),a[s4]*7); + if(t == a[s1]*2) s1++; + if(t == a[s2]*3) s2++; + if(t == a[s3]*5) s3++; + if(t == a[s4]*7) s4++; + a[i] = t; + } + while(scanf("%ld",&n)) + { + if(n==0) + break; + if(n%10==1&&n%100!=11) + printf("The %ldst humble number is %ld.\n",n,a[n]); + else if(n%10==2&&n%100!=12) + printf("The %ldnd humble number is %ld.\n",n,a[n]); + else if(n%10==3&&n%100!=13) + printf("The %ldrd humble number is %ld.\n",n,a[n]); + else + printf("The %ldth humble number is %ld.\n",n,a[n]); + } + return 0; +} diff --git a/HDOJ/1059_autoAC.cpp b/HDOJ/1059_autoAC.cpp new file mode 100644 index 0000000..07b1fd2 --- /dev/null +++ b/HDOJ/1059_autoAC.cpp @@ -0,0 +1,46 @@ +#include +#include +#define maxn 444444//(1+2+3+4+5+6)*20000=420000 +int bag[maxn]={0}; +int main() +{ + int w[111],n[7],cnt=1;//2^15(>20000)*6=90 + while(scanf("%d%d%d%d%d%d",&n[1],&n[2],&n[3],&n[4],&n[5],&n[6])&&(n[1]||n[2]||n[3]||n[4]||n[5]||n[6])) + { + int i,j,k=1,sum=0; + printf("Collection #%d:\n",cnt++); + for(i=1;i<=6;i++) + { + int tmp=1; + sum+=n[i]*i; + while(n[i]>tmp) + { + w[k++]=tmp*i; + n[i]-=tmp; + tmp<<=1; + } + w[k++]=n[i]*i; + } + if(sum&1) + { + printf("Can't be divided.\n\n"); + continue; + } + sum/=2; + for(i=1;i<=sum;i++) + bag[i]=INT_MIN; + for(i=1;i=w[i];j--) + { + if(bag[j]=0) + printf("Can be divided.\n\n"); + else + printf("Can't be divided.\n\n"); + } + return 0; +} diff --git a/HDOJ/1060_autoAC.cpp b/HDOJ/1060_autoAC.cpp new file mode 100644 index 0000000..dc1a72e --- /dev/null +++ b/HDOJ/1060_autoAC.cpp @@ -0,0 +1,20 @@ +#include +#include +using namespace std; +int main() +{ + int t; + while(cin>>t) + { + while(t--) + { + unsigned long n; + cin>>n; + double x=n*log10(n*1.0); + x-=(__int64)x; + int a=pow(10.0, x); + cout<