Powered By HC TECH : AutoACer Engine

This commit is contained in:
KiritoTRw 2016-08-12 10:16:11 +08:00 committed by GitHub
parent 4bf3126523
commit ed61b5abf1
10 changed files with 512 additions and 0 deletions

32
HDOJ/1061_autoAC.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <iostream>
#include <stdio.h>
using namespace std;
bool l[10];
int r[10];
int main()
{
int t;
while(cin>>t)
{
while(t--)
{
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
unsigned long n;
cin>>n;
int a=n%10;
int b=a;
int i=1;
l[b]=true;r[0]=b;
b=(b*a)%10;
while(!l[b])
{
l[b]=true;
r[i++]=b;
b=(b*a)%10;
}
cout<<r[(n-1)%i]<<endl;
}
}
return 0;
}

42
HDOJ/1062_autoAC.cpp Normal file
View File

@ -0,0 +1,42 @@
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
const int Max = 1000 + 10;
char str[Max];
char w[Max];
int main()
{
int cases;
cin >> cases;
char c = getchar();
while(cases--)
{
gets(str);
int pos = 0;
int len = strlen(str);
for(int i=0; i<=len; i++)
{
if(str[i] == ' ')
{
w[pos++] = '\0';
strrev(w);
printf("%s ", w);
pos = 0;
}
else if(str[i] == '\0')
{
w[pos++] = '\0';
strrev(w);
printf("%s", w);
pos = 0;
}
else
{
w[pos++] = str[i];
}
}
printf("\n");
}
return 0;
}

76
HDOJ/1063_autoAC.cpp Normal file
View File

@ -0,0 +1,76 @@
#include <iostream>
using namespace std;
const int MAX_LEN=1000;
int temp[1000];
void mul(char* z,char* x,char* y)
{
int lenx=strlen(x);
int leny=strlen(y);
int i,j;
memset(temp,0,1000*4);
for(i=0;i<lenx;i++)
for(j=0;j<leny;j++)
temp[i+j]+=(x[lenx-1-i]-'0')*(y[leny-1-j]-'0');
memset(z,0,1000);
for(i=0;(i<lenx+leny-1) || temp[i]>9;i++)
{
if(temp[i]>9)
temp[i+1]+=temp[i]/10;
z[i]=temp[i]%10+'0';
}
z[i]=temp[i]+'0';
z[i+1]=0;
while(z[i]=='0' && i)
z[i--]=0;
_strrev(z);
}
int main()
{
char t[1000];
char s[7];
int i,n,dot,len,integer;
while(cin>>s>>n)
{
dot=-1;
integer=0;
for(i=0;i<6;i++)
if(s[i]=='.')
{
dot=i;
for(;i<6;i++)
{
s[i]=s[i+1];
if(s[i]==0)
break;
}
while(s[--i]=='0' && i>=dot)
s[i]=0;
dot=strlen(s)-dot;
if(dot==0)
integer=1;
break;
}
if(dot==-1)
integer=1;
memset(t,0,1000);
t[0]='1';
for(i=0;i<n;i++)
mul(t,t,s);
len=int(strlen(t))-dot*n;
if(integer)
cout<<t<<endl;
else if(len>0)
{
for(i=0;i<len;i++)
cout<<t[i];
cout<<'.'<<t+len<<endl;
}
else
{
cout<<'.';
for(i=0;i<-len;i++)
cout<<'0';
cout<<t<<endl;
}
}
}

14
HDOJ/1064_autoAC.cpp Normal file
View File

@ -0,0 +1,14 @@
#include<stdio.h>
int main()
{
double avg,cache;
int i;
avg=cache=0;
for(i=0;i<12;i++)
{
scanf("%lf",&cache);
avg+=cache;
}
printf("$%.2lf\n",avg/12);
return 0;
}

17
HDOJ/1065_autoAC.cpp Normal file
View File

@ -0,0 +1,17 @@
#include<iostream>
#include<math.h>
#define PI 3.1415926
using namespace std;
int main(){
int m;
double x, y;
cin>>m;
for(int i = 0; i < m; i++){
cin>>x>>y;
double s = PI * (x * x + y * y);
int count = s / 100 + 1;
cout<<"Property "<<i + 1<<
": This property will begin eroding in year "<<count<<"."<<endl;
}
cout<<"END OF OUTPUT."<<endl;
}

