Merge pull request #29 from KiritoTRw/master

AutoACer Engine !
This commit is contained in:
Kirigaya Kazuto 2016-08-13 10:51:59 +08:00 committed by GitHub
commit 991104cf80
88 changed files with 4540 additions and 0 deletions

49
HDOJ/1081_autoAC.cpp Normal file
View File

@ -0,0 +1,49 @@
#include<iostream>
using namespace std;
int MaxSum1D(int *a, int n)
{
int sum = -128, b = 0;
int i;
for (i=0; i<n; ++i)
{
if(b > 0) b += a[i];
else b = a[i];
if(b > sum) sum = b;
}
return sum;
}
int MaxSum2D(int a[][101], int m, int n)
{
int sum = -128;
int i, j, k;
int *b = new int[n+1];
for (i=0; i<m; ++i)
{
for (k=0; k<n; ++k) b[k] = 0;
for (j=i; j<m; ++j)
{
for (k=0; k<n; ++k) b[k] += a[j][k];
int Max = MaxSum1D(b, n);
if(Max > sum)
sum = Max;
}
}
return sum;
}
int main()
{
int n, i, j;
int a[101][101];
while (cin >> n)
{
for (i=0; i<n; ++i)
{
for (j=0; j<n; ++j)
{
cin >> a[i][j];
}
}
cout << MaxSum2D(a, n, n) << endl;
}
return 0;
}

63
HDOJ/1082_autoAC.cpp Normal file
View File

@ -0,0 +1,63 @@
#include <iostream>
#include <stack>
using namespace std;
const int MATRIX_LEN = 30;
const int INPUT_LEN = 200;
class Matrix
{
public:
char name[2];
int row, col;
};
Matrix matrices[MATRIX_LEN];
stack<Matrix> stackMatrices;
int main ()
{
int matricesNum;
scanf("%d",&matricesNum);
Matrix aMatrix;
for (int i = 0;i < matricesNum;i ++)
{
scanf("%s%d%d",aMatrix.name,&aMatrix.row,&aMatrix.col);
int pos = aMatrix.name[0] - 'A';
matrices[pos] = aMatrix;
}
char input[INPUT_LEN];
while (scanf("%s",input) != -1)
{
while ( ! stackMatrices.empty())
stackMatrices.pop();
int totalMultiCount = 0;
int isError = 0;
Matrix left, right;
for (int i = 0;i < strlen(input);i ++)
{
if (isalpha(input[i]))
{
aMatrix = matrices[ input[i] - 'A' ];
stackMatrices.push(aMatrix);
continue;
}
if (input[i] == '(')
continue;
right = stackMatrices.top();
stackMatrices.pop();
left = stackMatrices.top();
stackMatrices.pop();
if (left.col != right.row)
{
isError = 1;
break;
}
totalMultiCount += left.row * left.col * right.col;
aMatrix.row = left.row;
aMatrix.col = right.col;
stackMatrices.push(aMatrix);
}
if (isError)
printf("error\n");
else
printf("%d\n",totalMultiCount);
}
return 0;
}

61
HDOJ/1083_autoAC.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <iostream>
#include <vector>
using namespace std;
const int STUDENT_NUM = 305;
const int COURSE_NUM = 105;
int augmentedPathsNum;
int mapping[COURSE_NUM];
int isVisited[COURSE_NUM];
vector<int> coursesAttend[STUDENT_NUM];
int DFS_isAugmentedPathExist(int studentId)
{
for (int i = 0;i < coursesAttend[studentId].size();i ++)
{
int courseId = coursesAttend[studentId][i];
if (isVisited[courseId] != 0)
continue;
isVisited[courseId] = 1;
if (mapping[courseId] == -1 || DFS_isAugmentedPathExist(mapping[courseId]))
{
mapping[courseId] = studentId;
return 1;
}
}
return 0;
}
int main ()
{
int casesNum;
scanf("%d",&casesNum);
for (int i = 1;i <= casesNum;i ++)
{
int coursesNum, studentsNum;
scanf("%d%d", &coursesNum, &studentsNum);
for (int j = 1;j <= studentsNum;j ++)
coursesAttend[j].clear();
for (int j = 1;j <= coursesNum;j ++)
{
int studentsNumOfCourse;
scanf("%d",&studentsNumOfCourse);
for (int k = 1;k <= studentsNumOfCourse;k ++)
{
int studentId;
scanf("%d",&studentId);
coursesAttend[studentId].push_back(j);
}
}
memset(mapping, -1, sizeof(mapping));
augmentedPathsNum = 0;
for (int j = 1;j <= studentsNum;j ++)
{
memset(isVisited, 0, sizeof(isVisited));
if ( DFS_isAugmentedPathExist(j) == 1 )
augmentedPathsNum ++;
}
if (augmentedPathsNum == coursesNum)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}

46
HDOJ/1084_autoAC.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <cstdio>
#include <algorithm>
using std::sort;
struct Node{
int pos, num, s, val;
} stu[102];
int arr[6];
bool cmp1(Node a, Node b)
{
if(a.num == b.num) return a.s < b.s;
return a.num > b.num;
}
bool cmp2(Node a, Node b)
{
return a.pos < b.pos;
}
int main()
{
int n, h, m, s, num;
while(scanf("%d", &n) == 1 && n > 0){
for(int i = 1; i < 6; ++i) arr[i] = 0;
for(int i = 0; i < n; ++i){
scanf("%d %d:%d:%d", &num, &h, &m, &s);
s += m * 60 + h * 3600;
stu[i].pos = i;
stu[i].num = num;
stu[i].s = s;
stu[i].val = 100 - (5 - num) * 10;
++arr[num];
}
sort(stu, stu + n, cmp1);
for(int i = 4, pos = 0; i; --i){
if(arr[i]){
while(stu[pos].num != i) ++pos;
if(arr[i] == 1) stu[pos++].val += 5;
for(int j = 0; j < arr[i] / 2; ++j)
stu[pos++].val += 5;
}
}
sort(stu, stu + n, cmp2);
for(int i = 0; i < n; ++i)
printf("%d\n", stu[i].val);
printf("\n");
}
return 0;
}

24
HDOJ/1085_autoAC.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <iostream>
using namespace std;
bool money[8002];
int main()
{
unsigned numFive,numTwo,numOne;
while(cin>>numOne>>numTwo>>numFive)
{
if(numOne==0&&numTwo==0&&numFive==0)
break;
memset(money,0,sizeof(bool)*(8002));
for(unsigned i=0;i<=numFive;i++)
for(unsigned j=0;j<=numTwo;j++)
for(unsigned k=0;k<=numOne;k++)
money[k+j*2+i*5]=true;
for(int i=1;i<=8001;i++)
if(money[i]==false)
{
cout<<i<<endl;
break;
}
}
return 0;
}

40
HDOJ/1086_autoAC.cpp Normal file
View File

@ -0,0 +1,40 @@
#include<iostream>
#include<stdio.h>
using namespace std;
const int Max = 110;
struct Point
{
double x, y;
};
struct Segment
{
Point s, e;
};
Segment s[Max];
double product(Point &a, Point &b, Point &c)
{
double x1, y1, x2, y2;
x1 = a.x - c.x, y1 = a.y - c.y;
x2 = b.x - c.x, y2 = b.y - c.y;
return x1 * y2 - y1 * x2;
}
bool intersect(Segment &a, Segment &b)
{
return product(a.s, a.e, b.s) * product(a.s, a.e, b.e) <= 0 &&
product(b.s, b.e, a.s) * product(b.s, b.e, a.e) <= 0;
}
int main()
{
int n, cnt;
while(scanf("%d", &n) && n)
{
for(int i=0; i<n; i++)
scanf("%lf %lf %lf %lf", &s[i].s.x, &s[i].s.y, &s[i].e.x, &s[i].e.y);
cnt = 0;
for(int i=0; i<n; i++)
for(int j=i+1; j<n; j++)
if(intersect(s[i], s[j])) cnt ++;
printf("%d\n", cnt);
}
return 0;
}

40
HDOJ/1087_autoAC.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <iostream>
using namespace std;
int main()
{
int i,j,k,l,n,m,t;
int a[1002],b[1002] = {0};
while (scanf("%d",&n)!=EOF && n)
{
for (i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
memset(b,0,sizeof(b));
int sum = 0;
k=0;
int maxnum = -1;
for (i=0;i<n;i++)
{
b[i] = a[i];
int maxb = 0;
for (j=0;j<i;j++)
{
if (a[i] > a[j])
{
if (b[j] > maxb)
{
maxb = b[j];
}
}
}
b[i] += maxb;
if (b[i] > maxnum)
{
maxnum = b[i];
}
}
printf("%d\n",maxnum);
}
return 0;
}

37
HDOJ/1088_autoAC.cpp Normal file
View File

@ -0,0 +1,37 @@
#include<cstdio>
#include<cstring>
char a[81];
int main()
{
int p=0;
while(scanf("%s",a+1)!=EOF)
{
int len=strlen(a+1);
if(a[1]=='<')
{
if(a[2]=='b')printf("\n");
else{
if(p)printf("\n");
for(int i=1;i<=80;i++)printf("-");
printf("\n");
}
p=0;
}else if(p==0)
{
for(int i=1;i<=len;i++)printf("%c",a[i]);
p=len;
}else if(p+len>=80)
{
printf("\n");
for(int i=1;i<=len;i++)printf("%c",a[i]);
p=len;
}else
if(p+len<80){
printf(" ");
for(int i=1;i<=len;i++)printf("%c",a[i]);
p+=len+1;
}
}
printf("\n");
return 0;
}

10
HDOJ/1089_autoAC.cpp Normal file
View File

@ -0,0 +1,10 @@
#include<stdio.h>
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
printf("%d\n",a+b);
}
return 0;
}

11
HDOJ/1090_autoAC.cpp Normal file
View File

@ -0,0 +1,11 @@
#include <stdio.h>
int main(void)
{
int a, b, n;
scanf("%d", &n);
while(n--&&scanf("%d%d", &a, &b))
{
printf("%d\n", a + b);
}
return 0;
}

12
HDOJ/1091_autoAC.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
int main(void)
{
int a, b;
scanf("%d%d", &a, &b);
while(a != 0 || b != 0)
{
printf("%d\n", a + b);
scanf("%d%d", &a, &b);
}
return 0;
}

16
HDOJ/1092_autoAC.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
int main(void)
{
int a, n, i, sum;
while(scanf("%d", &n) && n != 0)
{
sum = 0;
for(i = 0; i < n; i ++)
{
scanf("%d", &a);
sum = sum + a;
}
printf("%d\n", sum);
}
return 0;
}

20
HDOJ/1093_autoAC.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
int main()
{
int n, m, a, sum, i, j;
while(scanf("%d", &n) != EOF)
{
for(i = 0; i < n; i ++)
{
scanf("%d", &m);
sum = 0;
for(j = 0; j < m; j ++)
{
scanf("%d", &a);
sum = sum + a;
}
printf("%d\n", sum);
}
}
return 0;
}

16
HDOJ/1094_autoAC.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
int main(void)
{
int n, a, sum, i;
while(scanf("%d", &n) != EOF)
{
sum = 0;
for(i = 0; i < n; i ++)
{
scanf("%d", &a);
sum = sum + a;
}
printf("%d\n", sum);
}
return 0;
}

12
HDOJ/1095_autoAC.cpp Normal file
View File

@ -0,0 +1,12 @@
#include <stdio.h>
int main(void)
{
int a, b, i = 0;
while(i < 5)
{
scanf("%d%d", &a, &b);
printf("%d\n\n", a + b);
i ++;
}
return 0;
}

20
HDOJ/1096_autoAC.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
int main(void)
{
int n, m, a, sum, i, j;
scanf("%d", &n);
for(i = 0; i < n; i ++)
{
scanf("%d", &m);
sum = 0;
for(j = 0; j < m; j ++)
{
scanf("%d", &a);
sum = sum + a;
}
printf("%d\n", sum);
if(i != n - 1)
printf("\n");
}
return 0;
}

23
HDOJ/1097_autoAC.cpp Normal file
View File

@ -0,0 +1,23 @@
#include <iostream>
using namespace std;
int main()
{
int a,b;
while(scanf("%d%d",&a,&b)!=EOF)
{
a%=10;
if(a==0||a==5||a==6||a==1) printf("%d\n",a);
else if(a==4||a==9)
{
printf("%d\n",b%2==0?a*a%10:a);
}
else
{
if(b%4==1) printf("%d\n",a);
else if(b%4==2) printf("%d\n",a*a%10);
else if(b%4==3) printf("%d\n",a*a*a%10);
else printf("%d\n",a*a*a*a%10);
}
}
return 0;
}

24
HDOJ/1098_autoAC.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <iostream>
using namespace std;
int main()
{
int k,a;
while(cin>>k)
{
if(k%65==0)
{
cout<<"no"<<endl;
continue;
}
for(a=0;a<65;++a)
{
if((a*k)%65==47)
{
cout << a << endl;
break;
}
}
if(a==65) cout << "no" <<endl;
}
return 0;
}

60
HDOJ/1099_autoAC.cpp Normal file
View File

@ -0,0 +1,60 @@
#include<stdio.h>
#include<string.h>
typedef __int64 ll;
ll gcd(ll a,ll b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
return a/gcd(a,b)*b;
}
ll numlen(ll n)
{
ll l=0;
while(n)
{
n=n/10;
l++;
}
return l;
}
int main()
{
ll n,son,mother,g,d,i;
while(scanf("%I64d",&n)!=EOF)
{
mother=1,son=0;
for(i=1;i<=n;i++)
mother=lcm(mother,i);
for(i=1;i<=n;i++)
son=son+mother/i;
son=son*n;
g=gcd(mother,son);
son=son/g;
mother=mother/g;
d=son/mother;
son=son%mother;
if(son==0)
{
printf("%d\n",d);
continue;
}
ll l1=numlen(d);
ll l2=numlen(mother);
for(i=0;i<=l1;i++)
printf(" ");
printf("%I64d\n",son);
printf("%I64d ",d);
for(i=1;i<=l2;i++)
printf("-");
printf("\n");
for(i=0;i<=l1;i++)
printf(" ");
printf("%I64d\n",mother);
}
return 0;
}

