From e56ca966bc806f93a4aa79a8a815baea2fe3c52c Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sun, 14 Aug 2016 09:16:58 +0800 Subject: [PATCH] Powered By HC TECH : AutoACer Engine 1400-1499 --- HDOJ/1400_autoAC.cpp | 36 ++++++++ HDOJ/1401_autoAC.cpp | 165 +++++++++++++++++++++++++++++++++ HDOJ/1402_autoAC.cpp | 88 ++++++++++++++++++ HDOJ/1403_autoAC.cpp | 41 ++++++++ HDOJ/1404_autoAC.cpp | 78 ++++++++++++++++ HDOJ/1405_autoAC.cpp | 30 ++++++ HDOJ/1406_autoAC.cpp | 35 +++++++ HDOJ/1407_autoAC.cpp | 17 ++++ HDOJ/1408_autoAC.cpp | 16 ++++ HDOJ/1409_autoAC.cpp | 98 ++++++++++++++++++++ HDOJ/1410_autoAC.cpp | 18 ++++ HDOJ/1411_autoAC.cpp | 16 ++++ HDOJ/1412_autoAC.cpp | 22 +++++ HDOJ/1413_autoAC.cpp | 97 +++++++++++++++++++ HDOJ/1415_autoAC.cpp | 123 ++++++++++++++++++++++++ HDOJ/1416_autoAC.cpp | 45 +++++++++ HDOJ/1417_autoAC.cpp | 54 +++++++++++ HDOJ/1418_autoAC.cpp | 9 ++ HDOJ/1420_autoAC.cpp | 26 ++++++ HDOJ/1421_autoAC.cpp | 40 ++++++++ HDOJ/1422_autoAC.cpp | 52 +++++++++++ HDOJ/1423_autoAC.cpp | 36 ++++++++ HDOJ/1425_autoAC.cpp | 25 +++++ HDOJ/1426_autoAC.cpp | 102 ++++++++++++++++++++ HDOJ/1427_autoAC.cpp | 60 ++++++++++++ HDOJ/1428_autoAC.cpp | 79 ++++++++++++++++ HDOJ/1429_autoAC.cpp | 72 +++++++++++++++ HDOJ/1430_autoAC.cpp | 93 +++++++++++++++++++ HDOJ/1431_autoAC.cpp | 58 ++++++++++++ HDOJ/1432_autoAC.cpp | 84 +++++++++++++++++ HDOJ/1433_autoAC.cpp | 42 +++++++++ HDOJ/1434_autoAC.cpp | 71 ++++++++++++++ HDOJ/1435_autoAC.cpp | 107 +++++++++++++++++++++ HDOJ/1436_autoAC.cpp | 59 ++++++++++++ HDOJ/1437_autoAC.cpp | 32 +++++++ HDOJ/1438_autoAC.cpp | 16 ++++ HDOJ/1439_autoAC.cpp | 55 +++++++++++ HDOJ/1443_autoAC.cpp | 49 ++++++++++ HDOJ/1444_autoAC.cpp | 26 ++++++ HDOJ/1445_autoAC.cpp | 22 +++++ HDOJ/1447_autoAC.cpp | 27 ++++++ HDOJ/1449_autoAC.cpp | 43 +++++++++ HDOJ/1450_autoAC.cpp | 89 ++++++++++++++++++ HDOJ/1451_autoAC.cpp | 29 ++++++ HDOJ/1452_autoAC.cpp | 29 ++++++ HDOJ/1453_autoAC.cpp | 42 +++++++++ HDOJ/1454_autoAC.cpp | 99 ++++++++++++++++++++ HDOJ/1455_autoAC.cpp | 95 +++++++++++++++++++ HDOJ/1456_autoAC.cpp | 64 +++++++++++++ HDOJ/1461_autoAC.cpp | 142 ++++++++++++++++++++++++++++ HDOJ/1462_autoAC.cpp | 160 ++++++++++++++++++++++++++++++++ HDOJ/1465_autoAC.cpp | 15 +++ HDOJ/1466_autoAC.cpp | 24 +++++ HDOJ/1467_autoAC.cpp | 65 +++++++++++++ HDOJ/1469_autoAC.cpp | 185 ++++++++++++++++++++++++++++++++++++ HDOJ/1470_autoAC.cpp | 216 +++++++++++++++++++++++++++++++++++++++++++ HDOJ/1472_autoAC.cpp | 56 +++++++++++ HDOJ/1474_autoAC.cpp | 70 ++++++++++++++ HDOJ/1476_autoAC.cpp | 51 ++++++++++ HDOJ/1479_autoAC.cpp | 78 ++++++++++++++++ HDOJ/1480_autoAC.cpp | 29 ++++++ HDOJ/1482_autoAC.cpp | 67 ++++++++++++++ HDOJ/1483_autoAC.cpp | 111 ++++++++++++++++++++++ HDOJ/1484_autoAC.cpp | 85 +++++++++++++++++ HDOJ/1486_autoAC.cpp | 64 +++++++++++++ HDOJ/1487_autoAC.cpp | 115 +++++++++++++++++++++++ HDOJ/1488_autoAC.cpp | 65 +++++++++++++ HDOJ/1489_autoAC.cpp | 41 ++++++++ HDOJ/1490_autoAC.cpp | 64 +++++++++++++ HDOJ/1491_autoAC.cpp | 60 ++++++++++++ HDOJ/1492_autoAC.cpp | 20 ++++ HDOJ/1493_autoAC.cpp | 66 +++++++++++++ HDOJ/1494_autoAC.cpp | 61 ++++++++++++ HDOJ/1495_autoAC.cpp | 71 ++++++++++++++ HDOJ/1496_autoAC.cpp | 40 ++++++++ HDOJ/1497_autoAC.cpp | 110 ++++++++++++++++++++++ HDOJ/1498_autoAC.cpp | 82 ++++++++++++++++ 77 files changed, 4924 insertions(+) create mode 100644 HDOJ/1400_autoAC.cpp create mode 100644 HDOJ/1401_autoAC.cpp create mode 100644 HDOJ/1402_autoAC.cpp create mode 100644 HDOJ/1403_autoAC.cpp create mode 100644 HDOJ/1404_autoAC.cpp create mode 100644 HDOJ/1405_autoAC.cpp create mode 100644 HDOJ/1406_autoAC.cpp create mode 100644 HDOJ/1407_autoAC.cpp create mode 100644 HDOJ/1408_autoAC.cpp create mode 100644 HDOJ/1409_autoAC.cpp create mode 100644 HDOJ/1410_autoAC.cpp create mode 100644 HDOJ/1411_autoAC.cpp create mode 100644 HDOJ/1412_autoAC.cpp create mode 100644 HDOJ/1413_autoAC.cpp create mode 100644 HDOJ/1415_autoAC.cpp create mode 100644 HDOJ/1416_autoAC.cpp create mode 100644 HDOJ/1417_autoAC.cpp create mode 100644 HDOJ/1418_autoAC.cpp create mode 100644 HDOJ/1420_autoAC.cpp create mode 100644 HDOJ/1421_autoAC.cpp create mode 100644 HDOJ/1422_autoAC.cpp create mode 100644 HDOJ/1423_autoAC.cpp create mode 100644 HDOJ/1425_autoAC.cpp create mode 100644 HDOJ/1426_autoAC.cpp create mode 100644 HDOJ/1427_autoAC.cpp create mode 100644 HDOJ/1428_autoAC.cpp create mode 100644 HDOJ/1429_autoAC.cpp create mode 100644 HDOJ/1430_autoAC.cpp create mode 100644 HDOJ/1431_autoAC.cpp create mode 100644 HDOJ/1432_autoAC.cpp create mode 100644 HDOJ/1433_autoAC.cpp create mode 100644 HDOJ/1434_autoAC.cpp create mode 100644 HDOJ/1435_autoAC.cpp create mode 100644 HDOJ/1436_autoAC.cpp create mode 100644 HDOJ/1437_autoAC.cpp create mode 100644 HDOJ/1438_autoAC.cpp create mode 100644 HDOJ/1439_autoAC.cpp create mode 100644 HDOJ/1443_autoAC.cpp create mode 100644 HDOJ/1444_autoAC.cpp create mode 100644 HDOJ/1445_autoAC.cpp create mode 100644 HDOJ/1447_autoAC.cpp create mode 100644 HDOJ/1449_autoAC.cpp create mode 100644 HDOJ/1450_autoAC.cpp create mode 100644 HDOJ/1451_autoAC.cpp create mode 100644 HDOJ/1452_autoAC.cpp create mode 100644 HDOJ/1453_autoAC.cpp create mode 100644 HDOJ/1454_autoAC.cpp create mode 100644 HDOJ/1455_autoAC.cpp create mode 100644 HDOJ/1456_autoAC.cpp create mode 100644 HDOJ/1461_autoAC.cpp create mode 100644 HDOJ/1462_autoAC.cpp create mode 100644 HDOJ/1465_autoAC.cpp create mode 100644 HDOJ/1466_autoAC.cpp create mode 100644 HDOJ/1467_autoAC.cpp create mode 100644 HDOJ/1469_autoAC.cpp create mode 100644 HDOJ/1470_autoAC.cpp create mode 100644 HDOJ/1472_autoAC.cpp create mode 100644 HDOJ/1474_autoAC.cpp create mode 100644 HDOJ/1476_autoAC.cpp create mode 100644 HDOJ/1479_autoAC.cpp create mode 100644 HDOJ/1480_autoAC.cpp create mode 100644 HDOJ/1482_autoAC.cpp create mode 100644 HDOJ/1483_autoAC.cpp create mode 100644 HDOJ/1484_autoAC.cpp create mode 100644 HDOJ/1486_autoAC.cpp create mode 100644 HDOJ/1487_autoAC.cpp create mode 100644 HDOJ/1488_autoAC.cpp create mode 100644 HDOJ/1489_autoAC.cpp create mode 100644 HDOJ/1490_autoAC.cpp create mode 100644 HDOJ/1491_autoAC.cpp create mode 100644 HDOJ/1492_autoAC.cpp create mode 100644 HDOJ/1493_autoAC.cpp create mode 100644 HDOJ/1494_autoAC.cpp create mode 100644 HDOJ/1495_autoAC.cpp create mode 100644 HDOJ/1496_autoAC.cpp create mode 100644 HDOJ/1497_autoAC.cpp create mode 100644 HDOJ/1498_autoAC.cpp diff --git a/HDOJ/1400_autoAC.cpp b/HDOJ/1400_autoAC.cpp new file mode 100644 index 0000000..1e604f9 --- /dev/null +++ b/HDOJ/1400_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +using namespace std; +int n,m; +long long add; +long long dp[2][1<<12]; +void dfs(int i,int s,int cur) +{ + if(cur==m) {dp[i][s]+=add;return;} + dfs(i,s,cur+1); + if(cur +#include +#include +#include +#define N 8 +using namespace std; +bitset<20000010> vis1,vis2; +int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; +bool map[N][N],flag; +struct point +{ + int x,y; +}; +struct node +{ + point p[4]; +}; +node start,end1; +queue Q1,Q2; +bool cmp(point a,point b) +{ + if(a.x!=b.x) + return a.x=N || y<0 || y>=N) + continue; + temp.p[i].x=x; + temp.p[i].y=y; + if(map[x][y]) + { + int x1=x+dir[k][0]; + int y1=y+dir[k][1]; + if(x1<0 || x1>=N || y1<0 || y1>=N || map[x1][y1]) + continue; + temp.p[i].x=x1;temp.p[i].y=y1; + } + a=get_hash(temp.p); + if(vis1[a]) continue; + if(vis2[a]) { + flag=true; + return ; + } + vis1[a]=true; + Q1.push(temp); + } + } +} +void BFS2() +{ + int a; + int size=Q2.size(); + while(size--) + { + node q=Q2.front(),temp; + Q2.pop(); + get_map(q.p); + for(int i=0;i<4;i++) + for(int k=0;k<4;k++) + { + temp=q; + int x=temp.p[i].x+dir[k][0]; + int y=temp.p[i].y+dir[k][1]; + if(x<0 ||x>=N || y<0 || y>=N) + continue; + temp.p[i].x=x; + temp.p[i].y=y; + if(map[x][y]) + { + int x1=x+dir[k][0]; + int y1=y+dir[k][1]; + if(x1<0 || x1>=N || y1<0 || y1>=N || map[x1][y1]) + continue; + temp.p[i].x=x1;temp.p[i].y=y1; + } + a=get_hash(temp.p); + if(vis2[a]) continue; + if(vis1[a]) { + flag=true; return ; + } + vis2[a]=true; + Q2.push(temp); + } + } +} +int main() +{ + while(scanf("%d %d",&start.p[0].x,&start.p[0].y)==2) + { + start.p[0].x--; + start.p[0].y--; + for(int i=1;i<4;i++) + { + scanf("%d %d",&start.p[i].x,&start.p[i].y); + start.p[i].x--;start.p[i].y--; + } + for(int i=0;i<4;i++) + { + scanf("%d %d",&end1.p[i].x,&end1.p[i].y); + end1.p[i].x--; + end1.p[i].y--; + } + while(!Q1.empty()) + Q1.pop(); + while(!Q2.empty()) + Q2.pop(); + vis1.reset(); + vis2.reset(); + int a; + a=get_hash(start.p); + vis1[a]=true; + int b=get_hash(end1.p); + if(a==b) { + printf("YES\n"); + continue; + } + vis2[b]=true; + Q1.push(start);Q2.push(end1); + int step=8; + flag=false; + while(step--) + { + if(Q1.size()<=Q2.size()) + BFS1(); + else BFS2(); + if(flag) break; + } + if(flag) printf("YES\n"); + else printf("NO\n"); + } + return 0; +} diff --git a/HDOJ/1402_autoAC.cpp b/HDOJ/1402_autoAC.cpp new file mode 100644 index 0000000..94438ab --- /dev/null +++ b/HDOJ/1402_autoAC.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#define N 50010 +using namespace std; +const double pi=acos(-1); +const complex I(0,1); +const double eps=1e-6; +char aa[N],bb[N]; +int ans[4*N]; +complex a[4*N],b[4*N]; +int n; +void initial() +{ + int lenA=strlen(aa),lenB=strlen(bb); + n=max(lenA,lenB); + double t=log2(n); + int tt=int(t); + if(t-tt>0)tt++; + n=1<<(tt+1); + int i; + for(i=0; i * a) +{ + for(int i=1; i>=1); + if(j>i)swap(a[i],a[j]); + } +} +void iterative_FFT(complex *a,int sig) +{ + bitReverse(a); + for(int m=2; m<=n; m<<=1) + { + int mh =m>>1; + for(int i=0; i wi=exp(i*sig*pi/mh*I); + for(int j=i; j u=a[j],t=wi*a[k];; + a[j]=u+t; + a[k]=u-t; + } + } + } + if(sig==-1)for(int i=0; i=0)cout< +#include +using namespace std; +const int Max = 100000 + 10; +char a[Max]; +char b[Max]; +struct Node +{ + char *suf; + bool flag; +}; +Node suffix[Max * 2]; +int com(const void * a, const void *b) +{ + return strcmp(((Node *)a)->suf, ((Node *)b)->suf); +} +int comLen(char *a, char *b) +{ + int len = 0; + while(*a++ == *b++) len ++; + return len; +} +int main() +{ + int max; + while(scanf("%s %s", a, b) != EOF) + { + int lenA = strlen(a); + int lenB = strlen(b); + for(int i=0; i max) + max = temp; + printf("%d\n", max); + } + return 0; +} diff --git a/HDOJ/1404_autoAC.cpp b/HDOJ/1404_autoAC.cpp new file mode 100644 index 0000000..81fe17b --- /dev/null +++ b/HDOJ/1404_autoAC.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +#include +using namespace std; +const int MAXN=1000000; +int sg[MAXN]; +int get_length(int n) +{ + if(n/100000) return 6; + if(n/10000) return 5; + if(n/1000) return 4; + if(n/100) return 3; + if(n/10) return 2; + return 1; +} +void _extend(int n) +{ + int len=get_length(n); + int i; + for(i=len;i>=1;i--) + { + int m=n; + int base=1; + for(int j=1;j +using namespace std; +int main() +{ + int n,num,p=0,i,m,j=1; + while(cin>>n&&n>1) + { + if(p) + cout< +#include +int main() +{ + int a[10004],i,j,t; + memset(a,0,sizeof(a)); + for (i=1;i<10004/2;i++) + { + for (j=i*2;j<=10000;j=j+i) + { + a[j]+=i; + } + } + scanf("%d",&t); + while (t--) + { + int num1,num2,count=0; + scanf("%d%d",&num1,&num2); + if (num1>num2) + { + num1^=num2; + num2^=num1; + num1^=num2; + } + for (i=num1;i<=num2;i++) + { + if (a[i]==i) + { + count++; + } + } + printf("%d\n",count); + } + return 0; +} diff --git a/HDOJ/1407_autoAC.cpp b/HDOJ/1407_autoAC.cpp new file mode 100644 index 0000000..5b4c137 --- /dev/null +++ b/HDOJ/1407_autoAC.cpp @@ -0,0 +1,17 @@ +#include +#include +int main(){ + int num=0; + int x,y,z; + while(scanf("%d",&num)!=EOF){ + for(x=1;x<=sqrt(num*1.0/3);x++) + for(y=x;y<=sqrt((num*1.0-x*x)/2);y++){ + z=sqrt(num-x*x-y*y); + if(z*z==(num-x*x-y*y)){ + printf("%d %d %d\n",x,y,z); + goto exit; + } + } + exit:; + } +} diff --git a/HDOJ/1408_autoAC.cpp b/HDOJ/1408_autoAC.cpp new file mode 100644 index 0000000..6e82000 --- /dev/null +++ b/HDOJ/1408_autoAC.cpp @@ -0,0 +1,16 @@ +#include +#include +#include +#include +using namespace std; +int main() +{ + int i, j, k, N; + double vl, d; + while (scanf("%lf%lf", &vl, &d) == 2) { + double dd = (int) ceil(vl / d); + int n = (int) (sqrt(2 * dd + 0.25) - 0.5001); + printf("%d\n", (int) dd + n); + } + return 0; +} diff --git a/HDOJ/1409_autoAC.cpp b/HDOJ/1409_autoAC.cpp new file mode 100644 index 0000000..424e23d --- /dev/null +++ b/HDOJ/1409_autoAC.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +using namespace std; +char s[200]; +int pz(int x,int y) +{ + int ys=0,i; + for(i=x;i<=y;i++) + { + if(i==x) + { + if(s[i]=='+'||s[i]=='-') + continue; + else if(s[i]>='0'&&s[i]<='9') + ys++; + else + return 0; + } + else + { + if(s[i]>='0'&&s[i]<='9') + ys++; + else + { + return 0; + } + } + } + if(ys>0) + return 1; + else + return 0; +} +int pd(int x,int y) +{ + int ys=0,i; + for(i=x;i<=y;i++) + { + if(i==x) + { + if((s[i]=='+'||s[i]=='-')||(s[i]>='0'&&s[i]<='9')) + continue; + else if(s[i]=='.') + ys++; + else + return 0; + } + else + { + if(s[i]>='0'&&s[i]<='9') + continue; + else if(s[i]=='.') + ys++; + else + return 0; + } + } + if(ys==1) + return 1; + else + return 0; +} +int main() +{ + int t,i,ye,e,T; + scanf("%d",&T); + getchar(); + while(T--) + { + ye=0; + gets(s); + t=strlen(s); + for(i=0;i +#include +int main() +{ + int HP1, HP2, AP1, AP2, N1, N2; + while(scanf("%d%d%d%d", &HP1, &HP2, &AP1, &AP2) != EOF){ + double ans = 0, tmp = 0; + N1 = (HP2 - 1) / AP1 + 1; + N2 = (HP1 - 1) / AP2 + 1; + ans = pow(0.5, N1); + for(int i = 1; i < N2; ++i){ + tmp += log10(N1 - 1.0 + i) - log10(i * 1.0); + ans += pow(10, tmp + (N1 + i) * log10(0.5)); + } + printf("%.4lf\n", ans * 100); + } + return 0; +} diff --git a/HDOJ/1411_autoAC.cpp b/HDOJ/1411_autoAC.cpp new file mode 100644 index 0000000..5b17822 --- /dev/null +++ b/HDOJ/1411_autoAC.cpp @@ -0,0 +1,16 @@ +#include +#include +#include +using namespace std; +int main() +{ + double a,b,c,m,n,l,v; + while(scanf("%lf%lf%lf%lf%lf%lf", &a, &c, &b, &n, &l, &m)!=EOF) + { + v=(double)sqrt((4.0*a*a*b*b*c*c-a*a*(b*b+c*c-m*m)*(b*b+c*c-m*m)- + b*b*(c*c+a*a-n*n)*(c*c+a*a-n*n)-c*c*(a*a+b*b-l*l)* + (a*a+b*b-l*l)+(a*a+b*b-l*l)*(b*b+c*c-m*m)*(c*c+a*a-n*n)))/12.0; + printf("%.4lf\n", v); + } + return 0; +} diff --git a/HDOJ/1412_autoAC.cpp b/HDOJ/1412_autoAC.cpp new file mode 100644 index 0000000..6c23dcd --- /dev/null +++ b/HDOJ/1412_autoAC.cpp @@ -0,0 +1,22 @@ +#include +#include +int p[20005]; +using namespace std; +int main() +{ + int a,b,i; + while(scanf("%d%d",&a,&b)!=EOF) + { + for(i=0;i +#include +#include +#include +#include +using namespace std; +const int FILEE = 0, DIR = 1; +char createRes[2][30] = { "file already exist", "directory already exist" }; +char delRes[2][30] = { "no such file", "can not delete the directory" }; +struct F { + int head, next, type, fa; + string name; + F() { + } + F(int h, int n, int t, int f, string s) : + head(h), next(n), type(t), fa(f), name(s) { + } +}; +int tot, cur; +vector V; +void cd(const char *com) { + int i = 1; + if (!strcmp(com, "\\")) { + cur = 0; + } else if (!strcmp(com, "..")) { + cur = V[cur].fa; + } else { + for (i = V[cur].head; i > 0; i = V[i].next) { + if (V[i].type == DIR && !strcmp(V[i].name.c_str(), com)) { + cur = i; + break; + } + } + } + puts(i ? "success" : "no such directory"); +} +void create(const char *com, int type) { + int i = 1; + if (!strcmp(com, "\\")) { + } else if (!strcmp(com, "..")) { + } else { + for (i = V[cur].head; i > 0; i = V[i].next) { + if (V[i].type == type && !strcmp(V[i].name.c_str(), com)) { + break; + } + } + if (!i) { + V.push_back(F(0, V[cur].head, type, cur, com)); + V[cur].head = tot++; + } + } + puts(i ? createRes[type] : "success"); +} +void del(const char *com, int type) { + int i = 0; + if (!strcmp(com, "\\")) { + } else if (!strcmp(com, "..")) { + } else { + int *p = &V[cur].head; + for (i = V[cur].head; i > 0; i = V[i].next) { + if (V[i].type == type && !strcmp(V[i].name.c_str(), com)) { + if (type == DIR && V[i].head) + continue; + *p = V[i].next; + break; + } + p = &V[i].next; + } + } + puts(i ? "success" : delRes[type]); +} +int main() { + char op[9], com[30]; + V.push_back(F(0, 0, DIR, 0, "\\")); + ++tot; + while (scanf("%s%s", op, com) != EOF) { + switch (op[0]) { + case 'C': + if (op[1] == 'D') { + cd(com); + } else { + create(com, FILEE); + } + break; + case 'M': + create(com, DIR); + break; + case 'D': + del(com, FILEE); + break; + case 'R': + del(com, DIR); + break; + } + } + return 0; +} diff --git a/HDOJ/1415_autoAC.cpp b/HDOJ/1415_autoAC.cpp new file mode 100644 index 0000000..1411df3 --- /dev/null +++ b/HDOJ/1415_autoAC.cpp @@ -0,0 +1,123 @@ +#include +#include +#include +char op[7][10]= {"","fill A","fill B","empty A","empty B","pour A B","pour B A"}; +struct state +{ + int a,b; + state() {}; + state(int _a,int _b) + { + a=_a; + b=_b; + } +}; +struct p +{ + int x,y; + p() {}; + p(int _y,int _x) + { + x=_x; + y=_y; + } +} mp[1001][1001]; +int A,B,n,vis[1001][1001]; +void print(int y,int x) +{ + if(vis[y][x]!=-1) + print(mp[y][x].y,mp[y][x].x); + if(y||x){ + puts(op[vis[y][x]]); + } +} +void bfs() +{ + std::queueq; + memset(vis,0,sizeof(vis)); + q.push(state(0,0)); + vis[0][0]=-1; + mp[0][0]=p(0,0); + while(!q.empty()) + { + state cur=q.front(); + q.pop(); + int x=cur.b,y=cur.a; + if(x==n) + { + print(y,x); + return ; + } + int yy=A; + if(y0) + { + yy=0; + if(!vis[yy][x]) + { + vis[yy][x]=3; + q.push(state(yy,x)); + mp[yy][x]=p(y,x); + } + } + if(x>0) + { + xx=0; + if(!vis[y][xx]) + { + vis[y][xx]=4; + q.push(state(y,xx)); + mp[y][xx]=p(y,x); + } + } + if(y>0) + { + xx=x+y;yy=0; + if(xx>B){ + yy=xx-B; + xx=B; + } + if(!vis[yy][xx]) + { + vis[yy][xx]=5; + q.push(state(yy,xx)); + mp[yy][xx]=p(y,x); + } + } + if(x>0) + { + yy=y+x;xx=0; + if(yy>A){ + xx=yy-A; + yy=A; + } + if(!vis[yy][xx]) + { + vis[yy][xx]=6; + q.push(state(yy,xx)); + mp[yy][xx]=p(y,x); + } + } + } +} +int main(void) +{ + while(~scanf("%d%d%d",&A,&B,&n)) + { + bfs(); + printf("success\n"); + } + return 0; +} diff --git a/HDOJ/1416_autoAC.cpp b/HDOJ/1416_autoAC.cpp new file mode 100644 index 0000000..d5d3b7b --- /dev/null +++ b/HDOJ/1416_autoAC.cpp @@ -0,0 +1,45 @@ +#include +#include +#define MAX(x,y) x>y?x:y +#define MIN(x,y) x +#include +#include +using namespace std; +struct data +{ + int x1,y1,z1; + int x2,y2,z2; + data(){} + data(int _x,int _y,int _z,int _d) + { + x1=_x;y1=_y;z1=_z; + x2=_x+_d;y2=_y+_d;z2=_z+_d; + } + data(int _x1,int _y1,int _z1,int _x2,int _y2,int _z2) + { + x1=_x1;y1=_y1;z1=_z1; + x2=_x2;y2=_y2;z2=_z2; + } + bool ok() + { + return x1 +#include +int main() +{ + __int64 n,m,r; + while(scanf("%I64d%I64d",&n,&r)&&(n||r)) + printf("%I64d\n",r+n-2); + return 0; +} diff --git a/HDOJ/1420_autoAC.cpp b/HDOJ/1420_autoAC.cpp new file mode 100644 index 0000000..463acfa --- /dev/null +++ b/HDOJ/1420_autoAC.cpp @@ -0,0 +1,26 @@ +#include +int main() +{ + __int64 a,b,c,i,n,f,d,e; + scanf("%I64d",&n); + while(n--) + { + scanf("%I64d%I64d%I64d",&a,&b,&c); + f=0; + e=a; + for(i=1;i<=b;i++) + { + d=a%c; + a=e*d; + if(a==0) + { + f=1; + printf("0\n"); + break; + } + } + if(!f) + printf("%I64d\n",d); + } + return 0; +} diff --git a/HDOJ/1421_autoAC.cpp b/HDOJ/1421_autoAC.cpp new file mode 100644 index 0000000..04ec4ee --- /dev/null +++ b/HDOJ/1421_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +#define min(a,b) a=2*i) + { + select[j][i]=min(select[j-1][i],select[j-2][i-1]+(thing[j]-thing[j-1])*(thing[j]-thing[j-1])); + } + else + select[j][i]=select[j-2][i-1]+(thing[j]-thing[j-1])*(thing[j]-thing[j-1]); + } + } + printf("%d\n",select[n][k]); + return 0; +} +int main() +{ + while(scanf("%d%d",&n,&k)!=EOF&&n>=2*k&&n<2000&&k>=1) + { + for(int i=1;i<=n;i++) + scanf("%d",&thing[i]); + dp(); + } + return 0; +} diff --git a/HDOJ/1422_autoAC.cpp b/HDOJ/1422_autoAC.cpp new file mode 100644 index 0000000..85b1a52 --- /dev/null +++ b/HDOJ/1422_autoAC.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int num[100005]; +int main() +{ + int n; + while(scanf("%d",&n)==1) + { + for(int i=1;i<=n;i++) + { + int a,b; + scanf("%d%d",&a,&b); + num[i]=a-b; + } + int i=1,j=n; + int maxn=0; + while(i<=n) + { + int sum=0; + int x=i,y=j; + int flag=0; + while(1) + { + sum+=num[x]; + if(sum<0) + break; + x++; + flag++; + if(x-1==y) + break; + if(x>n) + { + x=1; + } + } + i=i+flag+1; + maxn=max(maxn,flag); + j+=flag+1; + if(j>n) + j-=n; + } + printf("%d\n",maxn); + } +} diff --git a/HDOJ/1423_autoAC.cpp b/HDOJ/1423_autoAC.cpp new file mode 100644 index 0000000..db85c61 --- /dev/null +++ b/HDOJ/1423_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +#include +#define maxn 509 +using namespace std; +int a[maxn],b[maxn],dp[maxn][maxn]; +int main() +{ + int t,i,j,k,l,n,m; + scanf("%d",&t); + while(t--) + { + int ans=-1; + scanf("%d",&n); + for(i=1;i<=n;i++) + scanf("%d",a+i); + scanf("%d",&m); + for(i=1;i<=m;i++) + scanf("%d",b+i); + for(i=1;i<=n;i++) + { + int max=0; + for(j=1;j<=m;j++) + { + if(maxb[j])max=dp[i-1][j]; + if(a[i]!=b[j])dp[i][j]=dp[i-1][j]; + else dp[i][j]=max+1; + if(dp[i][j]>ans) + ans=dp[i][j]; + } + } + printf("%d\n",ans); + if(t) + puts(""); + } +} diff --git a/HDOJ/1425_autoAC.cpp b/HDOJ/1425_autoAC.cpp new file mode 100644 index 0000000..e430eda --- /dev/null +++ b/HDOJ/1425_autoAC.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#define N 1000000 +using namespace std; +int a[N]; +int main() +{ + int n,m,i,flag=0; + while(scanf("%d%d",&n,&m)!=EOF){ + for(i=0;i1;i--){ + printf(" %d",a[flag]); + flag--; + } + cout< +#include +#include +using namespace std; +char mmp[20]; +int mp[10][10]; +int vis1[10][10],vis2[10][10],vis3[4][4][10]; +int OK=0; +void dfs(int x,int y) +{ + if(OK) return; + if(x>9&&!OK) + { + for(int i=1;i<=9;i++) + { + for(int j=1;j<=9;j++) + { + if(j!=1) printf(" "); + printf("%d",mp[i][j]); + } + putchar(10); + } + OK=1; + return ; + } + int tx,ty; + if(mp[x][y]!=0) + { + tx=x; ty=y+1; + if(ty==10) + { + ty=1; + tx++; + } + dfs(tx,ty); + } + else if(mp[x][y]==0) + { + for(int i=1;i<=9;i++) + { + if(vis1[x][i]==0&&vis2[y][i]==0&&vis3[(x-1)/3+1][(y-1)/3+1][i]==0) + { + vis1[x][i]=1; + vis2[y][i]=1; + vis3[(x-1)/3+1][(y-1)/3+1][i]=1; + mp[x][y]=i; + tx=x; ty=y+1; + if(ty==10) + { + ty=1; + tx++; + } + dfs(tx,ty); + mp[x][y]=0; + vis1[x][i]=0; + vis2[y][i]=0; + vis3[(x-1)/3+1][(y-1)/3+1][i]=0; + } + } + } +} +int main() +{ + int cnt=1;int first=1; +while(gets(mmp)) +{ + for(int i=0;i<=16;i+=2) + { + if(mmp[i]!='?') + { + mp[cnt][(i+2)/2]=mmp[i]-'0'; + vis1[cnt][mp[cnt][(i+2)/2]]=1; + vis2[(i+2)/2][mp[cnt][(i+2)/2]]=1; + vis3[(cnt-1)/3+1][((i+2)/2-1)/3+1][mp[cnt][(i+2)/2]]=1; + } + else + mp[cnt][(i+2)/2]=0; + } + cnt++; + if(cnt==10) + { + cnt=1; + OK=0; + if(first) + { + first=0; + } + else + { + putchar(10); + } + dfs(1,1); + cnt=1; + memset(vis1,0,sizeof(vis1)); + memset(vis2,0,sizeof(vis2)); + memset(vis3,0,sizeof(vis3)); + } + if(cnt==1) + getchar(); +} + return 0; +} diff --git a/HDOJ/1427_autoAC.cpp b/HDOJ/1427_autoAC.cpp new file mode 100644 index 0000000..6fb625f --- /dev/null +++ b/HDOJ/1427_autoAC.cpp @@ -0,0 +1,60 @@ +#include +#include +using namespace std; +int res[4]; +void dfs(int sum, int cur, int temp); +bool flag = 0; +int main() +{ + char s[3]; + int i,j,k; + while(1) + { + for(i = 0;i < 4;i ++) + { + if(scanf("%s",s) == EOF) return 0; + if(s[0] == 'A') res[i] = 1; + else if(s[0] == 'J') res[i] = 11; + else if(s[0] == 'Q') res[i] = 12; + else if(s[0] == 'K') res[i] = 13; + else if(s[0] == '1' && s[1] == '0') res[i] = 10; + else res[i] = s[0] - '0'; + } + sort(res, res+4); + flag = 0; + do + { + dfs(res[0], 1, res[1]); + }while(next_permutation(res, res+4)&&!flag); + if(flag) printf("Yes\n"); + else printf("No\n"); + } + return 0; +} +void dfs(int sum, int cur, int temp) +{ + if(flag) + return; + if(cur==3) + { + if(sum+temp==24) + flag=1; + if(sum-temp==24) + flag=1; + if(sum*temp==24) + flag=1; + if(temp!=0&&sum%temp==0&&sum/temp==24) + flag=1; + return; + } + dfs(sum+temp, cur+1, res[cur+1]); + dfs(sum-temp, cur+1, res[cur+1]); + dfs(sum*temp, cur+1, res[cur+1]); + if(temp!=0&&sum%temp==0) + dfs(sum/temp, cur+1, res[cur+1]); + dfs(sum, cur+1, temp+res[cur+1]); + dfs(sum, cur+1, temp-res[cur+1]); + dfs(sum, cur+1, temp*res[cur+1]); + if(res[cur+1]!=0&&temp%res[cur+1]==0) + dfs(sum, cur+1, temp/res[cur+1]); +} diff --git a/HDOJ/1428_autoAC.cpp b/HDOJ/1428_autoAC.cpp new file mode 100644 index 0000000..7d3e7dd --- /dev/null +++ b/HDOJ/1428_autoAC.cpp @@ -0,0 +1,79 @@ +#include +using namespace std; +#include +#include +#include +#include +#include +#define N 51 +struct node{ + int x,y; + node(int a,int b) + { + x=a; y=b; + } + node(){}; +}; +int key[4][2]={0,1,0,-1,1,0,-1,0}; +int n,map[N][N],d[N][N]; +long long f[N][N]; +void find() +{ + int i; + node s; + queue Q; + memset(d,1,sizeof(d)); + d[n][n]=map[n][n]; + Q.push(node(n,n)); + while (!Q.empty()) + { + s=Q.front(); + Q.pop(); + for (i=0;i<4;++i) + { + int x,y; + x=s.x+key[i][0]; y=s.y+key[i][1]; + if (x>0&&x<=n && y>0&&y<=n) + { + if (d[x][y]>d[s.x][s.y]+map[x][y]) + { + d[x][y]=d[s.x][s.y]+map[x][y]; + Q.push(node(x,y)); + } + } + } + } +} +long long dp(int x,int y) +{ + if (f[x][y]!=-1) return f[x][y]; + int i; + long long t=0; + for (i=0;i<4;++i) + { + int x1,y1; + x1=x+key[i][0]; y1=y+key[i][1]; + if (x1>0&&x1<=n && y1>0&&y1<=n) + if (d[x1][y1] +#include +#include +#include +#define M 21 +#define KEY 10 +using namespace std; +typedef struct tP{ + int x,y,t,key; + tP(){} + tP(int x,int y,int t,int key):x(x),y(y),t(t),key(key){} +}P; +char mat[M][M]; +bool mark[1<q; +int dir[][2]={{0,1},{0,-1},{1,0},{-1,0}}; +int K(char c) +{ + return c-(isupper(c)?'A':'a'); +} +int Wall(int x,int y) +{ + if(x<0||x>=n||y<0||y>=m) return true; + if(mat[x][y]=='*') return true; + return false; +} +int Bfs(int cx,int cy) +{ + P cur; + int x,y,t,key,i; + while(!q.empty()) q.pop(); + memset(mark,false,sizeof(mark)); + mark[0][cx][cy]=true; + q.push(tP(cx,cy,0,0)); + while(!q.empty()){ + cur=q.front();q.pop(); + if(cur.t>=T) break;//濡娣卞害澶тT锛 + for(i=0;i<4;i++){ + x=cur.x+dir[i][0]; + y=cur.y+dir[i][1]; + t=cur.t+1;key=cur.key; + if(Wall(x,y)||mark[key][x][y]) continue; + if(isupper(mat[x][y])&&!(key&(1< +#include +#include +#include +#include +const int M = 50000; +using namespace std; +struct node{ + string s, path; + int val; +}; +const int f[] = {1, 1, 2, 6, 24, 120, 720, 5040, 5040*8}; +string ans[M]; +bool vis[M]; +int cal(string s){ + int sum = 0; + for(int i = 0; i < 8; ++ i){ + int cnt = 0; + for(int j = i+1; j < 8; ++ j) + if(s[j] < s[i]) ++cnt; + sum += cnt*f[7-i]; + } + return sum; +} +string tran(string s, int num){ + //string res = ""; + int i; + if(num == 0){ + for(i = 0; i < 4; ++ i){ + swap(s[i], s[i+4]); + } + } + else if(num == 1){ + char t= s[3]; + for(i = 2; i >= 0; -- i) s[i+1] = s[i]; + s[0] = t; + t = s[7]; + for(i = 6; i >= 4; -- i) s[i+1] = s[i]; + s[4] = t; + } + else{ + char t = s[1]; + s[1] = s[5]; s[5] = s[6]; s[6] = s[2]; + s[2] = t; + } + return s; +} +void bfs(string st){ + memset(vis, 0, sizeof(vis)); + queue q; + node t; + t.s = st; + t.val = cal(t.s); + t.path = ""; + ans[t.val] = t.path; + vis[t.val] = 1; + q.push(t); + while(!q.empty()){ + node temp = q.front(); q.pop(); + for(int i = 0; i < 3; ++ i){ + node cur = temp; + cur.path += (i+'A'); + string a = tran(cur.s, i); + int k = cal(a); + if(!vis[k]){ + cur.s = a; + cur.val = k; + ans[cur.val] = cur.path; + vis[k] = 1; + q.push(cur); + } + } + } +} +int main(){ + string st = "12345678"; + bfs(st); + string en, ss; + int i; + while(cin >> ss >> en){ + swap(ss[4], ss[7]); + swap(ss[5], ss[6]); + swap(en[4], en[7]); + swap(en[5], en[6]); + string mm(8, 'a'); + for(i = 0; i < 8; ++ i) mm[ss[i]-'0'] = i+'1'; + string de; + for(i = 0; i < 8; ++ i) de += mm[en[i]-'0']; + int k = cal(de); + cout << ans[k]< +#include +#include +int p[20000]; +bool sushu(int a) +{ + int i; + for(i=2;i<=sqrt((double)(a));i++) + { + if(a%i==0) + return 0; + } + return 1; +} +bool huiwen(int a) +{ + int b[44]; + int l=0,i; + int c=a; + while(a) + { + b[l++]=a%10; + a/=10; + } + for(i=0;i=a &&p[i]<=b) + printf("%d\n",p[i]); + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1432_autoAC.cpp b/HDOJ/1432_autoAC.cpp new file mode 100644 index 0000000..79fa631 --- /dev/null +++ b/HDOJ/1432_autoAC.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define ISZREO(x) (fabs(x)<1e-7) +const double PI = acos(-1.0); +struct Point +{ + double x,y; +}a[1100],c[1100],Q; +double b[800]; +void fun1(int n) +{ + int i; + for(i=0;ians) + { + ans=cy; + p=ji; + } + } + } + } + if(ans == 0)ans++; + if(!ISZREO(p))ans++; + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/1433_autoAC.cpp b/HDOJ/1433_autoAC.cpp new file mode 100644 index 0000000..f700890 --- /dev/null +++ b/HDOJ/1433_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +using namespace std; +char s[300]; +int len; +bool flag; +bool OK( int x,int y ){ + if( x == y ){ + if( s[x] >= 'p' && s[x] <= 'z' ) + return true; + else return false; + } + if( s[x] == 'N' ){ + if( OK(x+1,y) ) + return true; + else return false; + } + if( s[x] == 'C' || s[x] == 'D' || s[x] == 'E' || s[x] == 'I' ){ + for( int i = x+1 ; i <= y ; ++i ) + if( OK(x+1,i) && OK(i+1,y) ) + return true; + return false; + } + return false; +} +int main(){ + while(scanf("%s",s)!=EOF){ + flag = false; + len = strlen(s); + if( len == 1 && ( s[0] >= 'p' && s[0] <= 'z' ) ) + flag = true; + else{ + if( OK(0,len-1) ) + flag = true; + } + if( flag ) + printf("YES\n"); + else printf("NO\n"); + } + return 0; +} diff --git a/HDOJ/1434_autoAC.cpp b/HDOJ/1434_autoAC.cpp new file mode 100644 index 0000000..c277649 --- /dev/null +++ b/HDOJ/1434_autoAC.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +using namespace std; +struct node +{ + int RP; + char name[25]; + bool operator < (const node a) const + { + if(RP==a.RP) + { + if(strcmp(name,a.name)>0) + return 0; + else + return 1; + } + return RP>a.RP; + } +}t; +priority_queue q[10011]; +int main() +{ + int M,N,k; + int i,j,x1,x2; + char ch[20]; + while(scanf("%d%d",&M,&N)!=EOF) + { + for(i=0;i<10011;i++) + { + while(!q[i].empty()) + q[i].pop(); + } + for(i=1;i<=M;i++) + { + scanf("%d",&k); + for(j=0;j +#include +#include +#include +#include +#include +#include +using namespace std; +#define N 205 +int engage[N],n; +int boy[N][N],girl[N][N]; +void Gale_Shapley(){ + queue q; + int boyid,girlid; + for(int i=1;i<=n;i++){ + engage[i]=0; + boy[i][0]=1; + q.push(i); + } + while(!q.empty()){ + boyid=q.front(); + girlid=boy[boyid][boy[boyid][0]++]; + if(engage[girlid]==0){ + engage[girlid]=boyid; + q.pop(); + } + else{ + int i; + for(i=1;i<=n;i++) + if(girl[girlid][i]==boyid||girl[girlid][i]==engage[girlid]) + break; + if(girl[girlid][i]==boyid){ + q.push(engage[girlid]); + engage[girlid]=boyid; + q.pop(); + } + } + } +} +struct dis{ + double s; + double c; + int id; +}; +struct type{ + double c; + double x,y,z; + dis D[N]; +}O[N],I[N]; +void cal_dis(int x){ + for(int i=1;i<=n;i++){ + double d=0; + d+=(O[x].x-I[i].x)*(O[x].x-I[i].x); + d+=(O[x].y-I[i].y)*(O[x].y-I[i].y); + d+=(O[x].z-I[i].z)*(O[x].z-I[i].z); + d=sqrt(d); + O[x].D[i].s=d; + O[x].D[i].id=i; + O[x].D[i].c=I[i].c; + I[i].D[x].s=d; + I[i].D[x].id=x; + I[i].D[x].c=O[x].c; + } +} +bool cmp(dis a,dis b){ + if(a.s==b.s) + return a.c>b.c; + return a.s +#include +#define MAXN 1001 +__int64 com[MAXN][MAXN]; +void get_Combination(int n) +{ + int i, j; + memset(com, 0, sizeof(com)); + com[0][0] = 1; + for (i = 1; i <= n; i++) + { + com[i][0] = 1; + for (j = 1; j <= i; j++) com[i][j] = com[i-1][j-1] + com[i-1][j]; + } +} +int n, m, dlen; +__int64 d[MAXN]; +__int64 p1[MAXN], p2[MAXN]; +int main() +{ + int i, j, k; + get_Combination(MAXN); + while (~scanf("%d %d", &n, &m)) + { + memset(p1, 0, sizeof(p1)); + memset(p2, 0, sizeof(p2)); + for (i = 0; i < n; i++) + { + scanf("%d", &dlen); + for (j = 0; j < dlen; j++) scanf("%I64d", &d[j]); + if (i == 0) + { + for (j = 0; j < dlen; j++) + { + if (d[j] > m) continue; + p1[d[j]] = com[m][d[j]]; + } + continue; + } + for (j = m; j >= 0; j--) + if (p1[j] != 0) + { + for (k = 0; k < dlen; k++) + { + if (j + d[k] > m) break; + p2[j+d[k]] += com[m-j][d[k]] * p1[j]; + } + p2[j] = p1[j]; + } + for (j = 0; j <= m; j++) + { + p1[j] = p2[j]; + p2[j] = 0; + } + } + printf("%I64d\n", p1[m]); + } + return 0; +} diff --git a/HDOJ/1437_autoAC.cpp b/HDOJ/1437_autoAC.cpp new file mode 100644 index 0000000..442cec1 --- /dev/null +++ b/HDOJ/1437_autoAC.cpp @@ -0,0 +1,32 @@ +#include +#include +using namespace std; +double dp[3][3][1002],map[3][3]; +double DFS(int i,int j,int n){ + if(dp[i][j][n]!=-1) return dp[i][j][n]; + dp[i][j][n] = 0; + for(int k = 0;k<3;k++) + dp[i][j][n]+=DFS(i,k,n-1)*map[k][j]; + return dp[i][j][n]; +} +int main(){ + int T,m,a,b,n; + scanf("%d",&T); + while(T--){ + for(int i = 0;i<3;i++) + for(int j = 0;j<3;j++) + for(int k = 0;k<1002;k++) + dp[i][j][k] = -1; + for(int i = 0;i<3;i++) + for(int j = 0;j<3;j++){ + scanf("%lf",&map[i][j]); + dp[i][j][1] = map[i][j]; + } + scanf("%d",&m); + for(int i = 0;i +#include +using namespace std; +int main(){ +int i; +long long a[32] = { 0, 0, 0 }, c = 0, b = 2,t; +for (i = 3; i < 32; ++i) +{ + a[i] = a[i - 1] * 4 + (long long)(pow(2, i - 1) - 2) * 2 + (c + b) * 2; + t = c + b*2; + b = (c + b)*2 + 2; + c = t; +} +for (i = 2; i < 32; ++i) + cout << "N=" << i <<": " << a[i] << endl; +} diff --git a/HDOJ/1439_autoAC.cpp b/HDOJ/1439_autoAC.cpp new file mode 100644 index 0000000..65bf29d --- /dev/null +++ b/HDOJ/1439_autoAC.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +using namespace std; +const int maxn = 205; +char s[maxn], ans[maxn]; +int a[maxn]; +bool vis[maxn]; +pair belong[maxn]; +vector group[maxn], tmp; +int main() +{ + int n, i, j, cnt, k; + while (scanf("%d", &n), n) + { + for (i = 1; i <= n; ++i) + { + scanf("%d", &k); + a[i] = k; + } + memset(vis, 0, sizeof(vis)); + for (i = 0; i < n; ++i) group[i].clear(); + cnt = 0; + for (i = 1; i <= n; ++i) + { + if (!vis[i]) + { + for (j = a[i]; !vis[j]; j = a[j]) + { + belong[j] = make_pair(cnt, group[cnt].size()); + group[cnt].push_back(j); + vis[j] = true; + } + ++cnt; + } + } + while (scanf("%d", &k), k) + { + getchar(); + gets(s + 1); + for (i = strlen(s + 1) + 1; i <= n; ++i) + s[i] = ' '; + for (i = 1; i <= n; ++i) + { + tmp = group[belong[i].first]; + ans[tmp[(belong[i].second + k) % tmp.size()]] = s[i]; + } + ans[n + 1] = 0; + puts(ans + 1); + } + putchar(10); + } + return 0; +} diff --git a/HDOJ/1443_autoAC.cpp b/HDOJ/1443_autoAC.cpp new file mode 100644 index 0000000..04b545b --- /dev/null +++ b/HDOJ/1443_autoAC.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int n, a, b; +int con[15]; +int run(int a, int b) +{ + int cnt = 0; + int sum = 2 * a; + int index = b % (2 * a); + if(index == 0) index = sum; + while(index > a) + { + sum--; + index = (index + b - 1) % sum; + if(index == 0) index = sum; + cnt ++; + } + return cnt; +} +int solve(int a) +{ + for(int i=a+1; ; i++) + { + if(run(a, i) == a) return i; + } +} +void init() +{ + for(int i=1; i<=14; i++) + { + con[i] = solve(i); + } +} +int main() +{ + init(); + while(cin>>n) + { + if(n == 0) break; + else cout< +#include +#include +using namespace std; +int main() +{ + char a[19][10]={"pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac", "ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu","uayet"}; + char b[20][10]={"imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat", "muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau"}; + char c[10]; + int t,d,y,r,w; + cin>>t; + cout< +#include +using std::cin; +using std::cout; +using std::endl; +int main() { + while(true) { + int N; + cin>>N; + if(!N) + break; + double mint=1e36; + double v,t0; + while(N--) { + cin>>v>>t0; + if(t0>=0&&ceil(t0+4500*3.6/v)(mint)< +#include +int n,m,c,d[105][5005]; +int dfs(int n,int m) +{ + if(m<0||m>n*(n-1)>>1)return 0; + if(m==0)return 1; + if(d[n][m]!=-1)return d[n][m]; + for(int i=1;i<=n;i++) + { + d[n][m]=dfs(n-i,m-i*(n-i)); + if(d[n][m])return 1; + } + return 0; +} +int main() +{ + memset(d,-1,sizeof(d)); + while(scanf("%d%d",&n,&m),n+m) + { + printf("Case %d: %d lines ",++c,n); + if(dfs(n,m)) + printf("with exactly %d crossings can cut the plane into %d pieces at most.\n",m,n+m+1); + else + printf("cannot make exactly %d crossings.\n",m); + } +} diff --git a/HDOJ/1449_autoAC.cpp b/HDOJ/1449_autoAC.cpp new file mode 100644 index 0000000..312b7cf --- /dev/null +++ b/HDOJ/1449_autoAC.cpp @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include +#include +#define INF 0x3f3f3f3f +#define MAXN 1000005 +using namespace std; +int N, dp[MAXN]; +struct Node { + int x, y, ac; +}e[5005]; +int DP() { + int ret = INF; + memset(dp, 0x3f, sizeof (dp)); + dp[e[1].x] = 0; + for (int i = 2; i <= N; ++i) { + int a = e[i].ac, b = e[i].x; + for (int j = a; j < b; ++j) { + int p = 2*e[i].x-j; + if (p < e[N].x) { + dp[p] = min(dp[p], dp[j]+1); + } else { + ret = min(ret, dp[j]+1); + } + } + } + return ret == INF ? -1 : ret; +} +int main() { + int T; + scanf("%d", &T); + while (T--) { + scanf("%d", &N); + for (int i = 1; i <= N; ++i) { + scanf("%d %d", &e[i].x, &e[i].y); + e[i].ac = max(0, (int)ceil(e[i].x-sqrt(2.*e[i].y*e[1].y-1.*e[1].y*e[1].y))); + } + printf("%d\n", DP()); + } + return 0; +} diff --git a/HDOJ/1450_autoAC.cpp b/HDOJ/1450_autoAC.cpp new file mode 100644 index 0000000..010ecd6 --- /dev/null +++ b/HDOJ/1450_autoAC.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#define Max(a,b) ((a)>(b)?(a):(b)) +#define Min(a,b) ((a)<(b)?(a):(b)) +using namespace std; +const int N=105; +const int inf=(1<<30); +int n,m; +double a[N]; +bool mat[N][N]; +bool vis[N]; +int indgree[N]; +void floyd() +{ + for(int k=1;k<=n;k++) + for(int i=1;i<=n;i++) + for(int j=1;j<=n;j++) + if(i!=j&&mat[i][k]&&mat[k][j]) + { + mat[i][j]=true; + } +} +void solve() +{ + floyd(); + memset(vis,0,sizeof(vis)); + for(int i=1;i<=n;i++) + { + if(vis[i]) + continue; + double sum1=0,sum2=0; + vis[i]=true; + sum1+=a[i]; + sum2+=indgree[i]; + for(int j=1;j<=n;j++) + { + if(!vis[j]&&mat[i][j]) + { + sum1+=a[j]; + sum2+=indgree[j]; + //vis[i]=true; + } + } + if(sum2==0) + { + printf("%.3lf\n",sum1); + continue; + } + double k=(sum1)/sum2; + printf("%.3lf\n",k*indgree[i]); + for(int j=1;j<=n;j++) + { + if(!vis[j]&&mat[i][j]) + { + printf("%.3lf\n",k*indgree[j]); + vis[j]=true; + } + } + } + printf("\n"); +} +int main() +{ + int T; + scanf("%d",&T); + while(T--) + { + memset(mat,0,sizeof(mat)); + memset(indgree,0,sizeof(indgree)); + scanf("%d%d",&n,&m); + for(int i=1;i<=n;i++) + scanf("%lf",a+i); + int u,v; + for(int i=1;i<=m;i++) + { + scanf("%d%d",&u,&v); + if(!mat[u][v]) + { + mat[u][v]=mat[v][u]=true; + indgree[u]++; + indgree[v]++; + } + } + solve(); + } + return 0; +} diff --git a/HDOJ/1451_autoAC.cpp b/HDOJ/1451_autoAC.cpp new file mode 100644 index 0000000..7f27728 --- /dev/null +++ b/HDOJ/1451_autoAC.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +using namespace std; +const double PI=acos(-1.0); +int main() +{ + double a,b,c,L; + int cout=1; + while(cin>>a>>b>>c>>L) + { + if(a==0&&b==0&&c==0&&L==0) + break; + double p=(a+b+c)/2.0; + double S=sqrt(p*(p-a)*(p-b)*(p-c)); + double R=S/p; + if(L>=a+b+c) + printf("Case %d: %.2lf\n",cout++,S); + else if(L<=PI*R*2) + printf("Case %d: %.2lf\n",cout++,L*L/(4*PI)); + else + { + double r=R*(2*p-L)/(2*p-2*PI*R); + double s=(r/R)*(r/R)*S; + printf("Case %d: %.2lf\n",cout++,S-s+PI*r*r); + } + } + return 0; +} diff --git a/HDOJ/1452_autoAC.cpp b/HDOJ/1452_autoAC.cpp new file mode 100644 index 0000000..c8ebfc2 --- /dev/null +++ b/HDOJ/1452_autoAC.cpp @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int n=29; +long long pow_mod(long long a,long long i,long long n) +{ if(i==0) return 1; + int temp=pow_mod(a,i>>1,n); + temp=temp*temp%n; + if(i&1) temp=(long long)temp*a%n; + return temp; +} +int main() +{ int X,S; + while(cin>>X) + { if(X==0) break; + S=((pow_mod(2,2*X+1,n)+28)*(pow_mod(3,X+1,n)+28)*(pow_mod(167,X+1,n)+28)*9)%n; + cout< +#include +#include +using namespace std; +const int A=210; +int main() +{ + int m,n,i,j,ii,jj,c; + cin>>m>>n; + getchar(); + char p[A][A]; + int pp[A]; + for(i=0;i=1;k--) + { + int count=0; + for(j=0;j +#include +#include +using namespace std; +const double precision=1e-3; +const double inf=99999.0; +typedef class Node +{ +public: + double x; + double y; +}point; +int max(int a,int b) +{ + return a>b?a:b; +} +int dblcmp(double p) +{ + if(fabs(p)0?1:-1; +} +double det(double x1,double y1,double x2,double y2) +{ + return x1*y2-x2*y1; +} +double cross(point A,point B,point P) +{ + return det(B.x-A.x , B.y-A.y , P.x-A.x , P.y-A.y); +} +bool check(point A,point B,point C,point D) +{ + return (dblcmp(cross(A,B,C)) * dblcmp(cross(A,B,D)) <= 0); +} +double intersection(point A,point B,point C,point D) +{ + double area1=cross(A,B,C); + double area2=cross(A,B,D); + int c=dblcmp(area1); + int d=dblcmp(area2); + if(c*d<0) + return (area2*C.x - area1*D.x)/(area2-area1); + if(c*d==0) + if(c==0) + return C.x; + else + return D.x; + return -inf; +} +int main(int i,int j,int k) +{ + int n; + while(cin>>n) + { + if(!n) + break; + point* up=new point[n+1]; + point* down=new point[n+1]; + double max_x=-inf; + for(i=1;i<=n;i++) + { + cin>>up[i].x>>up[i].y; + down[i].x=up[i].x; + down[i].y=up[i].y-1; + } + bool flag=false; + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + if(i!=j) + { + for(k=1;k<=n;k++) + if(!check(up[i],down[j],up[k],down[k])) + break; + if(k>n) + { + flag=true; + break; + } + else if(k>max(i,j)) { + double temp=intersection(up[i],down[j],up[k],up[k-1]); + if(max_x < temp) + max_x=temp; + temp=intersection(up[i],down[j],down[k],down[k-1]); + if(max_x < temp) + max_x=temp; + } + } + if(flag) + break; + } + if(flag) + cout<<"Through all the pipe."< +#include +#include +#include +#include +#include +using namespace std; +int n,a[65],vis[65],sum; +bool cmp(int a,int b) +{ + return a>b; +} +int dfs(int now,int len,int pos,int q,int num) +{ + int i,j; + int cut; + cut=0; + if(len==0)cut=1; + if(num==0) + return 1; + if(q%2!=(len+num*now)%2) + return 0; + for(i=pos;inow) + continue; + if(vis[i])continue; + vis[i]=1; + if(a[i]+len==now) + { + if(a[i]%2==1) + { + if(dfs(now,0,0,q-1,num-1)) + return 1; + } + else + { + if(dfs(now,0,0,q,num-1)) + return 1; + } + vis[i]=0; + return 0; + } + else + { + if(a[i]%2==1) + { + if(dfs(now,len+a[i],i+1,q-1,num)) + return 1; + } + else + { + if(dfs(now,len+a[i],i+1,q,num)) + return 1; + } + vis[i]=0; + if(cut) + return 0; + while(i +#include +#include +#include +using namespace std; +struct Order +{ + int s; + int e; + int p; +}ord[23]; +int n, NumB, NumOrd; +int MaxEarn, CurEarn, off[8]; +int cmp (const void *aa, const void *bb) +{ + struct Order *a=(Order*) aa; + struct Order *b=(Order*) bb; + if(a -> s != b -> s) return a -> s - b -> s; + else return a -> e - a -> e; +} +void DFS (int num,int tolp) +{ + if (num == NumOrd) + { + if (MaxEarn < CurEarn) MaxEarn = CurEarn; + return ; + } + else + { + if (num > 0) + for (int i = ord[num - 1].s + 1; i <= ord[num].s; i++) + { + tolp -= off[i]; + } + tolp += ord[num].p; + if (tolp <= n) + { + CurEarn += (ord[num].e - ord[num].s) * ord[num].p; + off[ord[num].e] += ord[num].p; + DFS(num + 1, tolp); + CurEarn -= (ord[num].e - ord[num].s) * ord[num].p; + off[ord[num].e] -= ord[num].p; + } + tolp -= ord[num].p; + DFS (num + 1, tolp); + } + return ; +} +int main() +{ + while (scanf("%d %d %d", &n, &NumB, &NumOrd) && (n || NumB || NumOrd)) + { + memset(off, 0, sizeof(off)); + MaxEarn = 0; CurEarn = 0; + for (int i = 0; i < NumOrd; i++) + { + scanf("%d %d %d", &ord[i].s, &ord[i].e, &ord[i].p); + } + qsort (ord, NumOrd, sizeof(ord[0]), cmp); + DFS(0,0); + printf("%d\n", MaxEarn); + } + return 0; +} diff --git a/HDOJ/1461_autoAC.cpp b/HDOJ/1461_autoAC.cpp new file mode 100644 index 0000000..ae61a55 --- /dev/null +++ b/HDOJ/1461_autoAC.cpp @@ -0,0 +1,142 @@ +#include +#include +#include +#include +#define N 11 +using namespace std; +struct Node +{ + char map[10][N]; + int flag; +}; +char endstate[10][N]; +Node t1,t2,t3; +int n,i,j,k; +bool isEnd(Node tt) +{ + for(i=0;i qu; + if(isEnd(t1)) + { + printf("Preserved\n"); + return; + } + t1.flag=0; + qu.push(t1); + while(!qu.empty()) + { + t2=qu.front(); + qu.pop(); + if(t2.flag==0) + { + t1.flag=1; + rt90(); + if(isEnd(t1)) + { + printf("Rotated through 90 degrees\n"); + return; + } + rt180(); + if(isEnd(t1)) + { + printf("Rotated through 180 degrees\n"); + return; + } + rt270(); + if(isEnd(t1)) + { + printf("Rotated through 270 degrees\n"); + return; + } + reflect(); + if(isEnd(t1)) + { + printf("Reflected\n"); + return; + } + qu.push(t1); + } + else if(t2.flag==1) + { + rt90(); + if(isEnd(t1)) + { + printf("Reflected and rotated through 90 degrees\n"); + return; + } + rt180(); + if(isEnd(t1)) + { + printf("Reflected and rotated through 180 degrees\n"); + return; + } + rt270(); + if(isEnd(t1)) + { + printf("Reflected and rotated through 270 degrees\n"); + return; + } + printf("Improper\n"); + } + } +} +int main() +{ + while(scanf("%d",&n)&&n!=0) + { + for(i=0;i +using namespace std; +int main() +{ + char c1[10],c2[10],c3[10],c4[10]; + int xy=0; + int sum; + while(cin>>c1) + { + int i,j,r1,r2,cc1,cc2,k,v,m; + if(strcmp(c1,"#")==0) + break; + if(xy) + cout<>c2>>c3>>c4; + int len1=strlen(c1); + int len2=strlen(c2); + int len3=strlen(c3); + int len4=strlen(c4); + for(i=0;ir2) + { + for(k=0;k +int main() +{ + __int64 a[21]; + int i,n; + a[1]=0; + a[2]=1; + while(scanf("%d",&n)!=EOF) + { + for(i=3;i +int main(){ + int dp[21][191]; + int i,j,k; + for(i=0;i<21;i++) + for(j=0;j<191;j++) + dp[i][j]=0; + for(i=0;i<=20;i++){ + dp[i][0]=1; + for(j=0;j<=i;j++){ + for(k=0;k<=(j-1)*j/2;k++){ + dp[i][(i-j)*j+dp[j][k]*k]=1; + } + } + } + while(scanf("%d",&k)!=EOF){ + printf("0"); + for(i=1;i<=(k-1)*k/2;i++) + if(dp[k][i]) + printf(" %d",i); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1467_autoAC.cpp b/HDOJ/1467_autoAC.cpp new file mode 100644 index 0000000..a26f459 --- /dev/null +++ b/HDOJ/1467_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +using namespace std; +const int maxn=101; +char m[maxn][2*maxn]; +int n; +bool judge(int h,int left,int right) +{ + if(right>2*n-h||left=1;--i) + if(judge(i,l-(h-i),l+(h-i))) + result+=2*(h-i)+1; + else + break; + return result; +} +int down(int h,int l) +{ + int result=0; + for(int i=h;i<=n;++i) + if(judge(i,l-(i-h),l+(i-h))) + result+=2*(i-h)+1; + else + break; + return result; +} +int dfs() +{ + int maxarea=0; + for(int i=1;i<=n;++i) + for(int j=i;j<=2*n-i;++j) + { + if(m[i][j]=='#') + continue; + if((i+j)%2==1) + maxarea=max(maxarea,down(i,j)); + else + maxarea=max(maxarea,up(i,j)); + } + return maxarea; +} +int main() +{ + static int num=0; + while(cin>>n&&n) + { + getchar(); + for(int i=1;i<=n;++i) + gets(m[i]+1); + cout<<"Triangle #"<<++num< +#include +#include +#include +#include +#include +#include +using namespace std; +#define print(x) cout<>x +#define SIZE 128 +#define pb push_back +const double eps=1e-10; +inline int zero(double x) +{ + if(x<-eps) return -1; + else if(fabs(x)=min(l2.p1.x,l2.p2.x))&& + (max(l1.p1.y,l1.p2.y)>=min(l2.p1.y,l2.p2.y))&& + (max(l2.p1.x,l2.p2.x)>=min(l1.p1.x,l1.p2.x))&& + (max(l2.p1.y,l2.p2.y)>=min(l1.p1.y,l1.p2.y))&&//蹇ュ楠 + fabs((xmult(l1.p1,l2.p1,l2.p2)*xmult(l1.p2,l2.p1,l2.p2))<=eps)&& + fabs((xmult(l2.p1,l1.p1,l1.p2)*xmult(l2.p2,l1.p1,l1.p2))<=eps))//璺ㄧ瀹楠 + { + lineIntersect(makeLine(l1),makeLine(l2),p); + return true; + } + else return false; +} +struct polygen +{ + point pvec[SIZE]; + point core[SIZE]; + int sz; + polygen(){sz=0;} + inline void push_point(const point& p) + { + pvec[sz++]=p; + } + void Cut(segment s) + { + int q=0; + for(int i=0;i=0) + { + core[q++]=pvec[i]; + } + else + { + point cp; + if(xmult(pvec[i],s.p2,s.p1) * xmult(pvec[(i+1)%sz],s.p2,s.p1)<0) + { + point cp; + line l1=makeLine(s); + line l2=makeLine(pvec[i],pvec[(i+1)%sz]); + lineIntersect(l1,l2,cp); + core[q++]=cp; + } + } + } + for(int i=0;i0) print("Surveillance is possible."); + else print("Surveillance is impossible."); + puts(""); + } + return 0; +} diff --git a/HDOJ/1470_autoAC.cpp b/HDOJ/1470_autoAC.cpp new file mode 100644 index 0000000..3d23701 --- /dev/null +++ b/HDOJ/1470_autoAC.cpp @@ -0,0 +1,216 @@ +#include +#include +using namespace std; +#define N 55 +#define M 10 +int people[M]; +int brith[M]; +int n; +int ok; +int FP; +int now[M]; +int yes[M]; +struct say{ + char talk; + char name; + int bo; + int sex; +}; +void thesome() +{ + for(int i = 0; i < 6; i++) + if(now[i] != people[i]) + yes[i] = 1; +} +int ture_say(say f) +{ + if(f.sex != -1) + { + if(f.name == 'T') + { + if(f.bo && f.sex - 4 == people[0]) + return 1; + else if(!f.bo && f.sex - 4 != people[0]) + return 1; + else + return 0; + } + else + { + int id = f.name - 'A' + 1; + if(f.bo && f.sex == people[id]) + return 1; + else if(!f.bo && f.sex != people[id]) + return 1; + else + return 0; + } + } + else + { + int id = f.name - 'A' + 1; + if(people[id] == 3 && !f.bo) + return 1; + else if (people[id] == 1 && f.bo) + return 1; + else if(people[id] == 2) + { + if(people[0] && !f.bo) + return 1; + else if(!people[0] && f.bo) + return 1; + else + return 0; + } + else + return 0; + } +} +int write(char str[]) +{ + if(strncmp(str, "divine.", 7) == 0) + return 3; + else if(strncmp(str, "human.", 6) == 0) + return 2; + else if(strncmp(str, "evil.", 5) == 0) + return 1; + else if(strncmp(str, "day.", 4) == 0) + return 5; + else if( strncmp(str, "night.", 6) == 0) + return 4; + else if( strncmp(str, "lying.", 6) ==0) + return -1; +} +void read(say tem[]) +{ + char str[M]; + int id; + for(int i = 0; i < n; i++) + { + cin >> str; + tem[i].talk = str[0]; + id = str[0] - 'A' + 1; + brith[id] = 1; + cin >> str; + if(strcmp(str, "It") == 0) + tem[i].name = 'T'; + else if(str[0] == 'I') + tem[i].name = tem[i].talk; + else + { + tem[i].name = str[0]; + id = str[0] - 'A' + 1; + brith[id] = 1; + } + cin >> str; + cin >> str; + if(strcmp(str, "not")) + { + tem[i].bo = 1; + tem[i].sex = write(str); + } + else + { + tem[i].bo = 0; + cin >> str; + tem[i].sex = write(str); + } + } +} +int judge(say tem[]) +{ + for(int i = 0; i < n; i++) + { + int id = tem[i].talk - 'A' + 1; + if(people[id] == 3) + { + if(ture_say(tem[i])) + continue; + else + return 0; + } + else if(people[id] == 2) + { + int f = ture_say(tem[i]); + if( (people[0] && f) || (!people[0] && !f) ) + continue; + else + return 0; + } + else if(people[id] == 1) + { + if(!ture_say(tem[i])) + continue; + else + return 0; + } + } + return 1; +} +void build(int k, say tem[]) +{ + if(k < 6) + { + if(brith[k]) + { + for(people[k] = 1; people[k] < 4; people[k]++) + build(k + 1, tem); + } + else + build(k + 1, tem); + } + else if(judge(tem)) + { + if(ok >= 1) + thesome(); + else + for(int i = 0; i < 6; i++) + now[i] = people[i]; + ok++; + } +} +int main() +{ + int t = 1; + while(cin >> n, n) + { + memset(people, 0, sizeof(people)); + memset(brith, 0, sizeof(brith)); + ok = 0; + say tem[N]; + memset(yes, 0,sizeof(yes)); + read(tem); + cout << "Conversation #" << t++ << endl; + for(people[0] = 0; people[0] < 2; people[0]++) + build(1, tem); + if(ok == 0) + cout << "This is impossible." << endl; + else + { + //* + int oi = 0; + for(int i = 1; i < 6; i++) + { + if(!yes[i] && now[i]) + { + oi++; + char c = 'A' + i - 1; + if(now[i] == 3) + cout << c << " is divine." << endl; + else if(now[i] == 2) + cout << c << " is human." << endl; + else if(now[i] == 1) + cout << c << " is evil." << endl; + } + } + if(oi == 0 && yes[0]) + cout << "No facts are deducible." << endl; + if(now[0] && !yes[0]) + cout << "It is day." << endl; + else if(!yes[0]) + cout << "It is night." << endl; + } + cout << endl; + } + return 0; +} diff --git a/HDOJ/1472_autoAC.cpp b/HDOJ/1472_autoAC.cpp new file mode 100644 index 0000000..a9f3098 --- /dev/null +++ b/HDOJ/1472_autoAC.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include +using namespace std; +const double t = sqrt(2.0); +int main() +{ + string s; + int icase = 1; + while(cin >> s) { + if(s == "END") { + break; + } + int num = 0; + double x = 0, y = 0; + for(int i = 0; i < (int)s.length()-1; ++i) { + if(s[i] >= '0' && s[i] <= '9') { + num = num*10+(s[i]-'0'); + } + else if(s[i] == ','){ + num = 0; + continue; + } + else if(s[i] == 'N' && s[i+1] == 'E') { + x+=num/t, y+=num/t, i++; + } + else if(s[i] == 'N' && s[i+1] == 'W') { + x-=num/t, y+=num/t, i++; + } + else if(s[i] == 'S' && s[i+1] == 'E') { + x+=num/t, y-=num/t, i++; + } + else if(s[i] == 'S' && s[i+1] == 'W') { + x-=num/t, y-=num/t, i++; + } + else if(s[i] == 'N') { + y+=num; + } + else if(s[i] == 'S') { + y-=num; + } + else if(s[i] == 'E') { + x+=num; + } + else if(s[i] == 'W') { + x-=num; + } + } + printf("Map #%d\n", icase++); + printf("The treasure is located at (%.3lf,%.3lf).\n", x, y); + printf("The distance to the treasure is %.3lf.\n\n", sqrt(x*x+y*y)); + } + return 0; +} diff --git a/HDOJ/1474_autoAC.cpp b/HDOJ/1474_autoAC.cpp new file mode 100644 index 0000000..7cf0fce --- /dev/null +++ b/HDOJ/1474_autoAC.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include +using namespace std; +#define maxn 15 +#define maxk 1005 +#define maxd 35 +#define inf 0x3f3f3f3f +int n, m; +int f[maxn][maxk]; +int flight_num[maxn][maxn]; +int flight[maxn][maxn][maxd]; +void input() +{ + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + if (i != j) + { + scanf("%d", &flight_num[i][j]); + for (int k = 0; k < flight_num[i][j]; k++) + scanf("%d", &flight[i][j][k]); + } +} +void cal(int day, int u, int v) +{ + if (f[u][day] == -1) + return; + if (flight_num[u][v] == 0) + return; + if (flight[u][v][day % flight_num[u][v]] != 0 + && (f[v][day + 1] == -1 || f[v][day + 1] > f[u][day] + flight[u][v][day % flight_num[u][v]])) + f[v][day + 1] = f[u][day] + flight[u][v][day % flight_num[u][v]]; +} +int work() +{ + memset(f, -1, sizeof(f)); + f[0][0] = 0; + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + for (int k = 0; k < n; k++) + if (j != k) + cal(i, j, k); + return f[n - 1][m]; +} +void output() +{ + for (int i = 0; i <= m; i++) + { + for (int j = 0; j < n; j++) + printf("%d ", f[j][i]); + puts(""); + } +} +int main() +{ + int t = 0; + while (scanf("%d%d", &n, &m), n | m) + { + input(); + int ans = work(); + printf("Scenario #%d\n", ++t); + if (ans == -1) + puts("No flight possible."); + else + printf("The best flight costs %d.\n", ans); + puts(""); + } + return 0; +} diff --git a/HDOJ/1476_autoAC.cpp b/HDOJ/1476_autoAC.cpp new file mode 100644 index 0000000..8eff1d0 --- /dev/null +++ b/HDOJ/1476_autoAC.cpp @@ -0,0 +1,51 @@ +#include +#include +using namespace std; +int C; +int DI(int t) +{ + if(t==0) return 0; + else if(t>=1&&t<=10) return -C; + else return (t-10)*(t-10); +} +int main() +{ + int n,L,count=0,i,j; + int t[1010],lecture[1010],DP[1010]; + while(scanf("%d",&n),n) + { + count++; + if(count>1) + printf("\n"); + scanf("%d %d",&L,&C); + for(i=1;i<=n;i++) + scanf("%d",&t[i]); + lecture[0]=DP[0]=0; + lecture[1]=1;DP[1]=DI(L-t[1]); + for(i=2;i<=n;i++) + { + lecture[i]=lecture[i-1]+1; + DP[i]=DP[i-1]+DI(L-t[i]); + int sum=t[i]; + for(j=i-1;j>0;j--) + { + sum+=t[j]; + if(sum<=L) + { + int a=DP[j-1]+DI(L-sum); + if(lecture[i]>lecture[j-1]+1) + { + lecture[i]=lecture[j-1]+1; + DP[i]=a; + } + else if(lecture[i]==lecture[j-1]+1) + DP[i]=DP[i]>a?a:DP[i]; + } + else + break; + } + } + printf("Case %d:\n\nMinimum number of lectures: %d\nTotal dissatisfaction index: %d\n",count,lecture[n],DP[n]); + } + return 0; +} diff --git a/HDOJ/1479_autoAC.cpp b/HDOJ/1479_autoAC.cpp new file mode 100644 index 0000000..5cda4e0 --- /dev/null +++ b/HDOJ/1479_autoAC.cpp @@ -0,0 +1,78 @@ +#include +#include +#include +using namespace std; +void R(char* n,char* t) +{ + int i,j; + int time[10]={0}; + for(i=0;n[i];i++) + time[ n[i]-'0' ]++; + for(i=0,j=0;i<10;i++) + { + if(time[i]) + { + if(time[i]<10) + { + t[j++]=time[i]+'0'; + t[j++]=i+'0'; + } + else + { + t[j++]=time[i]/10+'0'; + t[j++]=time[i]%10+'0'; + t[j++]=i+'0'; + } + } + } + t[j]='\0'; + return; +} +int main(int i,int j) +{ + char n[16][85]; + while(cin>>n[0] && n[0][0]!='-') + { + bool flag1=false; + int flag2=0; + int flag3=0; + for(i=1;i<=15;i++) + R(n[i-1],n[i]); + if(!strcmp(n[0],n[1])) + flag1=true; + if(!flag1) + { + for(j=1;j<15;j++) + if(!strcmp(n[j],n[j+1])) + { + flag2=j; + break; + } + if(!flag2) + { + for(j=1;j<=15;j++) + { + for(i=0;i<=j-2;i++) + { + if(!strcmp(n[j],n[i])) + { + flag3=j-i; + break; + } + } + if(flag3) + break; + } + } + } + if(flag1) + cout< +#include +#define N 30 +using namespace std; +long long d[N],d1[N],d2[N]; +int main() +{ + int i; + long long t; + d1[3]=32; + d2[3]=72; + d[3]=104; + int n; + n=25; + for(i=4;i<=n;i++) + { + d1[i]=d1[i-1]+2*d2[i-1]; + d2[i]=4*d[i-1]; + t=pow(2,i+1); + d1[i]=d1[i]+4*t-32; + d2[i]=d2[i]+9*t-72; + d[i]=d1[i]+d2[i]; + } + for(i=3;i<=n;i++) + { + cout<<"N="< +#include +int main() +{ + char str[9][20]; + int a[12]; + int T; + scanf("%d",&T); + while(T--) + { + for(int i=0;i<9;i++)scanf("%s",&str[i]); + int res=-1; + while(res<12) + { + int t; + if(res==-1){res=0;t=1;} + else if(a[res]==1) t=-1; + else {res++;t=1;} + for(int i=0;i<12;i++) a[i]=0; + a[res]=t; + int L=0,R=0; + int len=strlen(str[0]); + for(int i=0;i=R)continue; + L=0,R=0; + len=strlen(str[3]); + for(int i=0;i=R)continue; + L=0,R=0; + len=strlen(str[6]); + for(int i=0;i=R)continue; + break; + } + printf("%c is the counterfeit coin and it is ",res+'A'); + if(a[res]==-1) printf("light.\n"); + else printf("heavy.\n"); + } + return 0; +} diff --git a/HDOJ/1483_autoAC.cpp b/HDOJ/1483_autoAC.cpp new file mode 100644 index 0000000..b3b4cb6 --- /dev/null +++ b/HDOJ/1483_autoAC.cpp @@ -0,0 +1,111 @@ +#include +#include +#include +using namespace std; +const int MAX = 10010; +struct node +{ + char word[110]; + int lenword; +}dic[MAX]; +char qu[1010]; +int Judge(char *a, char *b, int len) +{ + int i= 0, count = 0, j = 0; + while (i < len && j < len - 1) + { + if (a[i] == b[j]) + { + i ++; + j ++; + } + else + { + count ++; + i ++; + } + } + if (j == len - 1 && count == 0) + { + return 1; + } + if (count == 1) + { + return 1; + } + return 0; +} +int main() +{ + int n, i, m, j, lenqu, flag, k, count; + scanf("%d", &n); + for (i = 0; i < n; ++i) + { + scanf("%s", dic[i].word); + dic[i].lenword = strlen(dic[i].word); + } + scanf("%d", &m); + for (i = 0; i < m; ++i) + { + flag = 0; + scanf("%s", qu); + lenqu = strlen(qu); + for (j = 0; j < n; ++j) + { + if (strcmp (dic[j].word, qu) == 0) + { + flag = 1; + printf("%s is correct\n", qu); + break; + } + } + if (!flag) + { + for (j = 0; j < n; ++j) + { + if (dic[j].lenword == lenqu) + { + int com[110] = {0}; + count = 0; + for (k = 0; k < lenqu; ++k) + { + if (dic[j].word[k] != qu[k]) + { + count ++; + com[count] = k; + } + } + if (count == 1) + { + flag = 1; + } + if (count == 2) + { + if (dic[j].word[com[1]] == qu[com[2]] && dic[j].word[com[2]] == qu[com[1]] && com[2] - com[1] == 1) + { + flag = 1; + } + } + } + else if (dic[j].lenword - 1 == lenqu) + { + flag = Judge(dic[j].word, qu, dic[j].lenword); + } + else if (dic[j].lenword + 1 == lenqu) + { + flag = Judge(qu, dic[j].word, lenqu); + } + if (flag) + { + printf("%s is a misspelling of %s\n", qu, dic[j].word); + break; + } + } + } + if (!flag) + { + printf("%s is unknown\n", qu); + } + } + return 0; +} diff --git a/HDOJ/1484_autoAC.cpp b/HDOJ/1484_autoAC.cpp new file mode 100644 index 0000000..288063f --- /dev/null +++ b/HDOJ/1484_autoAC.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include +using namespace std; +const int MAX = 9,limit = 6,INF = 1000; +const int dirx[4]={0,-1,0,1},diry[4]={1,0,-1,0}; +int map[MAX][MAX][4]; +int dist[MAX][MAX],pre[MAX][MAX][2]; +int sx,sy,ex,ey,pax,pay,pbx,pby; +stack st; +void init(){ + int i,j; + for(i=0;ilimit || ty>limit)continue; + if(cnt+1>dist[tx][ty])continue; + dist[tx][ty] = cnt; + pre[tx][ty][0] = x; + pre[tx][ty][1] = y; + dfs(tx,ty,cnt+1); + } +} +void Path(){ + int px,py,x,y; + x = ex,y = ey; + px = pre[x][y][0]; + py = pre[x][y][1]; + while(1){ + if(x==px){ + if(py +#include +char s[1000010]; +int main() +{ + int n; + while (scanf("%d",&n)&&n) + { + getchar(); + gets(s); + int len=strlen(s); + int right=0; + int circle=0; + for (int i=0;i'9')) + { + int num=0; + char ope=s[i]; + i++; + bool have=false; + for (;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define inf 0x3f3f3f3f +#define maxn 1005 +using namespace std; +struct node +{ + int mm,dd,hh,MM; +} ttt[maxn]; +char str[1005]; +int f[maxn][maxn],t[maxn],n; +bool flag[maxn]; +int cmp(node t1,node t2) //t1t2 1; +{ + if(t1.mm!=t2.mm) + { + if(t1.mm=1; i--) + { + scanf("%d:%d:%d:%d %s %c",&ttt[i].mm,&ttt[i].dd,&ttt[i].hh,&ttt[i].MM,str,&op); + if(op=='+') flag[i]=1; + } + t[1]=0; + for(int i=2; i<=n; i++) + { + t[i]=t[i-1]; + if(cmp(ttt[i],ttt[i-1])>=0 ) t[i]++; + } + f[1][1]=1; + if(flag[1]) f[1][0]=inf; + else f[1][0]=0; + for(int i=2; i<=n; i++) f[1][i]=inf; + for(int i=2; i<=n; i++) + { + for(int j=1; j<=n; j++) f[i][j]=inf; + if(!flag[i]) f[i][0]=f[i-1][0]; + else f[i][0]=inf; + if(flag[i]) + { + if(t[i]==0) f[i][i]=min(f[i][i],f[i-1][0]+1); + for(int j=1; j=0) tt--; + if(tt==t[j]) //zhengque queding nianfen + { + f[i][i]=min(f[i-1][j]+1,f[i][i]); + } + } + } + else + { + for(int j=1; j<=n; j++) f[i][j]=min(f[i][j],f[i-1][j]); + if(t[i]==0) f[i][i]=min(f[i][i],f[i-1][0]+1); + for(int j=1; j=0) tt--; + if(tt==t[j]) //zhengque queding nianfen + { + f[i][i]=min(f[i-1][j]+1,f[i][i]); + } + } + } + } + int res; + res=inf; + for(int i=1; i<=n; i++) + res=min(res,f[n][i]); + res=min(res,n); + printf("%d\n",res); + } + return 0; +} diff --git a/HDOJ/1488_autoAC.cpp b/HDOJ/1488_autoAC.cpp new file mode 100644 index 0000000..e644a3a --- /dev/null +++ b/HDOJ/1488_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +using namespace std; +typedef struct +{ + int v,step; +} node; +long long MOD1=10007; +long long MOD2=10000013; +vector use[10010]; +char s[10010]; +int main() +{ + long long n; + while (scanf("%lld",&n)&&n) + { + long long a,b; + scanf("%lld%lld",&a,&b); + bool stop=0; + for (int i=0;i<10010;i++) + use[i].clear(); + node temp; + temp.v=0; + temp.step=1; + use[0].push_back(temp); + long long pre=0; + int step=1; + while (!stop) + { + step++; + long long now=(((a*pre)%n*pre)%n+b)%n; + long long x1=now%MOD1; + long long x2=now%MOD2; + int len=use[x1].size(); + bool find=false; + int stepp=0; + for (int i=0;i +#include +#include +#include +#include +#include +#include +#include +using namespace std; +long long s[100005]; +int main() +{ + long long n,i,ans; + while(cin>>n) + { + if(n==0) + { + break; + } + for(i=0;i>s[i]; + } + ans=0; + for(i=0;i0) + { + ans+=s[i]; + s[i+1]+=s[i]; + } + else + { + ans-=s[i]; + s[i+1]+=s[i]; + } + } + cout< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef unsigned long long ULL; +#define MAX(a,b) ((a) > (b) ? (a) : (b)) +#define MIN(a,b) ((a) < (b) ? (a) : (b)) +#define MEM(a,b) memset((a),(b),sizeof(a)) +const LL INF = 1000000007; +const int N = 1e3+10; +const double eps = 1e-12; +int a[N][N]; +int main() +{ + int n; + while (scanf("%d", &n) != EOF) + { + if (n == 0) break; + int flag = 1; + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + scanf("%d", &a[i][j]); + } + } + for (int i = 0; i < n; i++) + { + for (int j = i + 1; j < n; j++) + { + if (a[i][i] + a[j][j] != a[i][j] + a[j][i]) + { + flag = 0; + break; + } + } + if (flag == 0) break; + } + if (flag) puts("homogeneous"); + else puts("not homogeneous"); + } + return 0; +} diff --git a/HDOJ/1491_autoAC.cpp b/HDOJ/1491_autoAC.cpp new file mode 100644 index 0000000..4e40f3c --- /dev/null +++ b/HDOJ/1491_autoAC.cpp @@ -0,0 +1,60 @@ +#include +int main () +{ + int n,month,day; + scanf ("%d",&n); + while (n--) + { + scanf ("%d%d",&month,&day); + switch(month) + { + case 10 : + if (day<21) + { + printf ("%d\n",21-day); + break; + } + else if(day==21) + { + printf ("It's today!!\n"); + break; + } + else + { + printf("What a pity, it has passed!\n"); + break; + } + case 9 : + printf ("%d\n",30+21-day); + break; + case 8 : + printf ("%d\n",31+30+21-day); + break; + case 7: + printf ("%d\n",31+31+30+21-day); + break; + case 6 : + printf ("%d\n",30+31+31+30+21-day); + break; + case 5: + printf ("%d\n",31+30+31+31+30+21-day); + break; + case 4: + printf ("%d\n",30+31+30+31+31+30+21-day); + break; + case 3: + printf ("%d\n",31+30+31+30+31+31+30+21-day); + break; + case 2: + printf ("%d\n",28+31+30+31+30+31+31+30+21-day); + break; + case 1: + printf ("%d\n",31+28+31+30+31+30+31+31+30+21-day); + break; + default: + printf ("What a pity, it has passed!\n"); + break; + } + } + return 0; +} diff --git a/HDOJ/1492_autoAC.cpp b/HDOJ/1492_autoAC.cpp new file mode 100644 index 0000000..87f188b --- /dev/null +++ b/HDOJ/1492_autoAC.cpp @@ -0,0 +1,20 @@ +#include +int main() +{ + __int64 n; + __int64 a[]={2,3,5,7}; + while(scanf("%I64d",&n),n) + { + __int64 b[4]={1,1,1,1}; + for(int i=0;i<4;i++) + { + while(n%a[i]==0) + { + b[i]++; + n=n/a[i]; + } + } + printf("%I64d\n",b[0]*b[1]*b[2]*b[3]); + } + return 0; +} diff --git a/HDOJ/1493_autoAC.cpp b/HDOJ/1493_autoAC.cpp new file mode 100644 index 0000000..45d5114 --- /dev/null +++ b/HDOJ/1493_autoAC.cpp @@ -0,0 +1,66 @@ +#include +#include +double p[7],f[11][61]; +void dp(){ + int i,j,k; + double ans; + memset(f,0,sizeof(f)); + f[0][0]=1.0; + for (k=1;k<=10;k++) + for (j=60;j>=k;j--) + for (i=1;i<=6;i++) + if (j>=i) + f[k][j]+=f[k-1][j-i]*p[i]; + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][5]; + printf("5: %.1lf%%\n",ans*100); + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][12]; + printf("12: %.1lf%%\n",ans*100); + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][22]; + printf("22: %.1lf%%\n",ans*100); + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][29]; + printf("29: %.1lf%%\n",ans*100); + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][33]; + printf("33: %.1lf%%\n",ans*100); + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][38]; + printf("38: %.1lf%%\n",ans*100); + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][42]; + printf("42: %.1lf%%\n",ans*100); + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][46]; + printf("46: %.1lf%%\n",ans*100); + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][50]; + printf("50: %.1lf%%\n",ans*100); + ans=0; + for (i=1;i<=10;i++) + ans+=f[i][55]; + printf("55: %.1lf%%\n",ans*100); +} +int main(){ + int t; + scanf("%d",&t); + while (t--){ + for (int i=1;i<=6;i++) + scanf("%lf",&p[i]); + dp(); + if (t) + putchar('\n'); + } + return 0; +} diff --git a/HDOJ/1494_autoAC.cpp b/HDOJ/1494_autoAC.cpp new file mode 100644 index 0000000..0a42157 --- /dev/null +++ b/HDOJ/1494_autoAC.cpp @@ -0,0 +1,61 @@ +#include +#include +#include +using namespace std; +int dp[11000][16],a[110],b[110]; +inline void fun(int &x,int y) +{ + if(x == 0)x=y; + else x=min(x,y); +} +int main() +{ + int len,n,i,j,k,ans; + while(~scanf("%d %d",&len,&n)) + { + for(i=1;i<=len;i++) + { + scanf("%d",&a[i]); + } + for(i=1;i<=len;i++) + { + scanf("%d",&b[i]); + } + memset(dp,0,sizeof(dp)); + dp[1][1]=a[1]; + for(i=0;i=5 && k<14) + { + fun(dp[i*len+j][k+1],dp[i*len+j-1][k]+a[j]); + fun(dp[i*len+j][k-5],dp[i*len+j-1][k]+b[j]); + } + else if(k == 14) + { + fun(dp[i*len+j][10],dp[i*len+j-1][k]+a[j]); + fun(dp[i*len+j][k-5],dp[i*len+j-1][k]+b[j]); + } + else + { + fun(dp[i*len+j][k+1],dp[i*len+j-1][k]+a[j]); + } + } + } + } + } + ans=99999999; + for(i=0;i<15;i++) + { + if(dp[n*len][i] && dp[n*len][i] +#include +#include +using namespace std; +int mark[105][105][105]; +int flag; +int a,b,c; +int maxx,minn; +struct dian +{ + int map[3]; + int step; +}st; +void bfs(dian st) +{ + queue p; + mark[st.map[0]][st.map[1]][st.map[2]]=1; + p.push(st); + dian v,vn; + while(!p.empty()) + { + vn=p.front(); + p.pop(); + if(vn.map[0]==a/2&&vn.map[1]==a/2) + { + flag=1; + printf("%d\n",vn.step); + return; + } + for(int i=1;i<=10;i++) + { + v.map[0]=vn.map[0]; + v.map[1]=vn.map[1]; + v.map[2]=vn.map[2]; + v.step=vn.step+1; + if(i==1) {v.map[0]-=(maxx-v.map[1]);v.map[1]=maxx;} + else if(i==2){v.map[0]=0;v.map[1]+=vn.map[0];} + else if(i==3){v.map[0]-=(minn-v.map[2]);v.map[2]=minn;} + else if(i==4){v.map[0]=0;v.map[1]+=vn.map[0];} + else if(i==5){v.map[1]=0;v.map[0]+=vn.map[1];} + else if(i==6){v.map[1]=0;v.map[2]+=vn.map[1];} + else if(i==7){v.map[1]-=(minn-v.map[2]);v.map[2]=minn;} + else if(i==8){v.map[2]=0;v.map[1]+=vn.map[2];} + else if(i==9){v.map[2]=0;v.map[0]+=vn.map[2];} + else if(i==10){v.map[2]-=(maxx-v.map[1]);v.map[1]=maxx;} + if(v.map[0]>a||v.map[0]<0||v.map[1]>maxx||v.map[1]<0||v.map[2]>minn||v.map[2]<0) continue; + if(mark[v.map[0]][v.map[1]][v.map[2]]) continue; + mark[v.map[0]][v.map[1]][v.map[2]]=1; + p.push(v); + } + } +} +int main() +{ + while(scanf("%d%d%d",&a,&b,&c)!=EOF) + { + if(a==0&&b==0&&c==0) break; + flag=0; + memset(mark,0,sizeof(mark)); + if(b==c) {printf("1\n"); continue;} + if(a%2==1) {printf("NO\n"); continue;} + if(b>c) {maxx=b;minn=c;} + else {maxx=c;minn=b;} + st.map[0]=a; + st.map[1]=0; + st.map[2]=0; + st.step=0; + bfs(st); + if(!flag) printf("NO\n"); + } +} diff --git a/HDOJ/1496_autoAC.cpp b/HDOJ/1496_autoAC.cpp new file mode 100644 index 0000000..30e9406 --- /dev/null +++ b/HDOJ/1496_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +using namespace std; +int f1[1000001]; +int f2[1000001]; +int A,B,C,D; +int i,j,ans,s; +int main() +{ + while(~scanf("%d%d%d%d",&A,&B,&C,&D)) + { + ans = 0; + if(A>0 && B>0 && C>0 && D>0 || A<0 && B<0 && C<0 && D < 0) + { + printf("0\n"); + continue; + } + memset(f1,0,sizeof(f1)); + memset(f2,0,sizeof(f2)); + for(i=1;i<=100;i++) + { + for(j=1;j<=100;j++) + { + s = A*i*i + B*j*j; + if(s>=0) f1[s]++; + else f2[-s]++; + } + } + for(i=1;i<=100;i++) + { + for(j=1;j<=100;j++) + { + s = C*i*i + D*j*j; + if(s>0) ans += f2[s]; + else ans += f1[-s]; + } + } + printf("%d\n",ans*16); + } +} diff --git a/HDOJ/1497_autoAC.cpp b/HDOJ/1497_autoAC.cpp new file mode 100644 index 0000000..730ea36 --- /dev/null +++ b/HDOJ/1497_autoAC.cpp @@ -0,0 +1,110 @@ +#include +#include +#include +struct node +{ + int jb[10]; + int num; +}ui[1005]; +int main() +{ + int M,N,n; + int i; + int u,b,a[100010]; + char ch; + while(scanf("%d%d",&M,&N)!=EOF) + { + memset(a,-1,sizeof(a)); + memset(ui,0,sizeof(ui)); + scanf("%d",&n); + while(n--) + { + getchar(); + scanf("%c",&ch); + if(ch=='B') + { + scanf("%d %d",&u,&b); + if(a[b]!=-1) + { + printf("The book is not in the library now\n"); + } + else + { + if(ui[u].num==9) + { + printf("You are not allowed to borrow any more\n"); + } + else + { + printf("Borrow success\n"); + ui[u].jb[ui[u].num]=b; + ui[u].num++; + a[b]=u; + } + } + } + else if(ch=='R') + { + int j; + scanf("%d",&b); + if(a[b]==-1) + { + printf("The book is already in the library\n"); + } + else + { + int temp; + int num; + num=ui[a[b]].num; + for(j=0;ji;--j) + { + if(ui[u].jb[i] > ui[u].jb[j]) + { + int t = ui[u].jb[i]; + ui[u].jb[i]=ui[u].jb[j]; + ui[u].jb[j] = t; + } + } + } + for(i=0;i +#include +int tot,n,k,list[10005],mark_dfs[10005],mark_gx[20005],mark[105],map[205][205]; +struct dian +{ + int date,next ; +}cun[50005]; +struct rose +{ + int x[20005],y[20005]; + int count; +}cun1[55]; +void add(int a,int b) +{ + cun[tot].date=b; + cun[tot].next=list[a]; + list[a]=tot++; +} +int dfs(int x) +{ + for(int i=list[x];i;i=cun[i].next) + { + int date=cun[i].date; + if(mark_dfs[date]) continue; + mark_dfs[date]=1; + if(mark_gx[date]==-1||dfs(mark_gx[date])) + { + mark_gx[date]=x; + return 1; + } + } + return 0; +} +int main() +{ + int a; + while(scanf("%d%d",&n,&k)!=EOF) + { + if(n==0&&k==0) break; + memset(mark,0,sizeof(mark)); + memset(cun1,0,sizeof(cun1)); + for(int i=1;i<=n;i++) + for(int j=1;j<=n;j++) + { + scanf("%d",&a); + map[i][j]=a; + mark[a]=1; + cun1[a].x[cun1[a].count]=i; + cun1[a].y[cun1[a].count++]=j; + } + int flag=0; + for(int i=1;i<=50;i++) + { + if(mark[i]) + { + tot=1; + memset(cun,0,sizeof(cun)); + memset(list,0,sizeof(list)); + for(int j=0;jk) + { + if(flag==0) + printf("%d",i); + else printf(" %d",i); + flag=1; + } + } + } + if(!flag) printf("-1"); + printf("\n"); + } +}