43
HDOJ/1066_autoAC.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int Lib[4]={6,2,4,8};
const int fact[10]={1,1,2,6,4,2,2,4,2,8};
char s[200];
int a[200];
void todigit(char s[],int a[])
{
a[2]=0;
a[0]=strlen(s);
for (int i=0; i<a[0]; i++) a[a[0]-i]=s[i]-'0';
}
void mult(int a[],int x)
{
int j=0;
for (int i=a[0]; i>0; i--)
{
int k1=(j*10+a[i])/x;
j=(j*10+a[i])%x;
a[i]=k1;
}
while (a[0]>1 && a[a[0]]==0) a[0]--;
}
int last_nunzero(int a[])
{
if (a[0]==1) return fact[a[1]];
int x1=fact[a[1]%5];
mult(a,5);
int x2=Lib[(a[2]*10+a[1])%4];
int ret=(x1*x2*last_nunzero(a))%10;
return ret;
}
int main()
{
while (gets(s))
{
todigit(s,a);
printf("%d\n",last_nunzero(a));
}
return 0;
}

143
HDOJ/1067_autoAC.cpp Normal file
View File

@ -0,0 +1,143 @@
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#define ll __int64
#define MAX 1000009
using namespace std;
ll has[1000009];
ll b[4][8],op[32];
ll endval,start;
struct lmx{
ll arr[4][8];
ll val;
ll step;
ll blankx[4];
ll blanky[4];
};
ll a[4][8]=
{
{11,12,13,14,15,16,17},
{21,22,23,24,25,26,27},
{31,32,33,34,35,36,37},
{41,42,43,44,45,46,47}
};
ll _cnt(ll c[][8])
{
ll s=0,i,j;
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
s+=c[i][j]*op[8*i+j];
}
}
return s;
}
void exchange(ll c[][8])
{
ll i,j;
for(i=0;i<4;i++)
{
for(j=1;j<8;j++)
{
if(c[i][j]==11) swap(c[0][0],c[i][j]);
else if(c[i][j]==21) swap(c[1][0],c[i][j]);
else if(c[i][j]==31) swap(c[2][0],c[i][j]);
else if(c[i][j]==41) swap(c[3][0],c[i][j]);
}
}
}
bool ihash(ll val)
{
ll p=val%MAX;
while(has[p]!=-1&&has[p]!=val)
{
p=(p+20)%MAX;
}
if(has[p]==-1){has[p]=val;return true;}
return false;
}
void input()
{
int i,j;
for(i=0;i<4;i++)
{
for(j=1;j<8;j++)
{
scanf("%I64d",&b[i][j]);
}
b[i][0]=0;
}
}
lmx s,h,t;
queue<lmx> q;
ll bfs()
{
ll i,j,cnt=0,k,f=0,v,pos1,pos2,xx,yy;
if(start==endval) return 0;
while(!q.empty()) q.pop();
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
if(b[i][j]==0) {s.blankx[cnt]=i;s.blanky[cnt]=j;cnt++;}
}
}
memcpy(s.arr,b,sizeof(b));
s.step=0;
s.val=_cnt(b);
has[s.val%MAX]=s.val;
q.push(s);
while(!q.empty())
{
h=q.front();
q.pop();
for(i=0;i<4;i++)
{
t=h;
xx=h.blankx[i];
yy=h.blanky[i];
for(j=0;j<4;j++)
{
for(k=0;k<8;k++)
{
if(h.arr[xx][yy-1]+1==h.arr[j][k])
{
pos1=j;pos2=k;
swap(t.arr[pos1][pos2],t.arr[xx][yy]);
v=_cnt(t.arr);
t.blankx[i]=pos1;
t.blanky[i]=pos2;
if(ihash(v))
{
t.step=h.step+1;
t.val=v;
if(v==endval) return t.step;
q.push(t);
}
}
}
}
}
}
return -1;
}
int main()
{
ll i,j,n;
scanf("%I64d",&n);
op[0]=2;
for(i=1;i<32;i++) op[i]=op[i-1]<<1;
while(n--)
{
input();
exchange(b);
endval=_cnt(a);
start=_cnt(b);
memset(has,-1,sizeof(has));
printf("%I64d\n",bfs());
}
return 0;
}

