Add files via upload

This commit is contained in:
KiritoTRw 2016-08-12 10:15:40 +08:00 committed by GitHub
parent 42d56bbc4b
commit 4bf3126523
10 changed files with 509 additions and 0 deletions

61
HDOJ/1051_autoAC.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#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<y.l)
return true;
else if(x.l==y.l)
{if(x.w<=y.w)
return true;
}
return false;
}
int main()
{
int n;
int m;
int i,j,k;
scanf("%d",&m);
while(m--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d%d",&node[i].l,&node[i].w);
}
sort(node,node+n,cmp);
for(i=0;i<n;i++)
{vis[i]=0;}
int countn=0;
for(i=0;i<n;i++)
{
if(vis[i])
continue;
vis[i]=1;
countn++;
int pre=i;
for(j=i+1;j<n;j++)
{
if(vis[j]==0)
{
if(node[j].w>=node[pre].w)
{vis[j]=1;pre=j;}
}
}
}
cout<<countn<<endl;
}
return 0;
}

61
HDOJ/1052_autoAC.cpp Normal file
View File

@ -0,0 +1,61 @@
#include<stdio.h>
#include<algorithm>
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 );
}
}

104
HDOJ/1053_autoAC.cpp Normal file
View File

@ -0,0 +1,104 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
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<TreeNode> que;
queue<TreeNode> 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<len; i++){
if(str[i-1] == str[i]){
count++;
}
else{
t.count = count;
que.push(t);
t.ch = str[i];
count = 1;
}
}
t.count = count;
que.push(t);
res = 0;
if(que.size() == 1){
printf("%d %d 8.0\n", 8*len, len);
que.pop();
}
else{
hoffman();
printf("%d %d %.1lf\n", 8*len, res, 8*len*1.0/res);
}
}
return 0;
}

63
HDOJ/1054_autoAC.cpp Normal file
View File

@ -0,0 +1,63 @@
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;
bool used[1510];
int con[1510];
vector<int> 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;
}

43
HDOJ/1055_autoAC.cpp Normal file
View File

@ -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;
}

24
HDOJ/1056_autoAC.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <cstdlib>
#include <iostream>
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<<circleA+1<<" card(s)"<<endl;
break;
}
}
}
return 0;
}

48
HDOJ/1057_autoAC.cpp Normal file
View File

@ -0,0 +1,48 @@
#include <iostream>
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<day;++k)
{
for(i=0;i<20;++i)
for(j=0;j<20;++j)
{
index=Map[i][j];
for(d=0;d<4;++d)
{
x = i+Dir[d][0];
y = j+Dir[d][1];
if(x>=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<<density[Map[i][j]];
cout<<endl;
}
if(t<T)cout<<endl;
}
return 0;
}

39
HDOJ/1058_autoAC.cpp Normal file
View File

@ -0,0 +1,39 @@
#include<iostream>
#include<cstdio>
#include<cstring>
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;
}

46
HDOJ/1059_autoAC.cpp Normal file
View File

@ -0,0 +1,46 @@
#include<stdio.h>
#include<limits.h>
#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<k;i++)
{
for(j=sum;j>=w[i];j--)
{
if(bag[j]<bag[j-w[i]]+w[i])
bag[j]=bag[j-w[i]]+w[i];
}
}
if(bag[sum]>=0)
printf("Can be divided.\n\n");
else
printf("Can't be divided.\n\n");
}
return 0;
}

20
HDOJ/1060_autoAC.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <iostream>
#include <math.h>
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<<a<<endl;
}
}
return 0;
}