68
HDOJ/1100_autoAC.cpp Normal file
View File

@ -0,0 +1,68 @@
#include<stdio.h>
__int64 array[21];
int init()
{
array[0]=1;
array[1]=1;
for(int i=2;i<=20;i++)
{
array[i]=0;
for(int j=0;j<i;j++)
{
array[i]+=array[j]*array[i-j-1];
}
}
return 0;
}
int dfs(int num,__int64 n)
{
for(int i=0;i<=num-1;i++)
{
if(n>array[i]*array[num-1-i])
{
n-=array[i]*array[num-1-i];
}
else
{
__int64 x=n%array[num-1-i]==0?n/array[num-1-i]:n/array[num-1-i]+1;
if(i!=0)
{
printf("(");
dfs(i,x);
printf(")");
}
printf("X");
if(num-1-i!=0)
{
printf("(");
dfs(num-1-i,n-array[num-1-i]*(x-1));
printf(")");
}
return 0;
}
}
return 0;
}
int main()
{
__int64 n;
init();
while(scanf("%I64d",&n)!=EOF&&n>0)
{
__int64 temp=0;
int num;
for(int i=1;i<=20;i++)
{
if(temp+array[i]>=n)
{
n-=temp;
num=i;
break;
}
temp+=array[i];
}
dfs(num,n);
printf("\n");
}
return 0;
}

71
HDOJ/1102_autoAC.cpp Normal file
View File

@ -0,0 +1,71 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#define max 0x7fffffff
using namespace std;
struct edge
{
int v1;
int v2;
int w;
}e[6000];
int cmp(const void *a,const void *b)
{
struct edge *aa=(struct edge *)a;
struct edge *bb=(struct edge *)b;
if(aa->w != bb->w)
return aa->w - bb->w;
else
return aa->v1 - bb->v1;
}
int main()
{
int n,q,a,b,map[101][101],vis[101],i,j,k,min;//map璁板绘ョ╅碉vis涓洪《硅剧疆蹇
while(scanf("%d",&n)!=EOF)
{
min=0;
for(i=1;i<=n;i++) vis[i]=i;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&map[i][j]);
}
map[i][i]=max;
}
scanf("%d",&q);
for(i=1;i<=q;i++)
{
scanf("%d%d",&a,&b);
map[a][b]=map[b][a]=0;
}
for(i=1,k=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
e[k].v1=i;
e[k].v2=j;
e[k].w=map[i][j];
k++;
}
}
qsort(&e[1],k-1,sizeof(e[1]),cmp);
for(i=1,j=1;j<n;i++)
{
if(vis[e[i].v1] != vis[e[i].v2])
{
int m=vis[e[i].v1]>vis[e[i].v2] ? vis[e[i].v2] : vis[e[i].v1];
int M=vis[e[i].v1]>vis[e[i].v2] ? vis[e[i].v1] : vis[e[i].v2];
for(int ii=1;ii<=n;ii++)
{
if(vis[ii]==M)
vis[ii]=m;
}
min+=e[i].w;
j++;
}
}
printf("%d\n",min);
}
return 0;
}

118
HDOJ/1103_autoAC.cpp Normal file
View File

@ -0,0 +1,118 @@
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
int two,four,six,twotime[10000],threetime[10000];
int fourtime[10000],map[10000][3];
int a,b,c,d,i,j,k1,k2,k3,num,z,min,flash;
char str1[20];
while(~scanf("%d%d%d",&two,&four,&six))
{
if(two==0&&six==0&&four==0) break;
scanf("%s",str1);
for(i=1;str1[0]!='#';i++)
{
scanf("%d",&d);
a=(str1[0]-48)*10+str1[1]-48;
b=(str1[3]-48)*10+str1[4]-48;
map[i][1]=a*60+b;
map[i][2]=d;
scanf("%s",str1);
}
num=0;
for(j=1;j<=two;j++)
twotime[j]=0;
for(j=1;j<=four;j++)
threetime[j]=0;
for(j=1;j<=six;j++)
fourtime[j]=0;
for(j=1;j<i;j++)
{
if(map[j][2]<=2)
{
flash=0;
for(z=1;z<=two;z++)
if(map[j][1]>=twotime[z])
{
num+=map[j][2];
twotime[z]=map[j][1]+30;
flash=1;
break;
}
if(flash==0)
{
min=99999;
for(z=1;z<=two;z++)
if(twotime[z]-map[j][1]<min)
{
min=twotime[z]-map[j][1];
d=z;
}
if(min<=30)
{
num+=map[j][2];
twotime[d]+=30;
}
}
}
else if(map[j][2]>2&&map[j][2]<=4)
{
flash=0;
for(z=1;z<=four;z++)
if(map[j][1]>=threetime[z])
{
num+=map[j][2];
threetime[z]=map[j][1]+30;
flash=1;
break;
}
if(flash==0)
{
min=99999;
for(z=1;z<=four;z++)
if(threetime[z]-map[j][1]<min)
{
min=threetime[z]-map[j][1];
d=z;
}
if(min<=30)
{
num+=map[j][2];
threetime[d]+=30;
}
}
}
else
{
flash=0;
for(z=1;z<=six;z++)
if(map[j][1]>=fourtime[z])
{
num+=map[j][2];
fourtime[z]=map[j][1]+30;
flash=1;
break;
}
if(flash==0)
{
min=99999;
for(z=1;z<=six;z++)
if(fourtime[z]-map[j][1]<min)
{
min=fourtime[z]-map[j][1];
d=z;
}
if(min<=30)
{
num+=map[j][2];
fourtime[d]+=30;
}
}
}
}
printf("%d\n",num);
}
return 0;
}

24
HDOJ/1106_autoAC.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char s[1005];
int a[1005];
char * temp;
int cmp(const void *p1,const void *p2){
return *(int *)p1-*(int *)p2;
}
int main(){
int c;
while(gets(s)){
a[0]=atoi(strtok(s,"5"));
c=1;
while(temp=strtok(NULL,"5")){
a[c++]=atoi(temp);
}
qsort(a,c,sizeof a[0],cmp);
for(int i=0;i<c;i++){
printf(i==c-1?"%d\n":"%d ",a[i]);
}
}
return 0;
}

210
HDOJ/1107_autoAC.cpp Normal file
View File

@ -0,0 +1,210 @@
#include<stdio.h>
#include<string.h>
int w,s,e;
struct sl
{
int neili,wuyi,hp,dps,x,y,flag,fang;
}cuns[1005];
struct em
{
int neili,wuyi,hp,dps,x,y,flag,fang;
}cune[1005];
struct wd
{
int neili,wuyi,hp,dps,x,y,flag,fang;
}cunw[1005];
struct map
{
int sll,emm,wdd,slll,emmm,wddd;
}mmap[13][13];
void shaolingzou()
{
for(int i=0;i<s;i++)
{
if(cuns[i].flag==1)
{
if(cuns[i].x==12) cuns[i].fang=-1;
if(cuns[i].x==1) cuns[i].fang=1;
mmap[cuns[i].x][cuns[i].y].sll--;
cuns[i].x+=cuns[i].fang;
mmap[cuns[i].x][cuns[i].y].sll++;
mmap[cuns[i].x][cuns[i].y].slll=i;
}
}
}
void wudangzou()
{
for(int i=0;i<w;i++)
{
if(cunw[i].flag==1)
{
if(cunw[i].y==12) cunw[i].fang=-1;
if(cunw[i].y==1) cunw[i].fang=1;
mmap[cunw[i].x][cunw[i].y].wdd--;
cunw[i].y+=cunw[i].fang;
mmap[cunw[i].x][cunw[i].y].wdd++;
mmap[cunw[i].x][cunw[i].y].wddd=i;
}
}
}
void emeizou()
{
for(int i=0;i<e;i++)
{
if(cune[i].flag==1)
{
if(cune[i].x==12||cune[i].y==12) cune[i].fang=-1;
if(cune[i].x==1||cune[i].y==1) cune[i].fang=1;
if(cune[i].x==12&&cune[i].y==1) continue;
if(cune[i].y==12&&cune[i].x==1) continue;
mmap[cune[i].x][cune[i].y].emm--;
cune[i].x+=cune[i].fang;
cune[i].y+=cune[i].fang;
mmap[cune[i].x][cune[i].y].emm++;
mmap[cune[i].x][cune[i].y].emmm=i;
}
}
}
void slove()
{
for(int i=1;i<=12;i++)
for(int j=1;j<=12;j++)
{
if(mmap[i][j].sll+mmap[i][j].wdd+mmap[i][j].emm==2)
{
if(mmap[i][j].sll==1&&mmap[i][j].wdd==1)
{
int slll=mmap[i][j].slll;
int wddd=mmap[i][j].wddd;
cuns[slll].hp-=cunw[wddd].dps;
cunw[wddd].hp-=cuns[slll].dps;
double a=(0.8*cunw[wddd].neili+0.2*cunw[wddd].wuyi)*(cunw[wddd].hp+10)/100;
cunw[wddd].dps=(int)a;
double b=(0.5*cuns[slll].neili+0.5*cuns[slll].wuyi)*(cuns[slll].hp+10)/100;
cuns[slll].dps=(int)b;
if(cuns[slll].hp<=0) {cuns[slll].flag=0; mmap[i][j].sll--;}
if(cunw[wddd].hp<=0) {cunw[wddd].flag=0; mmap[i][j].wdd--;}
}
if(mmap[i][j].sll==1&&mmap[i][j].emm==1)
{
int slll=mmap[i][j].slll;
int emmm=mmap[i][j].emmm;
cuns[slll].hp-=cune[emmm].dps;
cune[emmm].hp-=cuns[slll].dps;
double b=(0.5*cuns[slll].neili+0.5*cuns[slll].wuyi)*(cuns[slll].hp+10)/100;
cuns[slll].dps=(int)b;
double c=(0.2*cune[emmm].neili+0.8*cune[emmm].wuyi)*(cune[emmm].hp+10)/100;
cune[emmm].dps=(int)c;
if(cuns[slll].hp<=0) {cuns[slll].flag=0; mmap[i][j].sll--;}
if(cune[emmm].hp<=0) {cune[emmm].flag=0; mmap[i][j].emm--;}
}
if(mmap[i][j].emm==1&&mmap[i][j].wdd==1)
{
int emmm=mmap[i][j].emmm;
int wddd=mmap[i][j].wddd;
cune[emmm].hp-=cunw[wddd].dps;
cunw[wddd].hp-=cune[emmm].dps;
double c=(0.2*cune[emmm].neili+0.8*cune[emmm].wuyi)*(cune[emmm].hp+10)/100;
cune[emmm].dps=(int)c;
double a=(0.8*cunw[wddd].neili+0.2*cunw[wddd].wuyi)*(cunw[wddd].hp+10)/100;
cunw[wddd].dps=(int)a;
if(cune[emmm].hp<=0) {cune[emmm].flag=0; mmap[i][j].emm--;}
if(cunw[wddd].hp<=0) {cunw[wddd].flag=0; mmap[i][j].wdd--;}
}
}
}
}
void clear()
{
memset(mmap,0,sizeof(mmap));
memset(cuns,0,sizeof(cuns));
memset(cunw,0,sizeof(cunw));
memset(cune,0,sizeof(cune));
}
int main()
{
int T,N;
char menpai[10];
scanf("%d",&T);
while(T--)
{
clear();
w=s=e=0;
scanf("%d",&N);
while(scanf("%s",menpai)!=EOF)
{
if(menpai[0]=='0') break;
if(menpai[0]=='W')
{
scanf("%d%d%d%d%d",&cunw[w].x,&cunw[w].y,&cunw[w].neili,&cunw[w].wuyi,&cunw[w].hp);
double a=(0.8*(double)cunw[w].neili+0.2*(double)cunw[w].wuyi)*((double)cunw[w].hp+10)/100.0;
mmap[cunw[w].x][cunw[w].y].wdd++;
mmap[cunw[w].x][cunw[w].y].wddd=w;
cunw[w].dps=(int)a;
cunw[w].flag=1;
cunw[w].fang=1;
w++;
}
if(menpai[0]=='S')
{
scanf("%d%d%d%d%d",&cuns[s].x,&cuns[s].y,&cuns[s].neili,&cuns[s].wuyi,&cuns[s].hp);
double b=(0.5*(double)cuns[s].neili+0.5*(double)cuns[s].wuyi)*((double)cuns[s].hp+10)/100.0;
cuns[s].dps=(int)b;
mmap[cuns[s].x][cuns[s].y].sll++;
mmap[cuns[s].x][cuns[s].y].slll=s;
cuns[s].fang=1;
cuns[s].flag=1;
s++;
}
if(menpai[0]=='E')
{
scanf("%d%d%d%d%d",&cune[e].x,&cune[e].y,&cune[e].neili,&cune[e].wuyi,&cune[e].hp);
double c=(0.2*(double)cune[e].neili+0.8*(double)cune[e].wuyi)*((double)cune[e].hp+10)/100;
cune[e].dps=(int)c;
mmap[cune[e].x][cune[e].y].emm++;
mmap[cune[e].x][cune[e].y].emmm=e;
cune[e].fang=1;
cune[e].flag=1;
e++;
}
}
for(int i=1;i<=N;i++)
{
slove();
shaolingzou();
wudangzou();
emeizou();
}
int sum=0,count=0;
for(int i=0;i<s;i++)
{
if(cuns[i].flag==1)
{
count++;
sum+=cuns[i].hp;
}
}
printf("%d %d\n",count,sum);
sum=count=0;
for(int i=0;i<w;i++)
{
if(cunw[i].flag==1)
{
count++;
sum+=cunw[i].hp;
}
}
printf("%d %d\n",count,sum);
count=sum=0;
for(int i=0;i<e;i++)
{
if(cune[i].flag==1)
{
count++;
sum+=cune[i].hp;
}
}
printf("%d %d\n",count,sum);
printf("***\n");
}
}

