Powered By HC TECH : AutoACer Engine

This commit is contained in:
unknown 2016-08-12 10:16:59 +08:00
parent a4c9e2129a
commit 9564705865
10 changed files with 578 additions and 0 deletions

18
HDOJ/1071_autoAC.cpp Normal file
View File

@ -0,0 +1,18 @@
#include<stdio.h>
#include<math.h>
int main()
{
int T;
double x1, x2, x3, y1, y2, y3, a, b, c, s;
scanf("%d",&T);
while(T--)
{
scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
a = ((y2-y1)*(x3-x2)/(x2-x1)-(y3-y2))/((x2*x2-x1*x1)*(x3-x2)/(x2-x1)-(x3*x3-x2*x2));
b = ((y2-y1)-a*(x2*x2-x1*x1))/(x2-x1);
c = y1-a*x1*x1-b*x1;
s = (a/3*x3*x3*x3+b/2*x3*x3+c*x3)-(a/3*x2*x2*x2+b*x2*x2/2+c*x2)-(y3+y2)*(x3-x2)/2;
printf("%.2lf\n",s);
}
return 0;
}

88
HDOJ/1072_autoAC.cpp Normal file
View File

@ -0,0 +1,88 @@
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
using namespace std;
struct node
{
int x, y;
int step;
int t;
};
const int maxn = 9;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int maze[maxn][maxn], graph[maxn][maxn];
int n, m, ex, ey, ans;
bool bfs(int x, int y);
int main()
{
int test;
scanf("%d", &test);
while(test-- != 0)
{
scanf("%d %d", &n, &m);
int sx, sy;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
scanf("%d", &maze[i][j]);
if(maze[i][j] == 2)
sx = i, sy = j;
if(maze[i][j] == 3)
ex = i, ey = j;
graph[i][j] = 0;
}
}
if(bfs(sx, sy))
printf("%d\n", ans);
else
printf("-1\n");
}
return 0;
}
bool bfs(int x, int y)
{
queue<node> que;
node s;
s.x = x;
s.y = y;
s.step = 0;
s.t = 6;
graph[x][y] = 6;
que.push(s);
while(!que.empty())
{
node st = que.front();
que.pop();
if(st.x == ex && st.y == ey)
{
ans = st.step;
return true;
}
if(st.t == 1)
continue;
for(int i = 0; i < 4; i++)
{
int dx = st.x + dir[i][0];
int dy = st.y + dir[i][1];
if(dx >= 0 && dx < n && dy >= 0 && dy < m && maze[dx][dy] != 0)
{
node tmp;
tmp.x = dx; tmp.y = dy;
tmp.step = st.step + 1;
tmp.t = st.t - 1;
if(maze[dx][dy] == 4)
tmp.t = 6;
if(tmp.t > graph[dx][dy])
{
graph[dx][dy] = tmp.t;
que.push(tmp);
}
}
}
}
return false;
}

59
HDOJ/1073_autoAC.cpp Normal file
View File

@ -0,0 +1,59 @@
#include<iostream>
#define N 10000
char str1[N],str2[N];
void input(char *str)
{
char tmp[N];
getchar();
gets(tmp);
while(gets(tmp) && strcmp(tmp,"END"))
{
if(strlen(tmp)==0)
strcat(str,"\n");
else
strcat(str,tmp);
}
}
void dechar(char *str,int len)
{
char tmp[N];
int t=0;
for(int i=0;i<len;i++)
if(!(str[i]==' ' || str[i]=='\t' || str[i]=='\n'))
tmp[t++]=str[i];
tmp[t]='\0';
strcpy(str,tmp);
}
int cmp()
{
int n1,n2;
n1=strlen(str1);
n2=strlen(str2);
if(n1==n2 && !strcmp(str1,str2))
return 1;
dechar(str1,n1);
dechar(str2,n2);
if(!strcmp(str1,str2))
return 0;
else
return -1;
}
int main()
{
int t,res;
while(scanf("%d",&t)!=EOF)
{
while(t--)
{
memset(str1,0,sizeof(str1));
memset(str2,0,sizeof(str2));
input(str1);
input(str2);
res=cmp();
if(res==1) puts("Accepted");
else if(res==0) puts("Presentation Error");
else if(res==-1) puts("Wrong Answer");
}
}
return 0;
}

68
HDOJ/1074_autoAC.cpp Normal file
View File