45
HDOJ/1068_autoAC.cpp Normal file
View File

@ -0,0 +1,45 @@
#include <iostream>
using namespace std;
const int MAX = 500;
bool visited[MAX];
bool linked[MAX][MAX];
int arossPath[MAX];
int n;
bool search(int u) {
for (int i = 0; i < n; i++) {
if (!visited[i]&& linked[i][u]) {
visited[i] = true;
if (arossPath[i] == -1 || search(arossPath[i])) {
arossPath[i] = u;
return true;
}
}
}
return false;
}
int maxMatch() {
int count = 0;
memset(arossPath, -1, sizeof(arossPath));
for (int i = 0; i < n; i++) {
memset(visited, false, sizeof(visited));
if (search(i))
count++;
}
return count;
}
int main()
{
int k, a, b;
while (scanf("%d", &n) != EOF) {
memset(linked, false, sizeof(linked));
for (int i = 0; i < n; i++) {
scanf("%d: (%d)", &a, &k);
while (k--) {
scanf("%d", &b);
linked[a][b] = true;
}
}
cout << (n - maxMatch()/2) << endl;
}
return 0;
}

58
HDOJ/1069_autoAC.cpp Normal file
View File

@ -0,0 +1,58 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
int x;
int y;
int z;
}block;
block blocks[100];
int dp[100];
int cmp(const void *a, const void *b)
{
return (*(block*)a).x * (*(block*)a).y - (*(block*)b).x * (*(block*)b).y;
}
int isFeasible(const block a, const block b)
{
if((a.x>b.x && a.y>b.y) || (a.x>b.y && a.y>b.x)){
return 1;
}
else{
return 0;
}
}
int main()
{
int n, i, j;
int x, y, z;
int cas, max;
cas = 0;
while(scanf("%d", &n)!=EOF && n!=0){
cas++;
for(i=0; i<3*n; i++){
scanf("%d%d%d", &x, &y, &z);
blocks[i].x = x; blocks[i].y = y; blocks[i].z = z; i++;
blocks[i].x = y; blocks[i].y = z; blocks[i].z = x; i++;
blocks[i].x = z; blocks[i].y = x; blocks[i].z = y;
}
qsort(blocks, 3*n, sizeof(block), cmp);
memset(dp, 0, sizeof(dp));
dp[0] = blocks[0].z;
max = dp[0];
for(i=1; i<3*n; i++){
dp[i] = blocks[i].z;
for(j=i-1; j>=0; j--){
if(isFeasible(blocks[i], blocks[j])){
if(dp[i] < dp[j] + blocks[i].z){
dp[i] = dp[j] + blocks[i].z;
}
}
}
if(dp[i] > max){
max = dp[i];
}
}
printf("Case %d: maximum height = %d\n", cas, max);
}
return 0;
}

42
HDOJ/1070_autoAC.cpp Normal file
View File

@ -0,0 +1,42 @@
#include <iostream>
#include <string>
using namespace std;
int main()
{
int T, n, money, v, day;
int vmin;
double imin, temp;
string brand, strmin;
cin >> T;
while (T--) {
cin >> n;
imin = -1.0;
vmin = -1;
while (n--) {
cin >> brand >> money >> v;
if (v < 200) continue;
else {
day = (v >= 1000) ? 5 : v / 200;
temp = money*1.0/day;
if (imin == -1.0) {
imin = money*1.0/day;
vmin = v;
strmin = brand;
}
if (temp < imin) {
strmin = brand;
imin = money*1.0/day;
vmin = v;
}
else if (temp-imin > -0.000001 && temp-imin < 0.000001) {
if (vmin < v) {
strmin = brand;
vmin = v;
}
}
}
}
cout << strmin << endl;
}
return 0;
}