24
HDOJ/1108_autoAC.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <iostream>
using namespace std;
int main(){
int a,b;
while(cin>>a>>b){
int aa,bb,tmp;
if(a<b){
tmp=a;
a=b;
b=tmp;
}
aa=a;
bb=b;
while(b!=0){
tmp=a%b;
a=b;
b=tmp;
}
int lcm;
lcm=aa*bb/a;
cout<<lcm<<endl;
}
return 0;
}

86
HDOJ/1109_autoAC.cpp Normal file
View File

@ -0,0 +1,86 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include<map>
#include<ctime>
using namespace std;
const int NUM=20;
const int RAD=1000;
struct point
{
double x,y,val;
point(){}
point(double _x,double _y):x(_x),y(_y){}
}p[10001],May[NUM],e1,e2;
int n;
double X,Y;
double dis(point a,point b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double judge(point t)
{
double len;
len=1LL<<45;
for(int i=0;i<n;i++)
len=min(len,dis(t,p[i]));
return len;
}
double Rand(){return rand()%(RAD+1)/(1.0*RAD);}
point Rand_point(point a,point b)
{
double xx=a.x+(b.x-a.x)*Rand();
double yy=a.y+(b.y-a.y)*Rand();
point tmp=point(xx,yy);
tmp.val=judge(tmp);
return tmp;
}
void solve(double D)
{
May[0]=point(0,0);
May[1]=point(X,Y);
May[2]=point(0,Y);
May[3]=point(X,0);
for(int i=4;i<NUM;i++)
May[i]=Rand_point(May[0],May[1]);
while(D>0.01)
{
for(int i=0;i<NUM;i++)
for(int j=0;j<NUM;j++)
{
point tmp=Rand_point(point(max(0.0,May[i].x-D),max(0.0,May[i].y-D)),point(min(X,May[i].x+D),min(Y,May[i].y+D)));
if(tmp.val>May[i].val)
{
May[i]=tmp;
}
}
D*=0.9;
}
point ans;
ans.val=0;
for(int i=0;i<NUM;i++)
if(May[i].val>ans.val)
ans=May[i];
printf("The safest point is (%.1f, %.1f).\n",ans.x,ans.y);
}
int main()
{
srand(time(0));
e2=point(0,0);
int Case;
scanf("%d",&Case);
while(Case--)
{
scanf("%lf%lf%d",&X,&Y,&n);
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
solve(max(Y,X));
}
}

43
HDOJ/1110_autoAC.cpp Normal file
View File

@ -0,0 +1,43 @@
#include<iostream>
#include <cmath>
using namespace std;
int main()
{
double a,b,x,y;int n;
cin>>n;
while(n--)
{
cin>>a>>b>>x>>y;
if(a<b)
{
double t=b;
b=a;
a=t;
}
if(x<y)
{
double t=x;
x=y;
y=t;
}
if(a>x&&b>y)
cout<<"Escape is possible."<<endl;
if((a<=x&&b<=y)|(a>x&&b<=y))
cout<<"Box cannot be dropped."<<endl;
if(a<=x&&b>y)
{
int flog=0;
for(double i=0;i<=90;i=i+0.2)
{
double rad=3.1415926*i/180;
if(x*cos(rad)+y*sin(rad)<a&&x*sin(rad)+y*cos(rad)<b)
{flog=1; break;}
}
if(flog==1)
cout<<"Escape is possible."<<endl;
if(flog==0)
cout<<"Box cannot be dropped."<<endl;
}
}
return 0;
}

51
HDOJ/1111_autoAC.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <iostream>
using namespace std;
int xr,xi,br,bi,con;
int flag,t;
int a[105];
void dfs(int n)
{
int x,y,i;
if(n>100) return;
if(xr==0&&xi==0)
{
flag=1;
t=n;
return;
}
for(i=0;i*i<con;i++)
{
x=(xr-i)*br+xi*bi;
y=xi*br-(xr-i)*bi;
a[n]=i;
if(x%con==0&&y%con==0)
{
xr=x/con;
xi=y/con;
dfs(n+1);
}
if(flag) return;
}
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>xr>>xi>>br>>bi;
con=br*br+bi*bi;
flag=0;
dfs(0);
if(!flag)
cout<<"The code cannot be decrypted."<<endl;
else
{
cout<<a[t-1];
for(int i=t-2;i>=0;i--)
cout<<','<<a[i];
cout<<endl;
}
}
return 0;
}

83
HDOJ/1112_autoAC.cpp Normal file
View File

@ -0,0 +1,83 @@
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
bool key[109][109],s[11009][1009],visit[11009][1009];
int n,m;
int nm,mm;
bool in(int y)
{
if(y>=0&&y<mm)
return true;
return false;
}
bool door(int x,int y)
{
int i,j;
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
if(key[i][j]&&s[i+x][j+y])
return false;
}
return true;
}
int main()
{
int cas,i,j,flag;
char str[1009];
scanf("%d",&cas);
while(cas--)
{
memset(key,false,sizeof(key));
memset(s,false,sizeof(s));
memset(visit,false,sizeof(visit));
scanf("%d%d",&n,&m);
for(i=0; i<n; i++)
{
scanf("%s",str);
for(j=0; j<m; j++)
{
if(str[j]=='#')
key[i][j]=true;
}
}
scanf("%d%d",&nm,&mm);
nm+=n;
for(i=n; i<nm; i++)
{
scanf("%s",str);
for(j=0; j<mm; j++)
{
if(str[j]=='#')
s[i][j]=true;
}
}
for(i=0; i<mm; i++)
visit[0][i]=true;
for(i=1; i<nm; i++)
{
flag=false;
for(j=0; j<=mm-m; j++)
{
if(!visit[i][j]&&(visit[i-1][j]||(in(j-1)&&visit[i][j-1])||(in(j+1)&&visit[i][j+1])))
{
if(door(i,j))
{
flag=true;
visit[i][j]=true;
if(j>0&&!visit[i][j-1])
j-=2;
}
}
}
if(!flag)
break;
}
if(i>=nm)
printf("The key can fall through.\n");
else
printf("The key falls to depth %d.\n",i-1);
}
return 0;
}

51
HDOJ/1113_autoAC.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int power[26] = {1}, dic[105], p = 0;
char source[105][7], rem[105][7];
bool comp (const int x, const int y) {
return strcmp (rem[x], rem[y]) < 0;
}
int main () {
int len;
char tmp[7];
for (int i = 1; i < 26; i++)
power[i] = power[i-1]*2;
while (true) {
dic[++p] = 0;
scanf ("%s", tmp);
if (strcmp (tmp, "XXXXXX") == 0)
break;
strcpy (source[p], tmp);
len = strlen (tmp);
for (int i = 0; i < len; i++)
dic[p] += power[tmp[i]-'a'];
}
while (true) {
int value = 0, pm = 0, situ[105];
sizeof (rem, '\0', sizeof (rem));
scanf ("%s", tmp);
if (strcmp (tmp, "XXXXXX") == 0)
break;
len = strlen (tmp);
for (int i = 0; i < len; i++)
value += power[tmp[i]-'a'];
for (int i = 1; i <= p; i++)
if (value == dic[i])
strcpy (rem[++pm], source[i]);
if (pm == 0) {
printf ("NOT A VALID WORD\n******\n");
continue;
}
for (int i = 1; i <= pm; i++)
situ[i] = i;
sort (situ+1, situ+pm+1, comp);
for (int i = 1; i <= pm; i++)
printf ("%s\n", rem[situ[i]]);
printf ("******\n");
}
return 0;
}

33
HDOJ/1114_autoAC.cpp Normal file
View File

@ -0,0 +1,33 @@
#include<stdio.h>
#define maxn 2222222
int bag[11111]={0},p[555],w[555];
int main()
{
int t,e,f,n,realw,i,j;
while(scanf("%d",&t)==1)
{
while(t--)
{
scanf("%d %d",&e,&f);
realw=f-e;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d %d",&p[i],&w[i]);
for(i=1;i<=realw;i++)
bag[i]=maxn;
for(i=1;i<=n;i++)
{
for(j=w[i];j<=realw;j++)
{
if(bag[j]>bag[j-w[i]]+p[i])
bag[j]=bag[j-w[i]]+p[i];
}
}
if(bag[realw]==maxn)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",bag[realw]);
}
}
return 0;
}

29
HDOJ/1115_autoAC.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<stdio.h>
#include<math.h>
struct p{
double x,y;
};
double cross(p a,p b,p c){
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
p p1,p2,tp;
double res=0,s,tx=0,ty=0;
scanf("%d",&n);
scanf("%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y);
for(int i=3;i<=n;++i){
scanf("%lf%lf",&tp.x,&tp.y);
s=cross(p1,p2,tp);
res+=s;
tx+=(p1.x+p2.x+tp.x)*s;
ty+=(p1.y+p2.y+tp.y)*s;
p2.x=tp.x;p2.y=tp.y;
}
printf("%.2lf %.2lf\n",tx/(3*res),ty/(3*res));
}
return 0;
}

72
HDOJ/1116_autoAC.cpp Normal file
View File

@ -0,0 +1,72 @@
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<time.h>
#include<map>
#include<algorithm>
#define ll long long
#define eps 1e-5
#define oo 1000000007
#define pi acos(-1.0)
#define MAXN 100005
#define MAXM 500005
using namespace std;
int P[2][26],father[26];
bool used[26];
char s[1005];
int getfather(int x)
{
if (father[x]==x) return x;
return father[x]=getfather(father[x]);
}
int main()
{
int i,cases,n,m,x,y,t1,t2;
scanf("%d",&cases);
while (cases--)
{
scanf("%d",&n);
memset(used,false,sizeof(used));
memset(P,0,sizeof(P));
for (i=0;i<26;i++) father[i]=i;
for (i=1;i<=n;i++)
{
scanf("%s",s+1);
x=s[1]-'a',y=s[strlen(s+1)]-'a';
P[0][x]++,P[1][y]++;
father[getfather(x)]=getfather(y);
used[x]=used[y]=true;
m=getfather(x);
}
if (n==1)
{
printf("Ordering is possible.\n");
continue;
}
for (i=0;i<26;i++)
if (used[i] && getfather(i)!=m) break;
if (i<26)
{
printf("The door cannot be opened.\n");
continue;
}
t1=t2=0;
for (i=0;i<26;i++)
{
if (P[0][i]==P[1][i]) continue;
if (P[0][i]+1==P[1][i]) t1++;
else
if (P[1][i]+1==P[0][i]) t2++;
else break;
}
if (i<26 || !(t1==1 && t2==1 || !t1 && !t2))
printf("The door cannot be opened.\n");
else
printf("Ordering is possible.\n");
}
return 0;
}

62
HDOJ/1117_autoAC.cpp Normal file
View File

@ -0,0 +1,62 @@
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<set>
#include<math.h>
#include<string>
using namespace std;
typedef long long ll;
using namespace std;
#define INF 10000000
int a[54][2];
int main()
{
int n;
while(scanf("%d",&n)!=EOF && n)
{
memset(a,0,sizeof(a));
if(n==1)
{
printf("Printing order for %d pages:\n", n);
printf("Sheet 1, front: Blank, 1\n");
continue;
}
int i,j,k = n/4;
if(n%4!=0 ) k++;
for(i=1;i<=2*k;i++)
a[i][0] =i;
for(i=2*k,j=i+1;i>=1;i--,j++)
{
if(j<=n)
a[i][1]=j;
}
printf("Printing order for %d pages:\n",n);
char s[2][10]={"front","back "};
char *p;
for(i=1;i<=2*k;i++)
{
if(a[i][0]==0 && a[i][0]==0 )continue;
j=i/2;
if( i&1 )
{
p=s[0];
j++;
}
else
p=s[1];
printf("Sheet %d, %s:",j,p);
if( i&1 )
swap(a[i][0],a[i][1]);
for(int m=0;m<2;m++)
{
if(a[i][m] ) printf(" %d",a[i][m]);
else printf(" Blank");
if(!m) putchar(',');
}
printf("\n");
}
}
}

164
HDOJ/1119_autoAC.cpp Normal file
View File