@ -0,0 +1,68 @@
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
const int N = 16;
int dp[1<<N];
struct Node
{
string s;
int time,cost;
};
Node a[N];
int pre[1<<N];
int n;
void Output(int status)
{
if(status==0)return;
int t=0;
for(int i=0;i<n;i++)
if( (status&(1<<i))!=0 && (pre[status]&(1<<i))==0 )
{
t=i;
break;
}
Output(pre[status]);
cout<<a[t].s<<endl;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
cin>>a[i].s>>a[i].time>>a[i].cost;
}
memset(dp,0x3f3f3f3f,sizeof(dp));
memset(pre,0,sizeof(pre));
dp[0]=0;
for(int st=0;st<(1<<n);st++)
{
int tmp=0;
for(int i=0;i<n;i++)
{
if(st&(1<<i))
tmp+=a[i].cost;
}
for(int i=0;i<n;i++)
{
//printf("fff %d %d %d",st,(1<<i),st&(1<<i));
if((st&(1<<i))==0)
{
if(dp[st|(1<<i)]>dp[st]+max(0,tmp+a[i].cost-a[i].time)){
dp[st|(1<<i)]=dp[st]+max(0,tmp+a[i].cost-a[i].time);
pre[st|(1<<i)]=st;
}
}
}
}
printf("%d\n",dp[(1<<n)-1]);
Output((1<<n)-1);
}
return 0;
}

105
HDOJ/1075_autoAC.cpp Normal file
View File

@ -0,0 +1,105 @@
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#include<ctype.h>
typedef struct node
{
char s[50];
struct node *next[26];
}node;
node memory[1000000];
int k=0;
void insert(char *b,char *a,node *T)
{
int i,len,j,id;
node *p,*q;
p=T;
len=strlen(b);
for(i=0;i<len;++i)
{
id=b[i]-'a';
if(p->next[id]==NULL)
{
q=&memory[k++];
memset(q->s,'\0',sizeof(q->s));
for(j=0;j<26;++j)
q->next[j]=NULL;
p->next[id]=q;
}
p=p->next[id];
}
strcpy(p->s,a);
}
int search(char *t,node *T)
{
int id,i=0;
char *p=t;
node *q=T;
while(islower(p[i]))
{
id=p[i]-'a';
if(q->next[id]==NULL)
return 0;
else
{
q=q->next[id];
++i;
}
}
if(strlen(q->s))
{
printf("%s",q->s);
return 1;
}
return 0;
}
int main()
{
int i,len;
char a[50],b[50];
char c[4000];
node *T;
T=&memory[k++];
memset(T->s,'\0',sizeof(T->s));
for(i=1;i<26;++i)
T->next[i]=NULL;
while(scanf("%s",a)&&strcmp(a,"START")==0)
{
while(scanf("%s",a)&&strcmp(a,"END"))
{
scanf("%s",b);
insert(b,a,T);
}
while(scanf("%s",a)&&strcmp(a,"START")==0)
{
getchar();
while(gets(c))
{
if(strcmp(c,"END")==0)
return 0;
len=strlen(c);
for(i=0;i<len;++i)
{
if(!islower(c[i]))
printf("%c",c[i]);
else
{
if(!search(&c[i],T))
{
while(islower(c[i]))
printf("%c",c[i++]);
--i;
}
else
{
while(islower(c[i++]));
i-=2;
}
}
}
printf("\n");
}
}
}
return 0;
}

31
HDOJ/1076_autoAC.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <stdio.h>
int leapyear(int Y)
{
if((Y%4==0 && Y%100!=0) || (Y%400==0))
return 1;
else
return 0;
}
int main()
{
int Y,N,n,count;
scanf("%d",&n);
while(n--)
{
count=0;
scanf("%d%d",&Y,&N);
while(count<N)
{
if(leapyear(Y))
{
count++;
Y++;
}
else
{
Y++;
}
}
printf("%d\n",Y-1);
}
}

67
HDOJ/1077_autoAC.cpp Normal file
View File

