Powered By HC TECH : AutoACer Engine

This commit is contained in:
KiritoTRw 2016-08-12 10:52:18 +08:00 committed by GitHub
parent ed61b5abf1
commit f270b9dcfd
20 changed files with 652 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;
}