@ -0,0 +1,164 @@
#include <iostream>
#include <string.h>
#include <stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
using namespace std;
char s1[510],s2[510],s[1010];
int t;
void Add(int A[],int a,int B[],int b,int C[],int &c)
{
int i,j,k,*p,*q;
if(a<b)
k=a,a=b,b=k,p=B,q=A;
else p=A,q=B;
for(C[0]=0,c=a,i=1;i<=a;i++) C[i]=p[i];
for(i=a,j=b;j>=1;j--,i--) C[i]+=q[j];
for(i=a;i>=0;i--)C[i-1]+=C[i]/10,C[i]%=10;
if(C[0]) for(c++,i=c;i>=1;i--) C[i]=C[i-1];
for(i=1;!C[i]&&i<=c;i++);
k=i,c-=i-1;
for(i=1;i<=c;i++) C[i]=C[k+i-1];
if(c<=0) c=1,C[1]=0;
}
void add()
{
int A[510],a,B[510],b,C[510],c,i;
a=strlen(s1);
for(i=0;i<a;i++) A[i+1]=s1[i]-'0';
b=strlen(s2);
for(i=0;i<b;i++) B[i+1]=s2[i]-'0';
Add(A,a,B,b,C,c);
int t=max(a,max(b+1,c));
for(i=1;i<=t-a;i++) putchar(' ');puts(s1);
for(i=1;i<=t-(b+1);i++) putchar(' ');putchar('+');puts(s2);
for(i=1;i<=t;i++) putchar('-');puts("");
for(i=1;i<=t-c;i++) putchar(' ');
for(i=1;i<=c;i++) printf("%d",C[i]);puts("");
}
void Sub(int A[],int a,int B[],int b,int C[],int &c)
{
int i,j,k,flag,*p,*q;
if(a==b)
{
flag=0;
for(i=1;i<=a;i++)
{
if(A[i]>B[i])flag=1;
if(A[i]<B[i])flag=-1;
if(flag) break;
}
}
if(a>b) flag=1;
if(a<b) flag=-1;
if(!flag)
{
C[0]=0,c=1;C[1]=0;
return;
}
if(flag==1)
p=A,q=B;
else p=B,q=A,k=a,a=b,b=k;
for(i=1;i<=a;i++) C[i]=p[i];
for(i=a,j=b;j>=1;j--,i--)
{
if(C[i]>=q[j])
C[i]-=q[j];
else C[i]=C[i]+10-q[j],C[i-1]--;
}
for(;i>=1&&C[i]<0;i--) C[i]+=10,C[i-1]--;
for(i=1;!C[i]&&i<=a;i++);
k=i,c=a-i+1;
for(i=1;i<=c;i++) C[i]=C[k+i-1];
C[0]=flag;
}
void sub()
{
int A[510],a,B[510],b,C[510],c,i;
a=strlen(s1);
for(i=0;i<a;i++) A[i+1]=s1[i]-'0';
b=strlen(s2);
for(i=0;i<b;i++) B[i+1]=s2[i]-'0';
Sub(A,a,B,b,C,c);
int t=max(a,max(b+1,c));
for(i=1;i<=t-a;i++) putchar(' ');puts(s1);
for(i=1;i<=t-(b+1);i++) putchar(' ');putchar('-');puts(s2);
for(i=1;i<=t-max(b+1,c);i++) putchar(' ');
for(i=1;i<=max(b+1,c);i++) putchar('-');puts("");
for(i=1;i<=t-c;i++) putchar(' ');
for(i=1;i<=c;i++) printf("%d",C[i]);puts("");
}
void Mul(int A[],int a,int B[],int b,int C[],int &c)
{
int i,j,k;
for(i=0;i<=a+b;i++) C[i]=0;
for(i=a;i>=1;i--)
for(j=b;j>=1;j--)
C[i+j]+=A[i]*B[j];
for(i=a+b;i>1;i--)C[i-1]+=C[i]/10,C[i]%=10;
for(i=0;!C[i]&&i<=a+b;i++);
k=i,c=a+b-i+1;
for(i=1;i<=c;i++) C[i]=C[k+i-1];
if(c<=0) c=1,C[1]=0;
}
int C[510][1010];
void mul()
{
int A[510],a,B[510],b,ans[1010],x,c[510],temp,i,j,t=0,k;
a=strlen(s1);
for(i=0;i<a;i++) A[i+1]=s1[i]-'0';
b=1;
temp=strlen(s2);
for(i=0;i<temp;i++)
{
B[1]=s2[i]-'0';
Mul(A,a,B,b,C[i],c[i]);
t=max(t,temp-1-i+c[i]);
}
k=t;
t=max(t,max(a,temp+1));
for(i=0;i<temp;i++) B[i+1]=s2[i]-'0';
Mul(A,a,B,temp,ans,x);
t=max(t,x);
for(i=1;i<=t-a;i++) putchar(' ');puts(s1);
for(i=1;i<=t-(temp+1);i++) putchar(' ');putchar('*');puts(s2);
if(temp==1)
{
for(i=1;i<=t-max(k,temp+1);i++) putchar(' ');
for(i=1;i<=max(k,temp+1);i++) putchar('-');puts("");
}
else
{
for(i=1;i<=t-max(c[temp-1],temp+1);i++) putchar(' ');
for(i=1;i<=max(c[temp-1],temp+1);i++) putchar('-');puts("");
}
for(i=temp-1;i>=0;i--)
{
for(j=1;j<=t-(temp-1-i+c[i]);j++) putchar(' ');
for(j=1;j<=c[i];j++) printf("%d",C[i][j]);puts("");
}
if(temp>1)
{
for(i=1;i<=t-max(k,x);i++) putchar(' ');
for(i=1;i<=max(k,x);i++) putchar('-');puts("");
for(i=1;i<=t-x;i++) putchar(' ');
for(i=1;i<=x;i++) printf("%d",ans[i]);puts("");
}
}
int main()
{
for(scanf("%d",&t);t--;)
{
scanf("%s",s);
int i,len=strlen(s);
for(i=0;i<len;i++) if(s[i]=='+'||s[i]=='-'||s[i]=='*') break;
char c=s[i];
s[i]='\0';
strcpy(s1,s);
strcpy(s2,s+i+1);
if(c=='+') add();
else if(c=='-') sub();
else mul();
puts("");
}
return 0;
}

59
HDOJ/1121_autoAC.cpp Normal file
View File

@ -0,0 +1,59 @@
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int x,y;
scanf("%d%d",&x,&y);
int a[1000];
int b[1000];
int c[1000];
for(int i=0;i<x;i++)
{
scanf("%d",&a[i]);
}
int num;
int flag=0;
int w=x;
int f1=0;
for(num=0;;num++)
{
int k=0;
b[f1++]=a[w-1];
if(flag==1)
break;
for(int i=0;i<w-1;i++)
{
if(a[i]==a[i+1])
{
k++;
}
}
if(k==w-1)
flag=1;
if(flag==0)
{
for(int i=0;i<w-1;i++)
a[i]=a[i+1]-a[i];
}
w--;
}
for(int i=0;i<y;i++)
{
c[i]=b[num-1];
}
for(int i=num-2;i>=0;i--)
{
c[0]+=b[i];
for(int j=1;j<y;j++)
c[j]+=c[j-1];
}
int ff=0;
for(int i=0;i<y;i++)
ff==0?printf("%d",c[i]):printf(" %d",c[i]),ff=1;
printf("\n");
}
return 0;
}

90
HDOJ/1123_autoAC.cpp Normal file
View File

@ -0,0 +1,90 @@
#include <stdio.h>
#include <string.h>
#define len 251
char post[len],s[len]; //post 涓哄缂琛ㄨ揪寮
int priority[len],n; //priority 涓鸿绠绗浼绾
void postfix(){
int p,ep,i;
char expresion[len];
for(i=p=ep=0;i<n;i++){
switch(s[i]){
case '(':expresion[ep++]=s[i];
break;
case '+':
case '-':for(;ep&&expresion[ep-1]!='(';post[p++]=expresion[--ep]);
expresion[ep++]=s[i];
break;
case '*':
case '/':for(;ep&&(expresion[ep-1]=='*'||expresion[ep-1]=='/');post[p++]=expresion[--ep]);
expresion[ep++]=s[i];
break;
case ')':for(;ep&&expresion[--ep]!='(';post[p++]=expresion[ep]);
break;
default:post[p++]=s[i];
break;
}
}
while(ep)
post[p++]=expresion[--ep];
post[p]='\0';
}
void infix(){
int k,p,i,tem;
bool c;
char stack[len][len],s1[len],s2[len];
for(i=p=0;i<n;i++){
switch(post[i]){
case '+':
case '-':
case '*':
case '/':k=(post[i]=='*'||post[i]=='/')?2:1;
c=(post[i]=='-'||post[i]=='/')?true:false;
if(priority[p-1]&&(priority[p-1]<k||(priority[p-1]==k&&c))){
s2[0]='(';
s2[1]='\0';
strcat(s2,stack[p-1]);
strcat(s2,")");
}
else{
s2[0]='\0';
strcat(s2,stack[p-1]);
}
--p;
if(priority[p-1]&&priority[p-1]<k){
s1[0]='(';
s1[1]='\0';
strcat(s1,stack[p-1]);
strcat(s1,")");
}
else{
s1[0]='\0';
strcat(s1,stack[p-1]);
}
strcpy(stack[p-1],s1);
tem=(int)strlen(stack[p-1]);
stack[p-1][tem]=post[i];
stack[p-1][tem+1]='\0';
strcat(stack[p-1],s2);
priority[p-1]=k;
break;
default:stack[p][0]=post[i];
stack[p][1]='\0';
priority[p++]=0;
break;
}
}
strcpy(post,stack[0]);
}
int main(void){
int t;
scanf("%d",&t);
while(t--){
scanf("%s",s);
n=(int)strlen(s);
memset(post,0,sizeof(post));
postfix();
infix();
puts(post);
}
return 0;
}

19
HDOJ/1124_autoAC.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
int t,n,sum;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
sum=0;
while(n!=0)
{
n=n/5;
sum+=n;
}
printf("%d\n",sum);
}
return 0;
}

17
HDOJ/1128_autoAC.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <iostream>
using namespace std;
bool a[1000001]={false};
int main()
{
int i,j,sum=0;
for(i=1;i<=1000000;i++)
{
j=i;
for(sum=j;j;j/=10)
sum+=j%10;
a[sum]=true;
if(!a[i])
printf("%d\n",i);
}
return 0;
}

29
HDOJ/1129_autoAC.cpp Normal file
View File

@ -0,0 +1,29 @@
#include<stdio.h>
#include<string.h>
char c[28]={'_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','.'};
int plaincode[71];
int main(){
int k,i,n;
char ch[71];
while(scanf("%d",&k),k){
scanf("%s",ch);
n=strlen(ch);
for(i=0;i<n;i++){
if(ch[i]>='a'&&ch[i]<='z'){
plaincode[(k*i)%n]=((ch[i]-96)+i)%28;
//printf("%d ",(int)(ch[i]-96));
}
else if(ch[i]=='_'){
plaincode[(k*i)%n]=((ch[i]-95)+i)%28;
}
else{
plaincode[(k*i)%n]=((ch[i]-19)+i)%28;
}
}
for(i=0;i<n;i++){
printf("%c",c[plaincode[i]]);
}
printf("\n");
}
return 0;
}

50
HDOJ/1130_autoAC.cpp Normal file
View File

@ -0,0 +1,50 @@
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define base 10000
#define maxx 100
void multiply(int a[],int max,int b)
{
int i,array=0;
for(i=max-1;i>=0;i--)
{
array+=b*a[i];
a[i]=array%base;
array/=base;
}
}
void divide(int a[],int max,int b)
{
int i,div=0;
for(i=0;i<max;i++)
{
div=div*base+a[i];
a[i]=div/b;
div%=b;
}
}
int main()
{
int n,i;
int a[101][maxx];
memset(a[1],0,maxx*sizeof(int));
for(i=2,a[1][maxx-1]=1;i<101;i++)
{
memcpy(a[i],a[i-1],maxx*sizeof(int));
multiply(a[i],maxx,4*i-2);
divide(a[i],maxx,i+1);
}
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<maxx&&a[n][i]==0;i++);
printf("%d",a[n][i++]);
for(;i<maxx;i++)
{
printf("%04d",a[n][i]);
}
printf("");
printf("\n");
}
return 0;
}

34
HDOJ/1131_autoAC.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int a[1001];
void mul(int a[],int b)
{
int i;
for(i=0;i<1001;i++)
a[i]*=b;
for(i=0;i<1000;i++)
if(a[i]>=10)
{
a[i+1]+=a[i]/10;
a[i]%=10;
}
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF,n)
{
int i;
for(i=0;i<1001;i++)
a[i]=0;
a[0]=1;
for(i=n+2;i<=2*n;i++)
mul(a,i);
for(i=1000;!a[i]&&i>0;i--);
for(;i>0;i--)
printf("%d",a[i]);
printf("%d\n",a[0]);
}
return 0;
}

63
HDOJ/1133_autoAC.cpp Normal file
View File

@ -0,0 +1,63 @@
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
const int MAX=501;
int s[MAX];
using namespace std;
int main()
{
int n,m,q,p=1,c,sum,k,temp,t,i,j;
while(cin>>m>>n&&(m||n))
{
cout<<"Test #"<<p++<<':'<<endl;
if(m<n)
{
cout<<0<<endl;
continue;
}
memset(s,0,sizeof(s));
s[1]=1;
sum=0;
for(i=2;i<=(m+n);i++)
{
for(j=1;j<MAX;j++)
{
c=s[j]*i+sum;
s[j]=c%10;
sum=c/10;
}
}
q=m+1-n;
sum=0;
for(j=1;j<MAX;j++)
{
c=s[j]*q+sum;
s[j]=c%10;
sum=c/10;
}
for(j=MAX-1;j>=1;j--)
{
if(s[j]!=0)
break;
}
for(i=j,sum=0,t=0;j>=1;j--)
{
temp=sum*10+s[j];
if(t==0)
{
if(temp/(m+1)>0)
{
t=1;
cout<<temp/(m+1);
}
}
else
cout<<temp/(m+1);
sum=temp%(m+1);
}
cout<<endl;
}
return 0;
}

70
HDOJ/1134_autoAC.cpp Normal file
View File

@ -0,0 +1,70 @@
#include<stdio.h>
#include<string.h>
int record[110][110];
int a1[110],weishu[110];
void cheng(int a)
{
int i,m,c,chushu,temp;
m=weishu[a-1];
c=0;
for(i=0;i<=m;++i)
{
a1[i]=a1[i]*(4*a-2)+c;
c=a1[i]/10000;
a1[i]%=10000;
}
if(c>0)
{
++m;
a1[m]=c;
}
chushu=a+1,temp=a1[m];
if(m==0)
a1[0]/=chushu;
else
{
for(i=m;i>=0;--i)
{
if(temp<chushu)
{
if(i==m)
{
--m;
}
else
a1[i]=0;
}
else
{
a1[i]=temp/chushu;
temp%=chushu;
}
temp=temp*10000+a1[i-1];
}
}
weishu[a]=m;
for(i=0;i<=weishu[a];++i)
{
record[a][i]=a1[i];
}
}
int main()
{
int a,i,n;
record[1][0]=1;
weishu [1]=0;
a1[0]=1;
for(i=2;i<=100;++i)
{
cheng(i);
}
while(scanf("%d",&n)&&n!=-1)
{
printf("%d",record[n][weishu[n]]);
for(i=weishu[n]-1;i>=0;--i)
{
printf("%.4d",record[n][i]);
}
printf("\n");
}
}