@ -0,0 +1,67 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#define INF 1E9
using namespace std;
double X[301],Y[301];
int n,ans;
double x,y;
inline double c(int i)
{
return (X[i]-x)*(X[i]-x)+(Y[i]-y)*(Y[i]-y);
}
int calc()
{
int i,ans=0;
for(i=0;i<n;i++)
{
if(c(i)>1.0+1e-8)continue;
ans++;
}
return ans;
}
void center(int i,int j)
{
double x1=X[i]-X[j],y1=Y[i]-Y[j],len,k;
double a,b;
if(x1==0)
a=1,b=0;
else if (y1==0)
a=0,b=1;
else
{
k=-1/y1*x1;
len=sqrt(1+k*k);
a=1.0/len;
b=k/len;
}
len=1-(x1*x1+y1*y1)/4;
if(len<0)return;
len=sqrt(len);
x1=(X[i]+X[j])/2.0;y1=(Y[i]+Y[j])/2.0;
a*=len;b*=len;
x=x1+a;y=y1+b;
ans=max(ans,calc());
x=x1-a;y=y1-b;
ans=max(ans,calc());
}
int main()
{
int T;
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf",&X[i],&Y[i]);
ans=0;
for(i=0;i<n;i++)
for(j=i;j<n;j++)
center(i,j);
printf("%d\n",ans);
}
}

61
HDOJ/1078_autoAC.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <iostream>
#include <utility>
using namespace std;
const int N = 102;
int graph[N][N];
int collect[N][N];
int n, k, ans;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool isBound(int x, int y)
{
if(x < 0 || y < 0)
return false;
if(x >= n || y >= n)
return false;
return true;
}
int memory(pair<int, int> p )
{
int i, j, maxb = 0, tmax;
pair<int , int> cs;
if(collect[p.first][p.second] > 0)
return collect[p.first][p.second];
for(i = 0; i < 4; i++)
{
cs = p;
for(j = 0; j < k; j++)
{
cs.first += dir[i][0];
cs.second += dir[i][1];
if(!isBound(cs.first, cs.second))
break;
if(graph[cs.first][cs.second] > graph[p.first][p.second])
{
tmax = memory(cs);
if(tmax > maxb)
maxb = tmax;
}
}
}
collect[p.first][p.second] = maxb + graph[p.first][p.second];
return collect[p.first][p.second];
}
int main()
{
pair<int, int> p;
int i, j;
while(scanf("%d%d", &n, &k))
{
if(n == -1 && k == -1)
break;
for(i = 0; i < n; i++)
for(j = 0; j < n; j++)
{
scanf("%d", &graph[i][j]);
collect[i][j] = 0;
}
p.first = p.second = 0;
printf("%d\n", memory(p));
}
return 0;
}

15
HDOJ/1079_autoAC.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main(){
int yy,mm,dd;
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&yy,&mm,&dd);
if( ((mm + dd) & 1) ==0 )
puts("YES");
else if(dd==30 && ( mm == 9 || mm == 11))
puts("YES");
else puts("NO");
}
return 0;
}

66
HDOJ/1080_autoAC.cpp Normal file
View File

@ -0,0 +1,66 @@
#include <stdio.h>
int matrix[5][5] = {
{5, -1, -2, -1, -3},
{-1, 5, -3, -2, -4},
{-2, -3, 5, -2, -2},
{-1, -2, -2, 5, -1},
{-3, -4, -2, -1, 0},
};
char exchange[5] = {'A', 'C', 'G', 'T', ' '};
int Value (char m, char n){
int R, C;
int i;
for (i=0; i<5; ++i){
if (exchange[i] == m)
R = i;
if (exchange[i] == n)
C = i;
}
return matrix[R][C];
}
int Max (int a, int b, int c){
int max = (a > b) ? a : b;
return (max > c) ? max : c;
}
int Similarity (char str1[], int length1, char str2[], int length2){
int dp[110][110];
int i, j;
dp[0][0] = 0;
for (i=1; i<=length1; ++i)
dp[i][0] = dp[i-1][0] + Value (str1[i], ' ');
for (i=1; i<=length2; ++i)
dp[0][i] = dp[0][i-1] + Value (' ', str2[i]);
for (i=1; i<=length1; ++i){
for (j=1; j<=length2; ++j){
if (str1[i] == str2[j]){
dp[i][j] = dp[i-1][j-1] + Value (str1[i], str2[j]);
}
else{
dp[i][j] = Max (dp[i-1][j] + Value (str1[i], ' '),
dp[i][j-1] + Value (' ', str2[j]),
dp[i-1][j-1] + Value (str1[i], str2[j]));
}
}
}
return dp[length1][length2];
}
int main(void){
char str1[110];
char str2[110];
int length1;
int length2;
int T;
int ans;
while (scanf ("%d", &T) != EOF){
while (T-- != 0){
scanf ("%d%s", &length1, str1 + 1);
scanf ("%d%s", &length2, str2 + 1);
if (length1 > length2)
ans = Similarity (str1, length1, str2, length2);
else
ans = Similarity (str2, length2, str1, length1);
printf ("%d\n", ans);
}
}
return 0;
}