54
HDOJ/1140_autoAC.cpp Normal file
View File

@ -0,0 +1,54 @@
#include <iostream>
#include <cmath>
#define maxn 102
#define eps 1e-8
using namespace std;
int m,k,i,j,n,ans,cnt[maxn];
struct point
{
friend inline istream & operator >> (istream & in, point &p)
{
in>>p.x>>p.y>>p.z;
return in;
}
point& operator -(point& b)
{
point a;
a.x=x-b.x;
a.y=y-b.y;
a.z=z-b.z;
return a;
}
double x,y,z;
};
bool equal(double a,double b)
{
return fabs(a-b)<eps;
}
double cal(point a,point b)
{
return a.x*b.x+a.y*b.y+a.z*b.z;
}
int main()
{
point o,v1,v2,sate[maxn],trop[maxn];
while(cin>>k>>m&&(m||k))
{
o.x=0,o.y=0,o.z=0;
ans=0;
memset(cnt,0,sizeof(cnt));
for(i=0;i<k;i++)cin>>sate[i];
for(i=0;i<m;i++)cin>>trop[i];
for(i=0;i<k;i++)
{
for(j=0;j<m;j++)
{
v1=o-trop[j];
v2=sate[i]-trop[j];
if(cal(v1,v2)<0||equal(cal(v1,v2),0))cnt[j]=1;
}
}
for(i=0;i<m;i++)if(cnt[i])++ans;
cout<<ans<<endl;
}
}

49
HDOJ/1141_autoAC.cpp Normal file
View File

@ -0,0 +1,49 @@
#include<iostream>
#include<cmath>
using namespace std;
int x[21];
void make()
{
int i,j;
double k=log(4.0);
for(i=196;i<=216;++i)
{
k*=2;
double f=0;
for(j=1;f<k;++j)
f+=log((double)j);
x[i-196]=j-2;
}
}
int main()
{
make();
int year;
while(cin>>year&&year)
cout<<x[(year-1960)/10]<<endl;
return 0;
}#include<iostream>
#include<cmath>
using namespace std;
int x[21];
void make()
{
int i,j;
double k=log(4.0);
for(i=196;i<=216;++i)
{
k*=2;
double f=0;
for(j=1;f<k;++j)
f+=log((double)j);
x[i-196]=j-2;
}
}
int main()
{
make();
int year;
while(cin>>year&&year)
cout<<x[(year-1960)/10]<<endl;
return 0;
}

91
HDOJ/1142_autoAC.cpp Normal file
View File

@ -0,0 +1,91 @@
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
const int inf = 1000000000;
int map[1010][1010];
int n, p;
bool flag[1010];
int dis[1010];
void spfa()
{
for(int i = 1; i <= n ;++i)
{
flag[i] = false;
dis[i] = inf;
}
dis[2] = 0;
flag[2] = true;
queue<int> que;
que.push(2);
while(!que.empty())
{
int now = que.front();
que.pop();
flag[now] = false;
for(int i = 1; i <= n ;++i)
{
if(dis[i] > dis[now] + map[now][i])
{
dis[i] = dis[now] + map[now][i];
if(!flag[i])
{
flag[i] = true;
que.push(i);
}
}
}
}
}
int cou[1010];
void dfs(int now)
{
if(now == 2)
{
cou[2] = 1;
return;
}
int result(0);
for(int i = 1; i <= n ;++i)
{
if(map[now][i] != inf && dis[i] < dis[now])
{
if(cou[i] >= 0)
{
result += cou[i];
}
else
{
dfs(i);
result += cou[i];
}
}
}
cou[now] = result;
}
int main()
{
int a, b, dist;
while(scanf("%d", &n) != EOF)
{
if(!n)
break;
scanf("%d", &p);
for(int i = 0; i <= n; ++i)
for(int j = 1; j <= n;++j)
map[i][j] = inf;
for(int i= 0; i < p; ++i)
{
scanf("%d %d %d", &a, &b, &dist);
map[a][b] = map[b][a] = dist;
}
spfa();
for(int i = 1; i <= n;++i)
{
cou[i] = -1;
}
dfs(1);
printf("%d\n", cou[1]);
}
return 0;
}

25
HDOJ/1143_autoAC.cpp Normal file
View File

@ -0,0 +1,25 @@
#include<string.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
const int MAX=31;
int s[MAX];
using namespace std;
int main()
{
int i,n;
s[0]=1;
s[2]=3;
for(i=4;i<MAX;i+=2)
{
s[i]=4*s[i-2]-s[i-4];
}
while(cin>>n,n>=0)
{
if(n&1)
cout<<0<<endl;
else
cout<<s[n]<<endl;
}
return 0;
}

41
HDOJ/1144_autoAC.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int k , m , data , c, t;
while(cin >> k && k && cin >> m)
{
vector<int> course;
bool pass = true;
while(k --)
{
cin >> data;
course.push_back(data);
}
while(m --)
{
cin >> c >> t;
if(pass)
{
int cnt = 0;
while(c--)
{
cin >> data;
if(find(course.begin() , course.end() , data) != course.end())
{++cnt;}
}
if(cnt < t)
{pass = false;}
}
else
{
while(c --)
{cin >> data;}
}
}
cout << (pass ? "yes" : "no") << endl;
}
return 0;
}

36
HDOJ/1145_autoAC.cpp Normal file
View File

@ -0,0 +1,36 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
using namespace std;
double ex[30+5]={0.0};
double mon[30+5]={0.0};
double t=0.0;
int n=0;
double bp=0.0;
int main()
{
mon[0]=1;
for(int i=1;i<=30;i++)
{
mon[i]=mon[i-1]*2;
}
while(scanf("%d%lf",&n,&t)!=EOF&&(n>0))
{
ex[n]=mon[n];
for(int i=n-1;i>=0;i--)
{
bp=mon[i]/ex[i+1];
if(bp<=t)
{
ex[i]=(1+t)/2 * ex[i+1];
}
else
{
ex[i]=(bp-t)/(1-t) * mon[i] + (1-bp)/(1-t) * (1+bp)/2 * ex[i+1];
}
}
printf("%.3lf\n",ex[0]);
}
return(0);
}

91
HDOJ/1146_autoAC.cpp Normal file
View File

@ -0,0 +1,91 @@
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int t, c, n, m, i, time, ln[2], lt[2], ont, bt, temp, llt;
bool bleft, tleft;
char ch[10];
cin >> c;
while (c--)
{
ln[0] = ln[1] = lt[0] = lt[1] = 0, bleft = 1, ont = 0, bt = 0;
cin >> n >> t >> m;
for (i = 0; i < m; i++)
{
scanf("%d%s", &time, ch);
if (ch[0] == 'l')
tleft = 1;
else
tleft = 0;
if (bt + ont <= time)
{
bleft = (bleft + ont / t) % 2;
bt = time;
if (bleft == tleft)
{
ln[tleft] = 0;
ont = t;
}
else
{
ln[tleft] = 1;
ont = 2 * t;
}
ln[(tleft + 1) % 2] = 0;
lt[0] = lt[1] = 0;
printf("%d\n", bt + ont);
}
else
{
llt = 0;
if (time >= bt + t)
{
temp = (time - bt) / t;
bt += temp * t;
ont -= temp * t;
bleft = (bleft + temp) % 2;
if (temp % 2)
lt[bleft]--;
lt[0] -= temp / 2;
lt[1] -= temp / 2;
lt[bleft] -= temp % 2;
lt[bleft]++;
if (lt[0] < 0)
{
ln[0] = 0;
lt[0] = 0;
}
if (lt[1] < 0)
{
ln[1] = 0;
lt[1] = 0;
}
}
if (time > bt)
llt = 2 * t;
ln[tleft]++;
if (bleft == tleft)
{
cout << bt + 2 * t * lt[tleft] + t + llt << endl;
if (2 * t * lt[tleft] + t + llt > ont)
ont = 2 * t * lt[tleft] + t + llt;
}
else
{
cout << bt + 2 * t + 2 * t * lt[tleft] << endl;
if (2 * t * lt[tleft] + 2 * t > ont)
ont = 2 * t * lt[tleft] + 2 * t;
}
if (ln[tleft] == n)
{
ln[tleft] = 0;
lt[tleft]++;
}
}
}
if (c)
printf("\n");
}
return 0;
}

70
HDOJ/1147_autoAC.cpp Normal file
View File

@ -0,0 +1,70 @@
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 100009;
struct Point{
double x, y;
};
struct Line {
Point p1, p2;
};
Line line[N];
vector<int> v;
bool vis[N];
double direction (Point p0, Point p1, Point p2) {
return ((p2.x - p0.x)*(p1.y - p0.y) - (p1.x - p0.x)*(p2.y - p0.y));
}
bool on_segment (Point p0, Point p1, Point p2) {
double minx, maxx, miny, maxy;
minx = min(p0.x, p1.x);
maxx = max(p0.x, p1.x);
miny = min(p0.y, p1.y);
maxy = max(p0.y, p1.y);
if (p2.x >= minx && p2.x <= maxx && p2.y >= miny && p2.y <= maxy)
return true;
else
return false;
}
bool segments_intersect (Point p1, Point p2, Point p3, Point p4) {
double d1, d2, d3, d4;
d1 = direction(p3, p4, p1);
d2 = direction(p3, p4, p2);
d3 = direction(p1, p2, p3);
d4 = direction(p1, p2, p4);
if (((d1 < 0 && d2 > 0) || (d1 > 0 && d2 < 0)) && ((d3 < 0 && d4 > 0) || (d3 > 0 && d4 < 0)))
return true;
else
return false;
}
int main()
{
int i, j, n;
while (scanf("%d", &n)!=EOF && n) {
v.clear();
memset(vis, 0, sizeof(vis));
for (i = 1; i <= n; ++i)
scanf("%lf %lf %lf %lf", &line[i].p1.x, &line[i].p1.y, &line[i].p2.x, &line[i].p2.y);
v.push_back(n);
for (j = n-1; j >= 1; j--) {
if (vis[j])
continue;
for (i = n; i > j; --i) {
if (vis[i])
continue;
if (segments_intersect(line[j].p1, line[j].p2, line[i].p1, line[i].p2))
break;
}
if (i <= j)
v.push_back(j);
}
int len = (int)v.size();
printf("Top sticks: ");
for (i = len -1; i > 0; --i)
printf("%d, ", v[i]);
printf("%d.\n", v[0]);
}
return 0;
}

76
HDOJ/1148_autoAC.cpp Normal file
View File

@ -0,0 +1,76 @@
#include<iostream>
#include<iomanip>
#include<string.h>
#include<string.h>
#include<algorithm>
using namespace std;
int dec(char *a,char *b)
{
int a1,b1;
a1=strcmp(a,"rock");
b1=strcmp(b,"rock");
if(a1>0)
{
if(b1>0)
return 0;
else if(b1<0)
return 1;
else
return -1;
}
else if(a1<0)
{
if(b1>0)
return -1;
else if(b1<0)
return 0;
else return 1;
}
else
{
if(b1>0)
return 1;
else if(b1<0)
return -1;
else
return 0;
}
}
int main()
{
char s1[10],s2[10];
double win[1000]={0},lose[1000]={0};
int m,n,i,j,k,a,b;
k=1;
while(cin>>m&&m)
{
if(k!=1)
cout<<endl;
cin>>n;
for(i=0;i<n;i++)
{
cin>>a>>s1>>b>>s2;
if(dec(s1,s2)==1)
{
win[a]++;
lose[b]++;
}
else if(dec(s1,s2)==-1)
{
win[b]++;
lose[a]++;
}
}
for(j=1;j<m+1;j++)
{
if(win[j]==0&&lose[j]==0)
cout<<"-"<<endl;
else
cout<<setiosflags(ios::fixed)<<setprecision(3)<<(win[j]/(win[j]+lose[j]))<<endl;
}
k++;
memset(win,0,sizeof(win));
memset(lose,0,sizeof(lose));
}
return 0;
}

37
HDOJ/1150_autoAC.cpp Normal file
View File

@ -0,0 +1,37 @@
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
#define M 1005
int map[M][M], vis[M], yy[105], x, y, n, cnt;
int getOne(int i){
for(int j=0; j<y; j++){
if(!vis[j] && map[i][j]){
vis[j] = 1;
if(!yy[j] || getOne(yy[j])){
yy[j] = i;
return 1;
}
}
}
return 0;
}
int main(){
int i, j, a, b, job;
while(scanf("%d", &x)!=EOF && x){
scanf("%d %d", &y, &n);
cnt = 0;
memset(map, 0, sizeof(map));
memset(yy, 0, sizeof(yy));
for(i=0; i<n; i++){
scanf("%d %d %d", &job, &a, &b);
if(a&&b)map[a][b] = 1;
}
for(i=0; i<x; i++){
memset(vis, 0, sizeof(vis));
if(getOne(i))cnt++;
}
printf("%d\n", cnt);
}
}

44
HDOJ/1151_autoAC.cpp Normal file
View File

@ -0,0 +1,44 @@
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
int const maxn=122;
int n,m;
bool mat[maxn][maxn];
bool vis[maxn];
int mac[maxn];
bool match(int x)
{
for(int i=1;i<=m;i++)
{
if(mat[x][i]&&!vis[i]){
vis[i]=1;
if(!mac[i]||match(mac[i])){
mac[i]=x;
return 1;
}
}
}
return 0;
}
int main(){
int a,b;
int test;
scanf("%d",&test);
while(test--){
scanf("%d%d",&m,&n);
memset(mat,0,sizeof(mat));
memset(mac,0,sizeof(mac));
for(int i=0;i<n;i++){
scanf("%d%d",&a,&b);
mat[a][b]=1;
}
int ans=0;
for(int i=1;i<=m;i++){
memset(vis,0,sizeof(vis));
if(match(i))ans++;
}
printf("%d\n",m-ans);
}
return 0;
}

36
HDOJ/1152_autoAC.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=200005;
struct node
{
int x,y;
} p[maxn];
int main()
{
int n;
int i;
while(scanf("%d",&n),n)
{
for(i=1; i<=n; i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
}
int sum=0;
int ans=0;
for(i=1; i<=n; i++)
{
if((p[i].x<p[n/2+1].x&&p[i].y>p[n/2+1].y)||(p[i].x>p[n/2+1].x&&p[i].y<p[n/2+1].y))
{
sum++;
}
else if((p[i].x<p[n/2+1].x&&p[i].y<p[n/2+1].y)||(p[i].x>p[n/2+1].x&&p[i].y>p[n/2+1].y))
{
ans++;
}
}
cout<<ans<<" "<<sum<<endl;
}
return 0;
}

20
HDOJ/1153_autoAC.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <iostream>
using namespace std;
long long p;
int a[100010];
int main()
{
while(cin >> p)
{
if(p==0)break;
if(p==2)cout << "Impossible" << endl;
else
{
for(int i=1;i<p;i++)a[i]=1;
for(long long i=1;i<p;i++)a[i*i%p]=0;
for(int i=1;i<p;i++)cout << a[i];
cout << endl;
}
}
return 0;
}

169
HDOJ/1154_autoAC.cpp Normal file
View File

@ -0,0 +1,169 @@
#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define maxn 1200
#define eps 1e-8
struct point
{
double x;
double y;
}po[maxn],rec[maxn];
struct line
{
point a;
point b;
}temp,temp1;
double xmulit(point &a,point &b,point &c)
{
return (a.x-b.x)*(a.y-c.y)-(a.y-b.y)*(a.x-c.x);
}
bool across(point &a,point &b,point &c,point &d)
{
double p=xmulit(a,b,c),p1=xmulit(a,b,d);
if( fabs(p1) <= eps || fabs(p) <= eps ) return true;
if( p*p1 < -eps )
return true;
return false;
}
bool one_line(point &a,point &b,point &c,point &d)
{
double p=xmulit(a,b,c),p1=xmulit(a,b,d);
if( fabs(p1) < eps && fabs(p) < eps ) return true;
return false;
}
bool is_equal(point &a,point &b)
{
return (fabs(a.x-b.x) <= eps) && (fabs(a.y-b.y) <=eps);
}
point intersection(line &u,line &v)
{
point ret=u.a;
double t=((u.a.x-v.a.x)*(v.a.y-v.b.y) - (u.a.y-v.a.y)*(v.a.x-v.b.x))/((u.a.x-u.b.x)*(v.a.y-v.b.y)-(u.a.y-u.b.y)*(v.a.x-v.b.x));
ret.x+=(u.b.x-u.a.x)*t;
ret.y+=(u.b.y-u.a.y)*t;
return ret;
}
int n,m;
double dis(point &a,point &b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int cmp(point a, point b)
{
if(fabs(a.x-b.x)<eps)
return a.y<b.y;
return a.x<b.x;
}
bool on_segment(point pi,point pj,point pk)
{
if(xmulit(pi, pj, pk)==0)
{
if(pk.x>=min(pi.x,pj.x)&&pk.x<=max(pi.x,pj.x)&&pk.y>=min(pi.y,pj.y)&&pk.y<=max(pi.y,pj.y))
return true;
}
return false;
}
bool segments_intersect(point p1,point p2,point p3,point p4)
{
double d1=xmulit(p3,p4,p1);
double d2=xmulit(p3,p4,p2);
double d3=xmulit(p1,p2,p3);
double d4=xmulit(p1,p2,p4);
if(d1*d2<0&&d3*d4<0)
return true;
else if(d1==0&&on_segment(p3,p4,p1))
return true;
else if(d2==0&&on_segment(p3,p4,p2))
return true;
else if(d3==0&&on_segment(p1,p2,p3))
return true;
else if(d4==0&&on_segment(p1,p2,p4))
return true;
return false;
}
int inpoto(point a)
{
int i;
point b,c,d;
b.y=a.y;
b.x=1e15;
int flag=0;
int count=0;
for(i=0;i<n;i++)
{
c = po[i];
d = po[i + 1];
if(on_segment(c,d,a))
return 1;
if(abs(c.y-d.y)<eps)
continue;
if(on_segment(a,b,c))
{
if(c.y>d.y)
count++;
}
else if(on_segment(a,b,d))
{
if(d.y>c.y)
count++;
}
else if(segments_intersect(a,b,c,d))
count++;
}
return count%2;
}
point mid(point &a,point &b)
{
point c;
c.x=(a.x+b.x)/2;
c.y=(a.y+b.y)/2;
return c;
}
double find_ans()
{
point a,b;
int i,j,k,pos=0;
double ans=0;
po[n]=po[0];
for(i=0;i<n;i++)
{
if(one_line(temp.a,temp.b,po[i],po[i+1]))
{
rec[pos++]=po[i];
rec[pos++]=po[i];
continue;
}
if(across(temp.a,temp.b,po[i],po[i+1]))
{
temp1.a=po[i],temp1.b=po[i+1];
rec[pos++]=intersection(temp,temp1);
}
}
sort(rec,rec+pos,cmp);
for(i=0;i<pos-1;i++)
{
if(inpoto(mid(rec[i],rec[i+1])))
ans+=dis(rec[i],rec[i+1]);
}
return ans;
}
int main()
{
int i,j,k;
while(scanf("%d%d",&n,&m))
{
if(m==0 && m==0)
return 0;
for(i=0;i<n;i++)
scanf("%lf%lf",&po[i].x,&po[i].y);
for(i=0;i<m;i++)
{
scanf("%lf%lf%lf%lf",&temp.a.x,&temp.a.y,&temp.b.x,&temp.b.y);
printf("%.3lf\n",find_ans());
}
}
return 0;
}

13
HDOJ/1155_autoAC.cpp Normal file
View File

@ -0,0 +1,13 @@
#include<stdio.h>
int main()
{
double k,l,s,w;
while(scanf("%lf%lf%lf%lf",&k,&l,&s,&w),k||l||s||w)
if(s<l||w*9.81*s-k*(s-l)*(s-l)/2>=0){
if(2*9.81*s-(s>=l)*k*(s-l)*(s-l)/w<=100)
puts("James Bond survives.");
else
puts("Killed by the impact.");
}
else
puts(Stuck in

164
HDOJ/1156_autoAC.cpp Normal file
View File

@ -0,0 +1,164 @@
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string.h>
#include<map>
using namespace std;
struct node{
int l, r, num;
};
bool cmp(pair<int, int> p1, pair<int, int> p2)
{
if (p1.first != p2.first)
return p1.first < p2.first;
else
return p1.second < p2.second;
}
node nodes[2][500000];
vector<pair<int, int>> posp;
vector<int> posy;
map<int,int> pysum;
vector<int> posx[200010];
int ress;
vector<int> reso;
void init(int i,int l,int r)
{
for (int j = 0; j < 2; j++)
{
nodes[j][i].l = l;
nodes[j][i].r = r;
nodes[j][i].num = 0;
}
if (l == r)
return;
else
{
int mid = (l + r) / 2;
init(i * 2, l, mid);
init(i * 2 + 1, mid+1, r);
}
}
void update(int t,int i, int y,int k)//k:0-add,1-nim
{
if (k == 0)
nodes[t][i].num++;
else
nodes[t][i].num--;
if (nodes[t][i].l == nodes[t][i].r)
return;
else
{
int mid = (nodes[t][i].l + nodes[t][i].r) / 2;
if (posy[mid-1] >= y)
update(t, i * 2, y,k);
else
update(t, i * 2 + 1, y,k);
}
}
int query_down(int i, int y)
{
if (posy[nodes[0][i].r-1] < y)
return nodes[0][i].num;
else if (nodes[0][i].l==nodes[0][i].r)
return 0;
else
{
int mid = (nodes[0][i].l + nodes[0][i].r) / 2;
int res = query_down(i*2,y);
if (y > posy[mid-1])
res += query_down(i * 2 + 1, y);
return res;
}
}
int query_up(int i, int y)
{
if (y < posy[nodes[1][i].l-1])
return nodes[1][i].num;
else if (nodes[1][i].l == nodes[1][i].r)
return 0;
else
{
int mid = (nodes[1][i].l + nodes[1][i].r) / 2;
int res = query_up(i * 2 + 1, y);
if (y <= posy[mid-1])
res += query_up(i * 2, y);
return res;
}
}
int main()
{
int n;
while (cin >> n&&n)
{
posp.clear();
posy.clear();
for (int i = 0; i < n; i++)
{
int x, y;
cin >> x >> y;
posp.push_back(make_pair(x,y));
posy.push_back(y);
}
sort(posp.begin(), posp.end(),cmp);
sort(posy.begin(), posy.end());
int cx = posp[0].first;
int mx = 0;
for (int i = 0; i < n; i++)
posx[i].clear();
pysum.clear();
for (int i = 0; i < n; i++)
{
if (posp[i].first != cx)
{
mx++;
cx = posp[i].first;
}
posx[mx].push_back(posp[i].second);
pysum[posp[i].second]++;
}
vector<int>::iterator i=unique(posy.begin(), posy.end());
posy.erase(i, posy.end());
init(1, 1, posy.size());
for (int i = 0; i < n; i++)
update(1, 1, posp[i].second, 0);
ress = -1;
reso.clear();
for (int i = 0; i <= mx; i++)
{
int tress = 999999, treso = -1;
for (int j = 0; j < posx[i].size(); j++)
update(1, 1, posx[i][j], 1);
for (int j = 0; j < posx[i].size(); j++)
{
int ld = query_down(1, posx[i][j]);
int ru = query_up(1, posx[i][j]);
if (tress > ld + ru)
tress = ld + ru;
treso=max(treso,int(n - tress - pysum[posx[i][j]] - posx[i].size() + 1));
}
for (int j = 0; j < posx[i].size(); j++)
update(0, 1, posx[i][j], 0);
if (tress > ress)
{
ress = tress;
reso.clear();
reso.push_back(treso);
}
else if (tress == ress)
{
reso.push_back(treso);
}
}
cout << "Stan: " << ress << "; Ollie:";
sort(reso.begin(), reso.end());
vector<int>::iterator j=unique(reso.begin(), reso.end());
reso.erase(j, reso.end());
for (int i = 0; i < reso.size(); i++)
{
cout <<" "<<reso[i];
}
cout << ";" << endl;
}
return 0;
}

39
HDOJ/1157_autoAC.cpp Normal file
View File

@ -0,0 +1,39 @@
#include<stdio.h>
int Division(int a[100000],int left , int right)
{
int base;
base = a[left];
while(left < right)
{
while(left<right && a[right]>=base)
right--;
a[left]=a[right];
while(left<right && a[left]<=base)
left++;
a[right]=a[left];
}
a[left]=base;
return left;
}
void QuickSort(int a[100000],int left,int right)
{
int i;
if(left<right)
{
i=Division(a,left,right);
QuickSort(a,left,i-1);
QuickSort(a,i+1,right);
}
}
int main()
{
int i,n,a[100000];
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
QuickSort(a,0,n-1);
printf("%d\n",a[(n-1)/2]);
}
return 0;
}

56
HDOJ/1158_autoAC.cpp Normal file
View File

@ -0,0 +1,56 @@
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int dp[15][99999];
int main()
{
int n,i,j,salary,hire,fire,num[15],Min,Max,k,a,b;
while(~scanf("%d",&n),n)
{
scanf("%d%d%d",&hire,&salary,&fire);
Min=99999;
Max=0;
for(i=1;i<=n;i++)
{
scanf("%d",&num[i]);
if(num[i]<Min) Min=num[i];
if(num[i]>Max) Max=num[i];
}
for(i=0;i<=n;i++)
for(j=Min;j<=Max;j++)
{if(i==0)dp[i][j]=0;else dp[i][j]=546548;}
for(i=1;i<=n;i++)
{
for(j=num[i];j<=Max;j++)
{
if(i==1)
{
dp[i][j]=dp[i-1][j]+j*(hire+salary);
}
else
{
for(k=num[i-1];k<=Max;k++)
{
a=dp[i-1][k];
b=j*salary;
if(j>=k)
{
dp[i][j]=min(dp[i][j],a+(j-k)*hire+b);
}
else
{
dp[i][j]=min(dp[i][j],a+(k-j)*fire+b);
}
}
}
}
}
a=546548;
for(i=num[n];i<=Max;i++)
if(dp[n][i]<a) a=dp[n][i];
printf("%d\n",a);
}
return 0;
}

34
HDOJ/1159_autoAC.cpp Normal file
View File

@ -0,0 +1,34 @@
#include<stdio.h>
#include<string.h>
char a[10009],b[10009];
int c[10009][10009];
int max(int x,int y)
{
if(x>y)
return x;
else
return y;
}
int main()
{
int i,j,x,y;
while(scanf("%s %s",a,b)!=EOF)
{
x=strlen(a);
y=strlen(b);
for(i=0;i<=x;i++)
c[0][i]=0;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
if(a[i]==b[j])
c[i+1][j+1]=c[i][j]+1;
else
c[i+1][j+1]=max(c[i][j+1],c[i+1][j]);
}
}
printf("%d\n",c[x][y]);
}
return 0;
}

75
HDOJ/1160_autoAC.cpp Normal file
View File

@ -0,0 +1,75 @@
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
const int MAX=10010;
int DP[MAX];
int rem[MAX];
using namespace std;
typedef struct Mouse
{
int weight;
int speed;
int num;
}mice;
mice s[MAX];
bool cmp(mice x,mice y)
{
if(x.weight==y.weight)
return x.speed<y.speed;
else
return x.weight>y.weight;
}
int main()
{
int n,m,maxn,i,j,k,t,mark;
for(i=1;i<MAX;i++)
rem[i]=i;
k=1;
while(scanf("%d%d",&s[k].weight,&s[k].speed)!=EOF)
{
s[k].num=k;
k+=1;
}
sort(s+1,s+k,cmp);
memset(DP,0,sizeof(DP));
for(i=1,m=0;i<k;i++)
{
maxn=0;
for(j=1;j<i;j++)
{
if(s[i].weight<s[j].weight&&s[i].speed>s[j].speed)
{
if(maxn<DP[j])
{
maxn=DP[j];
mark=s[j].num;
}
}
if(maxn)
rem[s[i].num]=mark;
DP[i]=maxn+1;
if(m<DP[i])
{
m=DP[i];
t=s[i].num;
}
}
}
if(m==1)
{
cout<<1<<endl<<1<<endl;
}
else
{
cout<<m<<endl;
while(rem[t]!=t)
{
cout<<t<<endl;
t=rem[t];
}
cout<<t<<endl;
}
return 0;
}

16
HDOJ/1161_autoAC.cpp Normal file
View File

@ -0,0 +1,16 @@
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main()
{
int i,len;
char s[1000];
while(gets(s))
{
len = strlen(s);
for(i=0;i<len;i++)
if(isupper(s[i]))s[i]=tolower(s[i]);
printf("%s\n",s);
}
return 0;
}

57
HDOJ/1162_autoAC.cpp Normal file
View File

@ -0,0 +1,57 @@
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
int father[10005], Enums, Count;
double MinL;
struct Point{
int begin;
int end;
double Dis;
}P[10005];
int Find(int k){
return father[k]==k?k:father[k]=Find(father[k]);
}
int Cmp(Point a, Point b){
return a.Dis<b.Dis;
}
double Kruskal(){
for(int i=0; i<Count; i++){
father[i] = i;
}
for(int i=0; i<Count; i++){
int a = Find(P[i].begin);
int b = Find(P[i].end);
if(a!=b){
father[b] = a;
MinL += P[i].Dis;
}
}
return MinL;
}
void Init(){
int N;
double x[100], y[100];
while(cin>>N){
for(int i=0; i<N; i++){
cin>>x[i]>>y[i];
}
MinL = 0.0;
Count=0;
for(int i=0; i<N; i++){
for(int j=i+1; j<N; j++){
P[Count].begin = i;
P[Count].end = j;
P[Count].Dis = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
Count++;
}
}
sort(P, P+Count, Cmp);
printf("%.2lf\n", Kruskal());
}
}
int main(){
Init();
}

9
HDOJ/1163_autoAC.cpp Normal file
View File

@ -0,0 +1,9 @@
#include<stdio.h>
int main()
{
int n;
char s[20]="149429719159479789";
while(~scanf("%d",&n),n)
printf("%c\n",s[(n-1)%18]);
return 0;
}

22
HDOJ/1164_autoAC.cpp Normal file
View File

@ -0,0 +1,22 @@
#include<stdio.h>
#include<math.h>
int main()
{
long int x;
int k,i;
while(scanf("%ld",&x)!=EOF)
{
k=sqrt((double)x);
for(i=2;i<=k;i++)
{
if(x%i==0)
{
x=x/i;
printf("%d*",i);
i=1;
k=sqrt((double)x);
}
}
printf("%d\n",x);
}
}

17
HDOJ/1165_autoAC.cpp Normal file
View File

@ -0,0 +1,17 @@
#include<stdio.h>
long int A(long int,long int);
int main()
{
long int n,m;
while(scanf("%ld%ld",&m,&n)!=EOF)
printf("%ld\n",A(m,n));
return 0;
}
long int A(long int m,long int n)
{
if(n==0) return A(m-1,1);
else if(m==0)return n+2;
else if(m==1) return n+2;
else if(m==2) return 2*n+3;
else if(m==3)return A(m,n-1)*2+3;
}

21
HDOJ/1170_autoAC.cpp Normal file
View File

@ -0,0 +1,21 @@
#include<stdio.h>
int main()
{
int n,a,b;
char c;
scanf("%d",&n);
while(n--)
{
getchar();
scanf("%c%d%d",&c,&a,&b);
if(c=='+')
printf("%d\n",a+b);
else if(c=='-')
printf("%d\n",a-b);
else if(c=='*')
printf("%d\n",a*b);
else
a%b?printf("%.2lf\n",a*1.0/b):printf("%d\n",a/b);
}
return 0;
}

49
HDOJ/1171_autoAC.cpp Normal file
View File

@ -0,0 +1,49 @@
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
#include <algorithm>
int dp[1000010];
int v[1000],m[1000];
void zoreone(int v1,int m1,int sum)
{
for(int i=sum;i>=m1;i--)
dp[i]=max(dp[i],dp[i-m1]+v1);
}
void complete(int v1,int m1,int sum)
{
for(int i=m1;i<=sum;i++)
dp[i]=max(dp[i],dp[i-m1]+v1);
}
void multiple(int v1,int m1,int sum,int num)
{
if(m1*num>sum)
complete( v1, m1, sum);
else
{
for(int k=1;k<num;k*=2)
{
zoreone(k*v1,k*m1,sum);
num-=k;
}
zoreone(num*v1,num*m1,sum);
}
}
int main(){
int n,sum,sum1;
while(~scanf("%d",&n)&&(n>=0))
{
sum=0;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&v[i],&m[i]);
sum+=v[i]*m[i];
}
sum1=sum/2;
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
multiple(v[i],v[i],sum1,m[i]);
printf("%d %d\n",sum-dp[sum/2],dp[sum/2]);
}
return 0;
}

77
HDOJ/1172_autoAC.cpp Normal file
View File

@ -0,0 +1,77 @@
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct num
{
char a[5];
int b;
int c;
}st[102];
int main()
{
int i,j,k,key,v;
int n;
int a[4];
char c[5];
while(cin>>n&&n)
{
int count=0;
for(v=0;v<n;v++)
{
cin>>st[v].a>>st[v].b>>st[v].c;
}
for(v=3585;v<=9999;v++)
{
a[0]=v/1000;
a[1]=v%1000/100;
a[2]=v%100/10;
a[3]=v%10;
int flag=0;
for(i=0;i<n;i++)
{
strcpy(c,st[i].a);
int count1=0;
int count2=0;
for(j=0;j<4;j++)
{
if(a[j]==c[j]-'0')
{
count1++;
}
}
for(j=0;j<4;j++)
{
for(k=0;k<4;k++)
{
if(a[j]==c[k]-'0')
{
count2++;
c[k]='#';
break;
}
}
}
if(st[i].b!=count2||st[i].c!=count1)
{
flag=1;
break;
}
}
if(flag==0)
{
count++;
key=v;
}
}
if(count!=1)
{
cout<<"Not sure"<<endl;
}
else
{
cout<<key<<endl;
}
}
return 0;
}

18
HDOJ/1173_autoAC.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include<iostream>
using namespace std;
#include<algorithm>
double x[1000002],y[1000002];
int main()
{
int n;
while(scanf("%d",&n)&&n)
{
for(int i=0;i<n;i++)
scanf("%lf%lf",&x[i],&y[i]);
sort(x,x+n);
sort(y,y+n);
printf("%.2lf %.2f\n",x[n/2],y[n/2]);
}
return 0;
}

35
HDOJ/1174_autoAC.cpp Normal file
View File

@ -0,0 +1,35 @@
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int T;
double h1,r1,x1,y1,z1;
double h2,r2,x2,y2,z2,x3,y3,z3;
while(cin>>T)
{
while(T--)
{
cin>>h1>>r1>>x1>>y1>>z1;
cin>>h2>>r2>>x2>>y2>>z2>>x3>>y3>>z3;
double x4,y4,z4;
x4 = x1 - x2;
y4 = y1 - y2;
z4 = z1 + h1 - r1 - (0.9*h2 + z2 - r2 );
double m,m1,m2;
m = x3*x4 + y3*y4 + z3*z4;
m1 = sqrt(x3*x3 + y3*y3 + z3*z3);
m2 = sqrt(x4*x4 + y4*y4 + z4*z4);
double dcos;
dcos = m/(m1*m2);
if(dcos<0) { cout<<"NO";continue;}
else
{
double d = m2*sqrt(1 - dcos*dcos);
if( d <= r1 ) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
}
return 0;
}

67
HDOJ/1175_autoAC.cpp Normal file
View File

@ -0,0 +1,67 @@
# include<stdio.h>
# include<string.h>
int map[1100][1100],vist[1100][1100],move[4][2]={1,0,0,1,-1,0,0,-1};
int a,b,c,d,flag;
void dfs(int x,int y,int t,int p)
{
int i,x1,y1;
if(t>3)return;
if(x==c&&y==d)
{
flag=1;return;
}
vist[x][y]=1;
if(t!=0)
{
if(map[x][y]!=0)return;
for(i=0;i<4&&!flag;i++)
{
x1=x+move[i][0];
y1=y+move[i][1];
if(vist[x1][y1]==1)continue;
if(p==i)
dfs(x1,y1,t,p);
else
dfs(x1,y1,t+1,i);
vist[x1][y1]=0;
}
}
else
for(i=0;i<4&&!flag;i++)
{
x1=x+move[i][0];
y1=y+move[i][1];
if(vist[x1][y1]==1)continue;
dfs(x1,y1,t+1,i);
vist[x1][y1]=0;
}
}
int main()
{
int n,m,i,j,t;
while(scanf("%d%d",&n,&m),n&&m)
{
memset(map,1,sizeof(map));
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
scanf("%d",&map[i][j]);
scanf("%d",&t);
while(t--)
{
flag=0;
scanf("%d%d%d%d",&a,&b,&c,&d);
if(map[a][b]!=map[c][d] || map[a][b]==0 || a<1||c<1||b<1||d<1||a>n||c>n||b>m||d>m)
printf("NO\n");
else
{
memset(vist,0,sizeof(vist));
dfs(a,b,0,-1);
if(flag)
printf("YES\n");
else
printf("NO\n");
}
}
}
return 0;
}

30
HDOJ/1176_autoAC.cpp Normal file
View File

@ -0,0 +1,30 @@
#include<stdio.h>
#include<string.h>
int a[100008][13];
int max(int a,int b,int c)
{
if(a<b)
a=b;
if(a<c)
a=c;
return a;
}
int main()
{
int i,j,n,x,t,fuck;
while(scanf("%d",&n)==1&&n)
{
memset(a,0,sizeof(a));fuck=0;
for(i=1;i<=n;i++)
{
scanf("%d%d",&x,&t);
if(t>fuck) fuck=t;
a[t][x+1]++;
}
for(i=fuck-1;i>0;i--)
for(j=1;j<=11;j++)
a[i][j]+=max(a[i+1][j],a[i+1][j-1],a[i+1][j+1]);
printf("%d\n",max(a[1][5],a[1][6],a[1][7]));
}
return 0;
}

90
HDOJ/1177_autoAC.cpp Normal file
View File

@ -0,0 +1,90 @@
#include <iostream>
#include <stdio.h>
#include<cstring>
using namespace std;
struct person{
int completed;
int hour;
int minute;
int second;
int judge;
};
int main()
{
int n=0,g=0,s=0,c=0,m=0;
struct person person[131];
int isEarly(struct person[],int a,int b);
while(scanf("%d%d%d%d%d",&n,&g,&s,&c,&m)&&(n||g||s||c||m))
{
for(int i=1;i<=n;i++)
{
scanf("%d %d:%d:%d",&person[i].completed,&person[i].hour,&person[i].minute,&person[i].second);
}
for(int i=1;i<=n;i++)
{
if(i!=m) person[i].judge=0;
else person[i].judge=1;
}
int index=0;
struct person cordinator;
for(int i=1;i<n;i++)
{
index=i;
for(int j=i+1;j<=n;j++)
{
if(person[index].completed<person[j].completed) index=j;
else if(person[index].completed==person[j].completed)
{
if(isEarly(person,index,j)==-1) index=j;
}
}
if(index!=i)
{
cordinator=person[i];person[i]=person[index];person[index]=cordinator;
}
}
int f=1;
while(f)
{
if(person[f].judge==1) {break;}
f++;
}
if(f<=g) cout<<"Accepted today? I've got a golden medal :)"<<endl;
else if(f<=g+s) cout<<"Accepted today? I've got a silver medal :)"<<endl;
else if(f<=g+s+c) cout<<"Accepted today? I've got a copper medal :)"<<endl;
else cout<<"Accepted today? I've got an honor mentioned :)"<<endl;
}
return 0;
}
int isEarly(person person[],int a,int b)
{
if(person[a].hour==person[b].hour)
{
if(person[a].minute==person[b].minute)
{
if(person[a].second==person[b].second)
{
return 0;
}
else if(person[a].second<person[b].second)
return 1;
else return -1;
}
else if(person[a].minute<person[b].minute)
{
return 1;
}
else
{
return -1;
}
}
else if(person[a].hour<person[b].hour)
{
return 1;
}
else
{
return -1;
}
}

19
HDOJ/1178_autoAC.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<stdio.h>
#include<math.h>
int main()
{
int n,i,k;
double s;
while(scanf("%d",&n),n)
{
s=1.0*(n+1)*n/6.0*(n+2);
k=0;
while(s>=10)
{
s=s/10;
k++;
}
printf("%.2lfE%d\n",s,k);
}
return 0;
}

50
HDOJ/1179_autoAC.cpp Normal file
View File

@ -0,0 +1,50 @@
#include<stdio.h>
#include<string.h>
int map[110][110],last_y[110],hav[110],N,M;
int findmax(int m);
int main()
{
int i,j,a,b,Sum;
while(scanf("%d %d",&N,&M)!=EOF)
{
memset(map,0,sizeof(map));
memset(last_y,-1,sizeof(last_y));
Sum=0;
for(i=1;i<=M;i++)
{
scanf("%d",&a);
for(j=0;j<a;j++)
{
scanf("%d",&b);
map[b][i]=1;
}
}
for(i=1;i<=N;i++)
{
if(findmax(i))
{
memset(hav,0,sizeof(hav));
Sum++;
}
}
printf("%d\n",Sum);
}
return 0;
}
int findmax(int m)
{
int i;
for(i=1;i<=M;i++)
{
if(!hav[i]&&map[m][i])
{
hav[i]=1;
if(last_y[i]==-1||findmax(last_y[i]))
{
last_y[i]=m;
return 1;
}
}
}
return 0;
}

137
HDOJ/1180_autoAC.cpp Normal file
View File

@ -0,0 +1,137 @@
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#define v 21
#include<cstring>
using namespace std;
char mapp[21][21];
int x1,x2,y1,y2;
int dir[4][2]={{1,0},{0,-1},{-1,0},{0,1}};
int used2[21][21];
int m,n;
int ans;int used[21][21];
int check(int y,int x)
{
if(y>m||y<1||x>n||x<1)
{
return 1;
}
if(mapp[y][x]=='*'||used[y][x]==1)
return 1;
return 0;
}
struct node{
int x,y,time;
bool friend operator<(node n1,node n2)
{
return n1.time>n2.time;
}
};
int bfs()
{
priority_queue<node>q;
node pre;
int i,X,Y;
pre.x=x1;pre.y=y1;
pre.time=0;
q.push(pre);
while(!q.empty())
{
pre=q.top();
q.pop();
if(pre.x==x2&&pre.y==y2)
{
return pre.time;
}
node next;
if(mapp[pre.y][pre.x]=='.'||mapp[pre.y][pre.x]=='S')
{
if(!used2[pre.y][pre.x])
{
used2[pre.y][pre.x]=1;
next.x=pre.x;next.y=pre.y;next.time=pre.time+1;
q.push(next);
}
}
for(i=0;i<4;i++)
{
X=pre.x+dir[i][0];Y=pre.y+dir[i][1];
if(check(Y,X))
continue;
if(mapp[Y][X]=='.')
{
next.x=X;next.y=Y;next.time=pre.time+1;
used[Y][X]=1;
q.push(next);
}
else if(mapp[Y][X]=='|')
{
if(pre.time%2==0&&(dir[i][1]==1||dir[i][1]==-1))
{
if(check(Y+dir[i][1],X))
continue;
Y+=dir[i][1];
used[Y][X]=1;
next.x=X;next.y=Y;next.time=pre.time+1;
q.push(next);
}
if(pre.time%2==1&&(dir[i][0]==1||dir[i][0]==-1))
{
if(check(Y,X+dir[i][0]))
continue;
X+=dir[i][0];used[Y][X]=1;
next.x=X;next.y=Y;next.time=pre.time+1;
q.push(next);
}
}
else if(mapp[Y][X]=='-')
{
if(pre.time%2==0&&(dir[i][0]==1||dir[i][0]==-1))
{
X+=dir[i][0];
if(check(Y,X))
continue;
used[Y][X]=1;
next.x=X;next.y=Y;next.time=pre.time+1;
q.push(next);
}
else if(pre.time%2==1&&(dir[i][1]==1||dir[i][1]==-1))
{
Y+=dir[i][1];
if(check(Y,X))continue;used[Y][X]=1;
next.x=X;next.y=Y;next.time=pre.time+1;
q.push(next);
}
}
}
}
return -1;
}
int main()
{
while(scanf("%d%d",&m,&n)!=EOF)
{
int i,j;
memset(used,0,sizeof(used));
memset(used2,0,sizeof(used2));
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
{
cin>>mapp[i][j];
if(mapp[i][j]=='T')
{
y2=i;x2=j;
mapp[i][j]='.';
}
if(mapp[i][j]=='S')
{
mapp[i][j]='.';
y1=i;x1=j;
}
}
ans=bfs();
printf("%d\n",ans);
}
return 0;
}

67
HDOJ/1181_autoAC.cpp Normal file
View File

@ -0,0 +1,67 @@
#include <iostream>
#include <cstdio>
#include <string.h>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
int main ()
{
char com[100][100];
int vis[10000];
int i,j,k=0,flag,fk,cot;
while(gets(com[k]))
{
flag=0;
while(com[k][0]!='0')
{
int num=strlen(com[k]);
if(com[k][0]=='b'){flag++;fk=k;}
if(com[k][num-1]=='m')flag++;
k++;
gets(com[k]);
}
if(flag<2)
cout<<"No."<<endl;
else
{
flag=0;
memset(vis,0,sizeof(vis));
queue<string>s;
string t;
vis[fk]=1;
s.push(com[fk]);
while(!s.empty())
{
t=s.front();
s.pop();
int num=t.length();
char c=t[num-1];
if(c=='m')
{
flag=1;
break;
}
else
{
for(i=0;i<k;i++)
{
if(vis[i]==0&&com[i][0]==c)
{
vis[i]=1;
s.push(com[i]);
continue;
}
}
}
}
if(flag)cout<<"Yes."<<endl;
else cout<<"No."<<endl;
}
k=0;
}
return 0;
}

73
HDOJ/1182_autoAC.cpp Normal file
View File

@ -0,0 +1,73 @@
#include <stdio.h>
#include <string.h>
void chessmove(char (*board)[8], char vert1, char hori1, char vert2, char hori2);
void printboard(char (*board)[8]);
int main()
{
char inputbuffer[1000];
char board_buffer[8][8] =
{
{'r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'},
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '},
{'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'},
{'R', 'N', 'B', 'Q', 'K', 'B', 'N', 'R'}
};
char board[8][8];
char vert1, hori1, vert2, hori2;
int end = 1;
while(1)
{
memcpy(board,board_buffer,sizeof(board));
while(1)
{
if(scanf("%d",&end)==EOF)
return 0;
if(end==-1) break;
gets(inputbuffer);
if (sscanf(inputbuffer,"%*c%*c%c%c%*c%c%c", &vert1, &hori1, &vert2, &hori2) != 4)
continue;
chessmove(board, vert1, hori1, vert2, hori2);
if (sscanf(inputbuffer+7,"%*c%*c%c%c%*c%c%c", &vert1, &hori1, &vert2, &hori2) != 4)
continue;
chessmove(board, vert1, hori1, vert2, hori2);
}
printboard(board);
}
return 0;
}
void chessmove(char (*board)[8], char vert1, char hori1, char vert2, char hori2)
{
int v1 = vert1 - 'a', h1 = 7 - hori1 + '1';
int v2 = vert2 - 'a', h2 = 7 - hori2 + '1';
char chessman = board[h1][v1];
board[h1][v1] = ' ';
board[h2][v2] = chessman;
}
void printboard(char (*board)[8])
{
int i, j, cnt;
for (i = 0; i < 8; ++i)
{
for (j = 0; j < 8; )
{
cnt = 0;
while (board[i][j] == ' ' && j < 8)
{
++cnt;
++j;
}
if (cnt > 0)
printf("%d", cnt);
else
printf("%c", board[i][j++]);
}
if (i < 7)
printf("/");
else
printf("\n");
}
}

15
HDOJ/1194_autoAC.cpp Normal file
View File

@ -0,0 +1,15 @@
#include <stdio.h>
int main ()
{
int n,s,d;
scanf ("%d",&n);
while (n--)
{
scanf ("%d%d",&s,&d);
if ((s+d)%2==0&&(s-d)%2==0&&(s+d)/2>=0&&(s-d)/2>=0)
printf ("%d %d",(s+d)/2,(s-d)/2);
else printf ("impossible");
printf ("\n");
}
return 0;
}

86
HDOJ/1195_autoAC.cpp Normal file
View File

@ -0,0 +1,86 @@
#include<iostream>
#include<queue>
using namespace std;
struct note
{
int num[4];
int count;
};
bool mark[10][10][10][10] = { false };
void bfs(note dd, note b1)
{
queue <note> q;
note now, next;
now = dd;
now.count = 0;
q.push(now);
while (!q.empty())
{
now = q.front();
q.pop();
if (now.num[0] == b1.num[0] && now.num[1] == b1.num[1] && now.num[2] == b1.num[2] && now.num[3] == b1.num[3])
{
cout << now.count << endl;
return;
}
for (int i = 0; i<4; i++)
{
next = now;
next.num[i]++;
if (next.num[i] == 10)
next.num[i] = 1;
if (mark[next.num[0]][next.num[1]][next.num[2]][next.num[3]] != true)
{
mark[next.num[0]][next.num[1]][next.num[2]][next.num[3]] = true;
next.count++;
q.push(next);
}
}
for (int i = 0; i<4; i++)
{
next = now;
next.num[i]--;
if (next.num[i] == 0)
next.num[i] = 9;
if (mark[next.num[0]][next.num[1]][next.num[2]][next.num[3]] != true)
{
mark[next.num[0]][next.num[1]][next.num[2]][next.num[3]] = true;
next.count++;
q.push(next);
}
}
for (int i = 0; i<3; i++)
{
next = now;
int temp = next.num[i];
next.num[i] = next.num[i + 1];
next.num[i + 1] = temp;
if (mark[next.num[0]][next.num[1]][next.num[2]][next.num[3]] != true)
{
mark[next.num[0]][next.num[1]][next.num[2]][next.num[3]] = true;
next.count++;
q.push(next);
}
}
}
}
int main()
{
int size;
cin >> size;
for (int i = 0; i<size; i++)
{
memset(mark, false, sizeof(mark));
int a, b;
cin >> a >> b;
note a1, b1;
for (int i = 3; i >= 0; i--)
{
a1.num[i] = a % 10;
a /= 10;
b1.num[i] = b % 10;
b /= 10;
}
bfs(a1, b1);
}
}

13
HDOJ/1196_autoAC.cpp Normal file
View File

@ -0,0 +1,13 @@
#include<iostream>
using namespace std;
int lowbit(int x)
{
return x&-x;
}
int main()
{
int n;
while(cin>>n&&n)
cout<<lowbit(n)<<endl;
return 0;
}

36
HDOJ/1197_autoAC.cpp Normal file
View File

@ -0,0 +1,36 @@
#include<stdio.h>
int check(int n)
{
int sum1=0,sum2=0,sum3=0;
int m;
m=n;
while(m)
{
sum1+=m%10;
m/=10;
}
m=n;
while(m)
{
sum2+=m%12;
m/=12;
}
m=n;
while(m)
{
sum3+=m%16;
m/=16;
}
if(sum1==sum2&&sum2==sum3)
return 1;
return 0;
}
int main()
{
int m=2992;
for(;m<=9999;m++)
{ if(check(m))
printf("%d\n",m);
}
return 0;
}

65
HDOJ/1198_autoAC.cpp Normal file
View File

@ -0,0 +1,65 @@
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn = 52;
int n,m;
int cnt;
int dir[4][2] = {-1,0,0,-1,1,0,0,1};
int arr[11][4] = {{1,1,0,0},{1,0,0,1},{0,1,1,0},{0,0,1,1},
{1,0,1,0},{0,1,0,1},{1,1,0,1},{1,1,1,0},{0,1,1,1},
{1,0,1,1},{1,1,1,1}};
int flag[maxn][maxn];
char Map[maxn][maxn];
void dfs(int x,int y)
{
flag[x][y] = 1;
for(int i = 0; i < 4; i++)
{
if(arr[Map[x][y]-'A'][i])
{
int nx = x+dir[i][0];
int ny = y+dir[i][1];
if(nx < 0 || ny < 0 || nx >= m || ny >= n)
continue;
switch(i)
{
case 0:if(arr[Map[nx][ny]-'A'][2] && !flag[nx][ny])
dfs(nx,ny);
break;
case 1:if(arr[Map[nx][ny]-'A'][3] && !flag[nx][ny])
dfs(nx,ny);
break;
case 2:if(arr[Map[nx][ny]-'A'][0] && !flag[nx][ny])
dfs(nx,ny);
break;
case 3:if(arr[Map[nx][ny]-'A'][1] && !flag[nx][ny])
dfs(nx,ny);
break;
}
}
}
}
int main()
{
while(~scanf("%d%d",&m,&n) && m>0 && n>0)
{
memset(flag,0,sizeof(flag));
for(int i = 0; i < m; i++)
scanf("%s",Map[i]);
cnt = 0;
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
if(!flag[i][j])
{
cnt++;
dfs(i,j);
}
}
}
printf("%d\n",cnt);
}
return 0;
}

47
HDOJ/1199_autoAC.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <iostream>
using namespace std;
char a[100002];
int main()
{
int n,x,y;
char ch;
while(cin>>n)
{
memset(a,'b',sizeof(a));
int maxnum=0,minnum=2e31-1;
for(int i=0;i<n;i++)
{
cin>>x>>y>>ch;
if(y>maxnum)
maxnum=y;
if(x<minnum)
minnum=x;
for(int j=x;j<=y;j++)
a[j]=ch;
}
int sum=0,max1=0,beg=minnum,end=minnum,minpos=-1,maxpos=-1;
for(int i=minnum;i<=maxnum+1;i++)
{
if(a[i]=='b')
{
if(sum>max1)
{
max1=sum;
minpos=beg;
maxpos=end;
}
sum=0;
continue;
}
if(sum==0)
beg=i;
sum++;
end=i;
}
if(max1==0)
cout<<"Oh, my god"<<endl;
else
cout<<minpos<<" "<<maxpos<<endl;
}
return 0;
}