From ed2de2e423508331d8456935d38ea55c2bf6ec35 Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Sun, 14 Aug 2016 17:42:04 +0800 Subject: [PATCH] Powered By HC TECH : AutoACer Engine 1500-1599 --- HDOJ/1500_autoAC.cpp | 25 ++++++ HDOJ/1501_autoAC.cpp | 38 +++++++++ HDOJ/1502_autoAC.cpp | 73 +++++++++++++++++ HDOJ/1503_autoAC.cpp | 71 ++++++++++++++++ HDOJ/1504_autoAC.cpp | 87 ++++++++++++++++++++ HDOJ/1505_autoAC.cpp | 65 +++++++++++++++ HDOJ/1506_autoAC.cpp | 45 ++++++++++ HDOJ/1507_autoAC.cpp | 90 ++++++++++++++++++++ HDOJ/1508_autoAC.cpp | 42 ++++++++++ HDOJ/1509_autoAC.cpp | 53 ++++++++++++ HDOJ/1510_autoAC.cpp | 41 ++++++++++ HDOJ/1511_autoAC.cpp | 58 +++++++++++++ HDOJ/1512_autoAC.cpp | 121 +++++++++++++++++++++++++++ HDOJ/1513_autoAC.cpp | 42 ++++++++++ HDOJ/1514_autoAC.cpp | 66 +++++++++++++++ HDOJ/1515_autoAC.cpp | 56 +++++++++++++ HDOJ/1516_autoAC.cpp | 43 ++++++++++ HDOJ/1517_autoAC.cpp | 16 ++++ HDOJ/1518_autoAC.cpp | 71 ++++++++++++++++ HDOJ/1519_autoAC.cpp | 22 +++++ HDOJ/1520_autoAC.cpp | 50 ++++++++++++ HDOJ/1521_autoAC.cpp | 45 ++++++++++ HDOJ/1522_autoAC.cpp | 88 ++++++++++++++++++++ HDOJ/1523_autoAC.cpp | 43 ++++++++++ HDOJ/1524_autoAC.cpp | 56 +++++++++++++ HDOJ/1525_autoAC.cpp | 25 ++++++ HDOJ/1526_autoAC.cpp | 160 ++++++++++++++++++++++++++++++++++++ HDOJ/1527_autoAC.cpp | 24 ++++++ HDOJ/1528_autoAC.cpp | 97 ++++++++++++++++++++++ HDOJ/1529_autoAC.cpp | 190 +++++++++++++++++++++++++++++++++++++++++++ HDOJ/1530_autoAC.cpp | 97 ++++++++++++++++++++++ HDOJ/1531_autoAC.cpp | 77 ++++++++++++++++++ HDOJ/1532_autoAC.cpp | 70 ++++++++++++++++ HDOJ/1533_autoAC.cpp | 130 +++++++++++++++++++++++++++++ HDOJ/1534_autoAC.cpp | 100 +++++++++++++++++++++++ HDOJ/1535_autoAC.cpp | 123 ++++++++++++++++++++++++++++ HDOJ/1536_autoAC.cpp | 46 +++++++++++ HDOJ/1537_autoAC.cpp | 70 ++++++++++++++++ HDOJ/1538_autoAC.cpp | 58 +++++++++++++ HDOJ/1539_autoAC.cpp | 56 +++++++++++++ HDOJ/1540_autoAC.cpp | 105 ++++++++++++++++++++++++ HDOJ/1541_autoAC.cpp | 43 ++++++++++ HDOJ/1542_autoAC.cpp | 83 +++++++++++++++++++ HDOJ/1543_autoAC.cpp | 9 ++ HDOJ/1544_autoAC.cpp | 36 ++++++++ HDOJ/1545_autoAC.cpp | 52 ++++++++++++ HDOJ/1546_autoAC.cpp | 79 ++++++++++++++++++ HDOJ/1547_autoAC.cpp | 66 +++++++++++++++ HDOJ/1548_autoAC.cpp | 60 ++++++++++++++ HDOJ/1551_autoAC.cpp | 51 ++++++++++++ HDOJ/1554_autoAC.cpp | 120 +++++++++++++++++++++++++++ HDOJ/1555_autoAC.cpp | 17 ++++ HDOJ/1556_autoAC.cpp | 25 ++++++ HDOJ/1557_autoAC.cpp | 40 +++++++++ HDOJ/1558_autoAC.cpp | 80 ++++++++++++++++++ HDOJ/1559_autoAC.cpp | 57 +++++++++++++ HDOJ/1560_autoAC.cpp | 76 +++++++++++++++++ HDOJ/1561_autoAC.cpp | 53 ++++++++++++ HDOJ/1562_autoAC.cpp | 17 ++++ HDOJ/1563_autoAC.cpp | 17 ++++ HDOJ/1564_autoAC.cpp | 18 ++++ HDOJ/1565_autoAC.cpp | 47 +++++++++++ HDOJ/1566_autoAC.cpp | 77 ++++++++++++++++++ HDOJ/1567_autoAC.cpp | 42 ++++++++++ HDOJ/1568_autoAC.cpp | 29 +++++++ HDOJ/1569_autoAC.cpp | 99 ++++++++++++++++++++++ HDOJ/1570_autoAC.cpp | 22 +++++ HDOJ/1571_autoAC.cpp | 89 ++++++++++++++++++++ HDOJ/1572_autoAC.cpp | 48 +++++++++++ HDOJ/1573_autoAC.cpp | 80 ++++++++++++++++++ HDOJ/1574_autoAC.cpp | 52 ++++++++++++ HDOJ/1575_autoAC.cpp | 79 ++++++++++++++++++ HDOJ/1576_autoAC.cpp | 15 ++++ HDOJ/1577_autoAC.cpp | 58 +++++++++++++ HDOJ/1578_autoAC.cpp | 47 +++++++++++ HDOJ/1579_autoAC.cpp | 46 +++++++++++ HDOJ/1580_autoAC.cpp | 65 +++++++++++++++ HDOJ/1581_autoAC.cpp | 69 ++++++++++++++++ HDOJ/1582_autoAC.cpp | 45 ++++++++++ HDOJ/1583_autoAC.cpp | 65 +++++++++++++++ HDOJ/1584_autoAC.cpp | 62 ++++++++++++++ HDOJ/1587_autoAC.cpp | 21 +++++ HDOJ/1588_autoAC.cpp | 66 +++++++++++++++ HDOJ/1589_autoAC.cpp | 162 ++++++++++++++++++++++++++++++++++++ HDOJ/1590_autoAC.cpp | 16 ++++ HDOJ/1591_autoAC.cpp | 26 ++++++ HDOJ/1592_autoAC.cpp | 38 +++++++++ HDOJ/1593_autoAC.cpp | 12 +++ HDOJ/1594_autoAC.cpp | 31 +++++++ HDOJ/1595_autoAC.cpp | 113 +++++++++++++++++++++++++ HDOJ/1596_autoAC.cpp | 31 +++++++ HDOJ/1597_autoAC.cpp | 15 ++++ HDOJ/1598_autoAC.cpp | 47 +++++++++++ HDOJ/1599_autoAC.cpp | 81 ++++++++++++++++++ 94 files changed, 5629 insertions(+) create mode 100644 HDOJ/1500_autoAC.cpp create mode 100644 HDOJ/1501_autoAC.cpp create mode 100644 HDOJ/1502_autoAC.cpp create mode 100644 HDOJ/1503_autoAC.cpp create mode 100644 HDOJ/1504_autoAC.cpp create mode 100644 HDOJ/1505_autoAC.cpp create mode 100644 HDOJ/1506_autoAC.cpp create mode 100644 HDOJ/1507_autoAC.cpp create mode 100644 HDOJ/1508_autoAC.cpp create mode 100644 HDOJ/1509_autoAC.cpp create mode 100644 HDOJ/1510_autoAC.cpp create mode 100644 HDOJ/1511_autoAC.cpp create mode 100644 HDOJ/1512_autoAC.cpp create mode 100644 HDOJ/1513_autoAC.cpp create mode 100644 HDOJ/1514_autoAC.cpp create mode 100644 HDOJ/1515_autoAC.cpp create mode 100644 HDOJ/1516_autoAC.cpp create mode 100644 HDOJ/1517_autoAC.cpp create mode 100644 HDOJ/1518_autoAC.cpp create mode 100644 HDOJ/1519_autoAC.cpp create mode 100644 HDOJ/1520_autoAC.cpp create mode 100644 HDOJ/1521_autoAC.cpp create mode 100644 HDOJ/1522_autoAC.cpp create mode 100644 HDOJ/1523_autoAC.cpp create mode 100644 HDOJ/1524_autoAC.cpp create mode 100644 HDOJ/1525_autoAC.cpp create mode 100644 HDOJ/1526_autoAC.cpp create mode 100644 HDOJ/1527_autoAC.cpp create mode 100644 HDOJ/1528_autoAC.cpp create mode 100644 HDOJ/1529_autoAC.cpp create mode 100644 HDOJ/1530_autoAC.cpp create mode 100644 HDOJ/1531_autoAC.cpp create mode 100644 HDOJ/1532_autoAC.cpp create mode 100644 HDOJ/1533_autoAC.cpp create mode 100644 HDOJ/1534_autoAC.cpp create mode 100644 HDOJ/1535_autoAC.cpp create mode 100644 HDOJ/1536_autoAC.cpp create mode 100644 HDOJ/1537_autoAC.cpp create mode 100644 HDOJ/1538_autoAC.cpp create mode 100644 HDOJ/1539_autoAC.cpp create mode 100644 HDOJ/1540_autoAC.cpp create mode 100644 HDOJ/1541_autoAC.cpp create mode 100644 HDOJ/1542_autoAC.cpp create mode 100644 HDOJ/1543_autoAC.cpp create mode 100644 HDOJ/1544_autoAC.cpp create mode 100644 HDOJ/1545_autoAC.cpp create mode 100644 HDOJ/1546_autoAC.cpp create mode 100644 HDOJ/1547_autoAC.cpp create mode 100644 HDOJ/1548_autoAC.cpp create mode 100644 HDOJ/1551_autoAC.cpp create mode 100644 HDOJ/1554_autoAC.cpp create mode 100644 HDOJ/1555_autoAC.cpp create mode 100644 HDOJ/1556_autoAC.cpp create mode 100644 HDOJ/1557_autoAC.cpp create mode 100644 HDOJ/1558_autoAC.cpp create mode 100644 HDOJ/1559_autoAC.cpp create mode 100644 HDOJ/1560_autoAC.cpp create mode 100644 HDOJ/1561_autoAC.cpp create mode 100644 HDOJ/1562_autoAC.cpp create mode 100644 HDOJ/1563_autoAC.cpp create mode 100644 HDOJ/1564_autoAC.cpp create mode 100644 HDOJ/1565_autoAC.cpp create mode 100644 HDOJ/1566_autoAC.cpp create mode 100644 HDOJ/1567_autoAC.cpp create mode 100644 HDOJ/1568_autoAC.cpp create mode 100644 HDOJ/1569_autoAC.cpp create mode 100644 HDOJ/1570_autoAC.cpp create mode 100644 HDOJ/1571_autoAC.cpp create mode 100644 HDOJ/1572_autoAC.cpp create mode 100644 HDOJ/1573_autoAC.cpp create mode 100644 HDOJ/1574_autoAC.cpp create mode 100644 HDOJ/1575_autoAC.cpp create mode 100644 HDOJ/1576_autoAC.cpp create mode 100644 HDOJ/1577_autoAC.cpp create mode 100644 HDOJ/1578_autoAC.cpp create mode 100644 HDOJ/1579_autoAC.cpp create mode 100644 HDOJ/1580_autoAC.cpp create mode 100644 HDOJ/1581_autoAC.cpp create mode 100644 HDOJ/1582_autoAC.cpp create mode 100644 HDOJ/1583_autoAC.cpp create mode 100644 HDOJ/1584_autoAC.cpp create mode 100644 HDOJ/1587_autoAC.cpp create mode 100644 HDOJ/1588_autoAC.cpp create mode 100644 HDOJ/1589_autoAC.cpp create mode 100644 HDOJ/1590_autoAC.cpp create mode 100644 HDOJ/1591_autoAC.cpp create mode 100644 HDOJ/1592_autoAC.cpp create mode 100644 HDOJ/1593_autoAC.cpp create mode 100644 HDOJ/1594_autoAC.cpp create mode 100644 HDOJ/1595_autoAC.cpp create mode 100644 HDOJ/1596_autoAC.cpp create mode 100644 HDOJ/1597_autoAC.cpp create mode 100644 HDOJ/1598_autoAC.cpp create mode 100644 HDOJ/1599_autoAC.cpp diff --git a/HDOJ/1500_autoAC.cpp b/HDOJ/1500_autoAC.cpp new file mode 100644 index 0000000..bb6862c --- /dev/null +++ b/HDOJ/1500_autoAC.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#define NN 5010 +#define Min(a,b) (a>b?b:a) +int set[NN]; +int dp[1010][NN]; +int main() +{ + int t,k,n,i,j; + scanf("%d",&t); + while(t--){ + scanf("%d%d",&k,&n); + k += 8; + for(i=n;i>=1;i--) + scanf("%d",&set[i]); + for(i=1;i<=k;i++){ + dp[i][i*3] = dp[i-1][i*3-2] + (set[i*3-1] - set[i*3])*(set[i*3-1] - set[i*3]); + for(j=i*3+1;j<=n;j++) + dp[i][j] = Min(dp[i][j-1],dp[i-1][j-2] +(set[j-1] -set[j])*(set[j-1] - set[j])); + } + printf("%d\n",dp[k][n]); + } + return 0; +} diff --git a/HDOJ/1501_autoAC.cpp b/HDOJ/1501_autoAC.cpp new file mode 100644 index 0000000..a085ea4 --- /dev/null +++ b/HDOJ/1501_autoAC.cpp @@ -0,0 +1,38 @@ +#include +#include +int v[205][205]; +char a[205],b[205],c[410]; +int lena,lenb,lenc; +int dfs(int i,int j,int k) +{ + if(c[k]=='\0') + return 1; + if(v[i][j])return 0; + v[i][j]=1; + if(lena +#include +#include +#include +#include +#define N 1000000 +int f[70][70][70][30] = {0}; +int main() +{ + int i, j, k, n, p; + f[0][0][0][0] = f[1][0][0][0] = f[1][1][0][0] = f[1][1][1][0] = 1; + for(i = 2; i < 65; i++) + { + for(j = 0; j <= i; j++) + { + for(k = 0; k <=j; k++) + { + if(i - 1 >= j) + { + for(p = 0; p < 30; p++) + { + f[i][j][k][p] += f[i - 1][j][k][p]; + if(f[i][j][k][p] >= N) + { + f[i][j][k][p + 1] += f[i][j][k][p]/N; + f[i][j][k][p] %= N; + } + } + } + if(j - 1 >= k) { + for(p = 0; p < 30; p++) + { + f[i][j][k][p] += f[i][j - 1][k][p]; + if(f[i][j][k][p] >= N) + { + f[i][j][k][p + 1] += f[i][j][k][p]/N; + f[i][j][k][p] %= N; + } + } + } + if(k - 1 >= 0) + { + for(p = 0; p < 30; p++) + { + f[i][j][k][p] += f[i][j][k - 1][p]; + if(f[i][j][k][p] >= N) + { + f[i][j][k][p + 1] += f[i][j][k][p]/N; + f[i][j][k][p] %= N; + } + } + } + } + } + } + while(scanf("%d",&n) != EOF) + { + for(i = 29; i >= 0; i--) + { + if(f[n][n][n][i]) + { + printf("%d",f[n][n][n][i]); + break; + } + } + for(i--; i >= 0; i--) + { + printf("%06d",f[n][n][n][i]); + } + printf("\n\n"); + } + return 0; +} diff --git a/HDOJ/1503_autoAC.cpp b/HDOJ/1503_autoAC.cpp new file mode 100644 index 0000000..398bb22 --- /dev/null +++ b/HDOJ/1503_autoAC.cpp @@ -0,0 +1,71 @@ +#include +#include +using namespace std; +char str1[105],str2[105]; +int dp[105][105]; +int record[205][205]; +void output(int l1,int l2) +{ + if(l1==0&&l2==0)return; + if(record[l1][l2]==2) + { + output(l1-1,l2-1); + printf("%c",str1[l1-1]); + } + if(record[l1][l2]==1) + { + output(l1,l2-1); + printf("%c",str2[l2-1]); + } + if(record[l1][l2]==3) + { + output(l1-1,l2); + printf("%c",str1[l1-1]); + } +} +int main() +{ + while(~scanf("%s%s",&str1,&str2)) + { + memset(dp,0,sizeof(dp)); + int len1=strlen(str1); + int len2=strlen(str2); + int count=0; + for(int i=1;i<=len1;i++) + { + dp[i][0]=i; + record[i][0]=3; + } + for(int i=1;i<=len2;i++) + { + dp[0][i]=i; + record[0][i]=1; + } + for(int i=1;i<=len1;i++) + { + for(int j=1;j<=len2;j++) + { + if(str1[i-1]==str2[j-1]) + { + dp[i][j]=dp[i-1][j-1]+1; + record[i][j]=2; + } + else + { + if(dp[i-1][j] +#include +struct node{ + node *child; + node *brother; + char key[10]; +}; +int n,m; +node *root; +void getname(char *str,char *key,int &j) +{ + int i; + for(i=0;str[j]!='\0'&&str[j]!='\\';i++,j++) + key[i]=str[j]; + key[i]='\0'; +} +node *insert(node *parent,char *key) +{ + node *p,*q,*t; + if(!parent->child||strcmp(parent->child->key,key)>0) + { + t=new node; + strcpy(t->key,key); + t->child=NULL; + t->brother=parent->child; + parent->child=t; + return t; + } + if(strcmp(parent->child->key,key)==0) + return parent->child; + for(p=parent->child,q=p->brother;q&&strcmp(q->key,key)<0;p=q,q=q->brother); + if(!q||strcmp(q->key,key)>0) + { + t=new node; + strcpy(t->key,key); + t->brother=p->brother; + p->brother=t; + t->child=NULL; + return t; + } + return q; +} +void read() +{ + char str[90],key[9]; + int i,cur; + node *p; + root=new node; + root->child=NULL; + scanf("%d",&n); + for(i=m=0;ibrother) + { + for(i=0;ikey); + if(p->child) + find(p->child,k+1); + } +} +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + read(); + find(root->child,0); + if(t) + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1505_autoAC.cpp b/HDOJ/1505_autoAC.cpp new file mode 100644 index 0000000..4a5fee3 --- /dev/null +++ b/HDOJ/1505_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +using namespace std; +char str[1100][1100]; +int s[1100][1100]; +struct Q +{ + int num,left,right; +}q[1100]; +int main() +{ + int t; + int row,col; + int i,j,max; + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&row,&col); + for(i=1;i<=row;i++) + for(j=1;j<=col;j++) + { + cin>>str[i][j]; + } + for(i=0;i<=col;i++) + s[0][i]=0; + for(i=1;i<=row;i++) + for(j=1;j<=col;j++) + { + if(str[i][j]!='R') + s[i][j]=s[i-1][j]+1; + else + s[i][j]=0; + } + max=0; + for(i=1;i<=row;i++) + { + for(j=1;j<=col;j++) + { + q[j].num=s[i][j]; + q[j].left=j; + q[j].right=j; + } + q[0].num=-1; + q[col+1].num=-1; + for(j=1;j<=col;j++) + { + while(q[q[j].left-1].num>=q[j].num) + q[j].left=q[q[j].left-1].left; + } + for(j=col;j>=1;j--) + { + while(q[q[j].right+1].num>=q[j].num) + q[j].right=q[q[j].right+1].right; + } + for(j=1;j<=col;j++) + { + if(max +#include +#include +#include +using namespace std; +#define maxn 100005 +int h[maxn]; +int z[maxn], y[maxn]; +int main() +{ + int n; + while(scanf("%d", &n), n) + { + int i, j, k=0, x; + __int64 max=0, sum; + for(i=0; i=0; i--) + { + j = i+1; + while(y[i] != n-1 && h[i] <= h[j]) + { + y[i] = y[j]; + j = y[j] + 1; + } + sum = (__int64)h[i] * (y[i] - z[i] + 1); + if(max < sum)max = sum; + } + printf("%I64d\n", max); + } + return 0; +} diff --git a/HDOJ/1507_autoAC.cpp b/HDOJ/1507_autoAC.cpp new file mode 100644 index 0000000..3567b12 --- /dev/null +++ b/HDOJ/1507_autoAC.cpp @@ -0,0 +1,90 @@ +#include +#include +int map[105][105]; +int m,n,max; +int x_la[50],y_la[50]; +int x_temp[50],y_temp[50]; +int can_move(int x,int y) +{ + if(x>0&&x<=n&&y>0&&y<=m) + { + return 1; + } + return 0; +} +void DFS(int x,int y,int num) +{ + int i,j,k; + if(num>max) + { + max=num; + for(i=0;i +#include +using namespace std; +int f[100000]; +int main() +{ + string s; + while(cin>>s&&s!="0") + { + int i; + for(i=0;i=0;i--) + { + while(s[i]=='0') + { + i--;f[i]=f[i+2];if(i==0)goto end; + i--;f[i]=f[i+1];if(i==0)goto end; + if(s[i]=='0')continue; + i--; + } + if(s[i]<='2') + { + f[i]=f[i+1]+f[i+2]; + } + else + { + f[i]=f[i+1]; + } + } + end: + cout< +#include +#include +#include +#include +#include +using namespace std; +struct node +{ + char name[20]; + int par,pri,id; + friend bool operator < (node a,node b) + { + if(a.pri!=b.pri) + { + return a.pri>b.pri; + } + else return a.id>b.id; + } +}; +int main() +{ + char c[5],na[20]; + int pout,cnt=0,pcmp; + node t; + priority_queue q; + while(scanf("%s",c)!=EOF) + { + if(c[0]=='P') + { + scanf("%s %d %d",na,&pout,&pcmp); + strcpy(t.name,na); + t.par=pout; + t.pri=pcmp; + t.id=++cnt; + q.push(t); + } + else + { + if(!q.empty()) + { + t=q.top(); + q.pop(); + printf("%s %d\n",t.name,t.par); + } + else + { + printf("EMPTY QUEUE!\n"); + } + } + } + return 0; +} diff --git a/HDOJ/1510_autoAC.cpp b/HDOJ/1510_autoAC.cpp new file mode 100644 index 0000000..8627d2e --- /dev/null +++ b/HDOJ/1510_autoAC.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +using namespace std; +const int maxn=110; +char board[maxn]; +int w[maxn][maxn]; +int Min(int x,int y) +{ + return (x=0;j--) + { + if(board[j]=='#') w[i][j]=0; + else w[i][j]=w[i][j+1]+1; + } + for(int j=0;j0;k--) + { + Max=Min(Max,w[k][j]); + if(Max==0) break; + ans+=Max; + } + } + } + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/1511_autoAC.cpp b/HDOJ/1511_autoAC.cpp new file mode 100644 index 0000000..c98f17d --- /dev/null +++ b/HDOJ/1511_autoAC.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +using namespace std; +#define MAX_N 100 +#define max(a,b) (a)>(b)?(a):(b) +int leftdp[MAX_N],rightdp[MAX_N]; +char s[MAX_N]; +bool compare(int s1,int s2,int t1,int t2){ + while(s[s1]=='0') + s1++; + while(s[t1]=='0') + t1++; + if(s2-s1!=t2-t1) + return s2-s1=0;i--) + for(j=i;j<=tlen;j++) + if(compare(i,j,j,rightdp[j])) + rightdp[i]=max(rightdp[i],j); + OutputPath(len); + } + return 0; +} diff --git a/HDOJ/1512_autoAC.cpp b/HDOJ/1512_autoAC.cpp new file mode 100644 index 0000000..526e678 --- /dev/null +++ b/HDOJ/1512_autoAC.cpp @@ -0,0 +1,121 @@ +#include +#include +#include +using namespace std; +const int maxn=100003; +int n,m; +int f[maxn]; +typedef struct node +{ + int sword; + int dis; + node* left; + node* right; +}*Pnode; +Pnode tree[maxn]; +int distance(Pnode t) +{ + return t?t->dis:0; +} +void fixdis(Pnode t) +{ + if(distance(t->left)right)) + swap(t->left,t->right); + t->dis=distance(t->right)+1; +} +Pnode merge(Pnode a,Pnode b) +{ + if(!a) + return b; + if(!b) + return a; + if(b->sword>a->sword) + swap(a,b); + a->right=merge(a->right,b); + fixdis(a); + return a; +} +Pnode delMax(Pnode t) +{ + if(t) + return merge(t->left,t->right); + return NULL; +} +void init(Pnode &t,int sword) +{ + t=new node; + t->dis=1; + t->left=t->right=NULL; + t->sword=sword; +} +int find(int x) +{ + int y,root,t; + y=x; + while(f[y]>0) + y=f[y]; + root=y; + y=x; + while(f[y]>0) + { + t=f[y]; + f[y]=root; + y=t; + } + return root; +} +int unio(int x,int y) +{ + if(f[x]sword/2); + p2=delMax(tree[fu]); + p2=merge(p1,p2); + init(p3,tree[fv]->sword/2); + p4=delMax(tree[fv]); + p4=merge(p3,p4); + fv=unio(fu,fv); + tree[fv]=merge(p2,p4); + cout<sword<>n) + { + for(i=1;i<=n;++i) + { + cin>>d; + init(tree[i],d); + } + memset(f,-1,sizeof(f)); + cin>>m; + for(i=0;i>u>>v; + solve(u,v); + } + for(i=1;i<=n;++i) + delete tree[i]; + } + return 0; +} diff --git a/HDOJ/1513_autoAC.cpp b/HDOJ/1513_autoAC.cpp new file mode 100644 index 0000000..af134be --- /dev/null +++ b/HDOJ/1513_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +using namespace std; +#define max 5000+10 +#define Max(a,b) a>b?a:b +int a[2][max]; +int commonorder(string s1,string s2) +{ + int i,j; + memset(a,0,sizeof(a)); + int m=1; + for(i=0;i>n) + { + cin>>str; + int j; + char temp[max]; + int k=0; + temp[n]='\0'; + for(j=n-1;j>=0;j--) + {temp[k]=str[j];k++;} + int sum=commonorder(str,temp); + printf("%d\n",n-sum); + } + return 0; +} diff --git a/HDOJ/1514_autoAC.cpp b/HDOJ/1514_autoAC.cpp new file mode 100644 index 0000000..d8e1dff --- /dev/null +++ b/HDOJ/1514_autoAC.cpp @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +const int candy_num = 40 + 5; +const int basket_num = 5 + 2; +int dp[candy_num][candy_num][candy_num][candy_num]; +int h[basket_num], f[candy_num][basket_num]; +int ans, n; +set S; +set ::iterator it; +int check(int a) +{ + it = S.find(a); + if (it != S.end()) + { + S.erase(a); + return 1; + } + S.insert(a); + return 0; +} +int dfs(int tmp) +{ + if (dp[h[0]][h[1]][h[2]][h[3]] != -1) + return dp[h[0]][h[1]][h[2]][h[3]]; + int tt = 0; + for (int i = 0; i < 4; i++) + { + if (h[i] < n && S.size() < 5) + { + int t = check(f[h[i]][i]); + if (S.size() < 5) + { + h[i]++; + tt = max(tt, dfs(tmp+t)); + h[i]--; + } + tt = max(tt, tmp+t); + if (t == 1) + S.insert(f[h[i]][i]); + else + S.erase(f[h[i]][i]); + } + } + return dp[h[0]][h[1]][h[2]][h[3]] = tt; +} +int main() +{ + while (scanf("%d", &n) != EOF && n) + { + for (int i = 0; i < n; i++) + { + for (int j = 0; j < 4; j++) + scanf("%d", &f[i][j]); + } + ans = 0; + h[0] = h[1] = h[2] = h[3] = 0; + memset(dp, -1, sizeof(dp)); + printf("%d\n", dfs(0)); + } + return 0; +} diff --git a/HDOJ/1515_autoAC.cpp b/HDOJ/1515_autoAC.cpp new file mode 100644 index 0000000..cec78d1 --- /dev/null +++ b/HDOJ/1515_autoAC.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +#include +using namespace std; +const int maxn=100; +char x1[maxn]; +char s1[maxn]; +char s2[maxn]; +char stack[maxn]; +int len1,len2,len3; +void dfs(int x,int y,int ptr) +{ + if(y==len2) + { + printf("\n"); + for(int i=0;i0&&stack[ptr-1]==s2[y]) + { + x1[len3++]='o'; + dfs(x,y+1,ptr-1); + len3--; + } + } +} +int main() +{ + while(scanf("%s%s",&s1,&s2)!=EOF) + { + len1=strlen(s1); + len2=strlen(s2); + len3=0; + if(len1!=len2) + { + printf("[\n]\n"); + continue; + } + printf("["); + dfs(0,0,0); + printf("\n]\n"); + } + return 0; +} diff --git a/HDOJ/1516_autoAC.cpp b/HDOJ/1516_autoAC.cpp new file mode 100644 index 0000000..f05f9f0 --- /dev/null +++ b/HDOJ/1516_autoAC.cpp @@ -0,0 +1,43 @@ +#include +#include +#define SIZE 80 +#define MAX 100000 +int Min(int x,int y,int z){ + int min= x +using namespace std; +int main() +{ + double n; + while(cin>>n) + { + while(n>18) + n/=18; + if(n<=9) + cout<<"Stan wins."< +#include +#include +using namespace std; +int a[25],sji,d[25],ji,n; +bool b[25]; +void dfs(int digit,int num,int bj) +{ + if(num == ji) + { + digit++; + num=0; + } + if(digit == 3) + { + sji=1; + return ; + } + int i; + if(num == 0)bj=digit; + for(i=bj+1;iy; +} +int main() +{ + int t,i,j; + while(~scanf("%d",&t)) + { + while(t--) + { + scanf("%d",&n); + ji=0; + for(i=0;iji) + { + printf("no\n"); + continue; + } + b[0]=false; + sji=0; + dfs(0,a[0],0); + if(!sji)printf("no\n"); + else printf("yes\n"); + } + } + return 0; +} diff --git a/HDOJ/1519_autoAC.cpp b/HDOJ/1519_autoAC.cpp new file mode 100644 index 0000000..facf57a --- /dev/null +++ b/HDOJ/1519_autoAC.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; +int main() +{ + int size; + cin>>size; + for(int l=0;l>n; + int sum=0; + for(int i=0;i>temp; + sum+=temp; + } + if(sum>=0) + cout< +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 99999999 +using namespace std; +const int MAX=6000+10; +int n,size,head[MAX],pre[MAX]; +int temp[2],val[MAX]; +struct Edge{ + int v,next; + Edge(){} + Edge(int V,int NEXT):v(V),next(NEXT){} +}edge[MAX]; +void Init(int num){ + for(int i=0;i<=num;++i)head[i]=-1,pre[i]=0; + size=0; +} +void InsertEdge(int u,int v){ + edge[size]=Edge(v,head[u]); + head[u]=size++; +} +void dfs(int u){ + int dp[2]={0,0}; + for(int i=head[u];i != -1;i=edge[i].next){ + int v=edge[i].v; + dfs(v); + dp[0]=dp[0]+max(temp[0],temp[1]); + dp[1]=dp[1]+temp[0]; + } + temp[0]=dp[0]; + temp[1]=dp[1]+val[u]; +} +int main(){ + int u,v; + while(~scanf("%d",&n)){ + Init(n); + for(int i=1;i<=n;++i)scanf("%d",&val[i]); + while(scanf("%d%d",&v,&u),u+v)pre[v]=u; + for(int i=1;i<=n;++i)InsertEdge(pre[i],i); + dfs(0); + printf("%d\n",temp[0]); + } + return 0; +} diff --git a/HDOJ/1521_autoAC.cpp b/HDOJ/1521_autoAC.cpp new file mode 100644 index 0000000..5071422 --- /dev/null +++ b/HDOJ/1521_autoAC.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +#include +using namespace std; +int a[15],n,m,ans; +int fun(int num) +{ + if(num == 0)return 1; + int sum=1,i; + for(i=2;i<=num;i++)sum*=i; + return sum; +} +void dfs(int num,int sum,int ma) +{ + if(sum>m)return ; + if(num == n) + { + if(sum == m) + { + ans+=fun(m)/ma; + } + return ; + } + int i; + for(i=0;i<=a[num];i++) + { + dfs(num+1,sum+i,ma*fun(i)); + } +} +int main() +{ + int i,j; + while(~scanf("%d %d",&n,&m)) + { + for(i=0;i +#include +#include +#include +#include +#include +#define maxn 555 +#define clr(x)memset(x,0,sizeof(x)) +using namespace std; +int tot; +int n; +int b[maxn][maxn]; +int g[maxn][maxn]; +int by[maxn],gl[maxn]; +int r[maxn]; +char s[100]; +string bo[maxn],gi[maxn]; +int main() +{ + int bn,gn,t,flag,i,j,f; + while(scanf("%d",&n)!=EOF) + { + f=0; + getchar(); + gn=1; + clr(b); + clr(g); + for(i=1;i<=n;i++)r[i]=1; + mapboy,girl; + boy.clear(),girl.clear(); + tot=1; + for(i=1;i<=n;i++) + { + scanf("%s",s); + boy[s]=i; + bo[i]=s; + for(j=1;j<=n;j++) + { + scanf("%s",s); + if(!girl[s]) + { + girl[s]=j; + gi[j]=s; + b[i][j]=j; + } + else b[i][j]=girl[s]; + } + } + for(i=1;i<=n;i++) + { + scanf("%s",s); + t=girl[s]; + for(j=1;j<=n;j++) + { + scanf("%s",s); + g[t][boy[s]]=n-j; + } + } + clr(by); clr(gl); + while(1) + { + flag=1; + for(i=1;i<=n;i++) + if(!by[i]) + { + t=b[i][r[i]++]; + if(!gl[t]) + { + by[i]=t; + gl[t]=i; + } + else if(g[t][gl[t]] +#include +char Morse[26][5]={{".-"},{"-..."},{"-.-."},{"-.."}, +{"."},{"..-."},{"--."},{"...."},{".."},{".---"},{"-.-"},{".-.."}, +{"--"},{"-."},{"---"},{".--."},{"--.-"},{".-."},{"..."},{"-"}, +{"..-"},{"...-"},{".--"},{"-..-"},{"-.--"},{"--.."}}; +char Dict[10005][205]; +int dp[40005]; +int main() +{ + int T, i, n, len, j, a; + char str[10270], str2[270]; + scanf("%d",&T); + while(T--) + { + scanf("%s",str); + len = strlen(str); + scanf("%d",&n); + memset(dp,0,sizeof(dp)); + for(i=0; i +#include +typedef struct to +{ + int num; + int go[1005]; +}E; +E e[1005]; +int sg[1005]; +int getsg(int n) +{ + int visit[1005]; + int i,j; + memset(visit,0,sizeof(visit)); + if(e[n].num==0){sg[n]=0;return sg[n];} + if(sg[n]!=-1)return sg[n]; + for(i=0;i +int main () +{ + int a,b,t,sw; + while(~scanf("%d%d",&a,&b)) + { + if(!a&&!b) + break; + t=0; + while(1) + { + if(a=2) + break; + a=a%b; + } + if(t&1) + printf("Stan wins\n"); + else + printf("Ollie wins\n"); + } + return 0; +} diff --git a/HDOJ/1526_autoAC.cpp b/HDOJ/1526_autoAC.cpp new file mode 100644 index 0000000..61f3450 --- /dev/null +++ b/HDOJ/1526_autoAC.cpp @@ -0,0 +1,160 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +const int N = 600; +const int M = 800000; +const int inf = 0x3f3f3f3f; +int n,m,k,sum,num; +struct node +{ + int to,c,next,pre; +}arc[M]; +int head[N],sta[N],que[N],cnt[N],dis[N],rpath[N]; +mapmp1,mp2; +void build(int s,int e,int cap) +{ + arc[num].to = e; + arc[num].c = cap; + arc[num].next = head[s]; + head[s] = num ++; + arc[num - 1].pre = num; + arc[num].pre = num - 1; + arc[num].to = s; + arc[num].next = head[e]; + arc[num].c = 0; + head[e] = num ++; +} +void init() +{ + memset(head,-1,sizeof(head)); + num = 0; + int i; + string s1,s2; + mp1.clear(); + mp2.clear(); + scanf("%d",&n); + for(i = 2;i < n + 2;i ++) + { + cin>>s1; + mp2[s1] = i; + build(i,1,1); + } + scanf("%d",&m); + sum = m + n + 2; + for(i = n + 2;i <= m + 1 + n;i ++) + { + cin>>s1>>s2; + mp1[s1] = i; + build(0,i,1); + if(mp2[s2] == 0) + { + mp2[s2] = sum ++; + } + build(i,mp2[s2],1); + } + scanf("%d",&k); + for(i = 1;i <= k;i ++) + { + cin>>s1>>s2; + if(mp2[s1] == 0) + { + mp2[s1] = sum ++; + } + if(mp2[s2] == 0) + { + mp2[s2] = sum ++; + } + build(mp2[s1],mp2[s2],inf); + } + sum --; +} +void re_Bfs() +{ + int i,front,rear; + for(i = 0;i <= sum;i ++) + { + cnt[i] = 0; + dis[i] = inf; + } + front = rear = 0; + que[rear ++] = 1; + cnt[0] ++; + dis[1] = 0; + while(front != rear) + { + int u = que[front ++]; + for(i = head[u];i != -1;i = arc[i].next) + { + if(arc[arc[i].pre].c == 0 || dis[arc[i].to] < inf) + continue; + dis[arc[i].to] = dis[u] + 1; + cnt[dis[arc[i].to]] ++; + que[rear ++] = arc[i].to; + } + } +} +void ISAP() +{ + re_Bfs(); + int i,u,v,maxflow = 0; + for(i = 0;i <= sum;i ++) + sta[i] = head[i]; + u = 0; + while(dis[0] < sum) + { + if(u == 1) + { + int curflow = inf; + for(i = 0;i != 1;i = arc[sta[i]].to) + curflow = min(curflow,arc[sta[i]].c); + for(i = 0;i != 1;i = arc[sta[i]].to) + { + arc[sta[i]].c -= curflow; + arc[arc[sta[i]].pre].c += curflow; + } + maxflow += curflow; + u = 0; + } + for(i = sta[u];i != -1;i = arc[i].next) + if(arc[i].c > 0 && dis[u] == dis[arc[i].to] + 1) + break; + if(i != -1) + { + sta[u] = i; + rpath[arc[i].to] = arc[i].pre; + u = arc[i].to; + } + else + { + if((-- cnt[dis[u]]) == 0) + break; + sta[u] = head[u]; + int Min = sum; + for(i = sta[u];i != -1;i = arc[i].next) + if(arc[i].c > 0) + Min = min(Min,dis[arc[i].to]); + dis[u] = Min + 1; + cnt[dis[u]] ++; + if(u != 0) + u = arc[rpath[u]].to; + } + } + printf("%d\n",m - maxflow); +} +int main() +{ + int t; + scanf("%d",&t); + while(t --) + { + init(); + ISAP(); + if(t) + puts(""); + } + return 0; +} diff --git a/HDOJ/1527_autoAC.cpp b/HDOJ/1527_autoAC.cpp new file mode 100644 index 0000000..b58cce0 --- /dev/null +++ b/HDOJ/1527_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +int main() +{ + int a,b; + while(scanf("%d%d",&a,&b)==2) + { + double j,k,r,R; + int t; + if(a>b) + { + t=a; + a=b; + b=t; + } + r=(sqrt(5.0)-1)/2; + R=1.0/r; + j=(int)(r*a); + if(a!=(int)(j*R)) + j+=1; + printf("%d\n",b!=(int)(j*R)+j); + } + return 0; +} diff --git a/HDOJ/1528_autoAC.cpp b/HDOJ/1528_autoAC.cpp new file mode 100644 index 0000000..c76db12 --- /dev/null +++ b/HDOJ/1528_autoAC.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +#include +using namespace std; +vector card[100]; +int n; +bool vis[100]; +int link[100]; +int num_pre(char a) +{ + static string pre = "23456789TJQKA"; + for(int i = 0;i < pre.size();i ++) + { + if(a == pre.at(i)) + return i; + } + return pre.size(); +} +int num_suf(char a) +{ + static string suf = "CDSH"; + for(int i = 0;i < suf.size();i ++) + { + if(a == suf.at(i)) + return i; + } + return suf.size(); +} +bool is_big(const string& a,const string& b) +{ + int aa = num_pre(a.at(0)); + int bb = num_pre(b.at(0)); + if(aa == bb) + return num_suf(a.at(1)) > num_suf(b.at(1)); + return aa > bb; +} +bool can(int x) +{ + int len = card[x].size(); + for(int i = 0;i < len;i ++) + { + int t = card[x].at(i); + if(!vis[t]) + { + vis[t] = true; + if(link[t] == -1 || can(link[t])) + { + link[t] = x; + return true; + } + } + } + return false; +} +int maxmatch() +{ + int num = 0; + for(int i = 0;i < n;i ++) + { + memset(vis,false,sizeof(vis)); + if(can(i)) + num ++; + } + return num; +} +int main() +{ + int cas; + cin >> cas; + while(cas --) + { + cin >> n; + memset(link,-1,sizeof(link)); + for(int i = 0;i < n;i ++) + { + card[i].clear(); + } + string ss[100]; + for(int i = 0;i < n;i ++) + { + cin >> ss[i]; + } + string ee; + for(int i = 0;i < n;i ++) + { + cin >> ee; + for(int j = 0;j < n;j ++) + { + if(is_big(ee,ss[j])) + card[j].push_back(i); + } + } + printf("%d\n",maxmatch()); + } + return 0; +} diff --git a/HDOJ/1529_autoAC.cpp b/HDOJ/1529_autoAC.cpp new file mode 100644 index 0000000..2829c2f --- /dev/null +++ b/HDOJ/1529_autoAC.cpp @@ -0,0 +1,190 @@ +#include +#include +using namespace std; +const long MAXN=1000; +const long lmax=0xF000FFFF; +typedef struct +{ + long v; + long next; + long cost; +}Edge; +Edge e[MAXN]; +long p[MAXN]; +long Dis[MAXN]; +bool vist[MAXN]; +long ct[MAXN]; +long R[30]; +long S[30]; +long Num[30]; +queue q; +long eid; +inline void init() +{ + memset(vist,0,sizeof(vist)); + memset(ct,0,sizeof(ct)); + long i; + for (i=0;i7) + { + from=i-8; + to=i; + cost=R[i]; + e[eid].next=p[from]; + e[eid].v=to; + e[eid].cost=cost; + p[from]=eid++; + } + } + from=MAXN-1,to=0,cost=0; + e[eid].next=p[from]; + e[eid].v=to; + e[eid].cost=cost; + p[from]=eid++; + long ss; + for (i=0;i<24;++i) + { + if(i==23) + { + ss=eid; + } + from=MAXN-1,to=i,cost=0; + e[eid].next=p[from]; + e[eid].v=to; + e[eid].cost=cost; + p[from]=eid++; + } + from=0,to=MAXN-1,cost=-Num[0]; + e[eid].next=p[from]; + e[eid].v=to; + e[eid].cost=cost; + p[from]=eid++; + long save[10]; + long sum=0; + for (i=0;i<=7;++i) + { + from=i+16; + to=i; + cost=R[i]-sum; + save[i]=eid; + e[eid].next=p[from]; + e[eid].v=to; + e[eid].cost=cost; + p[from]=eid++; + } + long Start,End; + Start=MAXN-1; + End=23; + bool doit=false; + while(!doit&&sum<=N) + { + for (i=0;i<=7;++i) + { + e[save[i]].cost=R[i]-sum; + } + e[ss].cost=sum; + init(); + doit=true; + ++(ct[Start]); + Dis[Start]=0; + vist[Start]=true; + q.push(Start); + while (!q.empty()) + { + long t=q.front(); + q.pop(); + vist[t]=false; + long j; + for (j=p[t];j!=-1;j=e[j].next) + { + long w=e[j].cost; + if (w+Dis[t]>Dis[e[j].v]) + { + Dis[e[j].v]=w+Dis[t]; + if (!vist[e[j].v]) + { + vist[e[j].v]=true; + q.push(e[j].v); + ++(ct[e[j].v]); + if ((ct[e[j].v])>eid) + { + doit=false; + goto L1; + } + } + } + } + } +L1: + if(!doit||Dis[End]!=sum) + { + doit=false; + ++sum; + } + else + { + break; + } + } + if (doit&&Dis[End]==sum&&N!=4) + { + printf("%ld\n",sum); + } + else + { + printf("No Solution\n"); + } +} +int main() +{ + long T; + scanf("%ld",&T); + while (T--) + { + SPF(); + } + return 0; +} diff --git a/HDOJ/1530_autoAC.cpp b/HDOJ/1530_autoAC.cpp new file mode 100644 index 0000000..8297504 --- /dev/null +++ b/HDOJ/1530_autoAC.cpp @@ -0,0 +1,97 @@ +#include +#include +#include +using namespace std; +#define NMAX 55 +bool path[NMAX][NMAX]; +int n,mmax; +int dp[NMAX]; +bool v[NMAX]; +int seq[NMAX], seq_pos; +bool dfs(int pos, int size) +{ + int i, j, unvis; + bool tv[NMAX]; + unvis = 0; + for (i=pos; i mmax) + { + mmax = size; + seq_pos = 0; + seq[ seq_pos ++] = pos+1; + return true; + } + return false; + } + for (i=pos; i < n && unvis > 0 ; i++) + { + if (!v[i]) + { + if (unvis + size <= mmax || dp[i] + size <= mmax) + { + return false; + } + v[i] = true; + unvis --; + memcpy(tv, v, sizeof(v)); + for (j=0; j=0; i--) + { + for (j=0; j +#include +#include +using namespace std; +int head[25000]; +int visit[25000]; +int dis[25000]; +int in[25000]; +const int inf=1<<30; +int ne; +int n,m; +struct edge +{ + int from,to,next; + int weight; +}P[250000]; +void insert(int x,int y,int weight) +{ + P[ne].from=x;P[ne].to=y;P[ne].weight=weight;P[ne].next=head[x];head[x]=ne++; +} +void init() +{ + int i; + for(i=0;i<=n;i++) + dis[i]=-inf; +} +bool bellman() +{ + int i,j; + init(); + for(i=0;i<=n+1;i++) + { + for(j=1;j>op; + scanf("%d",&weight); + if(op[0]=='g') + { + insert(si-1,ni+si,weight+1); + insert(-1,si-1,0); + insert(-1,si+ni,0); + } + else + { + insert(ni+si,si-1,1-weight); + insert(-1,si-1,0); + insert(-1,si+ni,0); + } + } + if(bellman()) + printf("lamentable kingdom\n"); + else + printf("successful conspiracy\n"); + } + return 0; +} diff --git a/HDOJ/1532_autoAC.cpp b/HDOJ/1532_autoAC.cpp new file mode 100644 index 0000000..7526c59 --- /dev/null +++ b/HDOJ/1532_autoAC.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +using namespace std; +const int MAXM=203; +int capacity[MAXM][MAXM]; +int flow[MAXM]; +int pre[MAXM]; +int n,m; +int bfs() +{ + memset(pre,0,sizeof(pre)); + flow[1]=11000000; + queue q; + q.push(1); + while(!q.empty()) + { + int s=q.front(); + q.pop(); + for(int i=2;i<=m;++i) + if(capacity[s][i]>0&&pre[i]==0) + { + flow[i]=min(flow[s],capacity[s][i]); + pre[i]=s; + if(i==m) + return flow[m]; + q.push(i); + } + } + return 0; +} +int maxFlow() +{ + int increase; + int sumflow=0; + while(increase=bfs()) + { + sumflow+=increase; + for(int i=m;i;i=pre[i]) + { + capacity[pre[i]][i]-=increase; + capacity[i][pre[i]]+=increase; + } + } + return sumflow; +} +void show() +{ + for(int i=1;i<=m;++i) + { + for(int j=1;j<=m;++j) + cout<>n>>m) + { + memset(capacity,0,sizeof(capacity)); + for(int i=1;i<=n;++i) + { + cin>>a>>b>>c; + capacity[a][b]+=c; + } + cout< +#include +#include +#define INF 1000000000 +#define N 1005 +using namespace std; +int list[N],dis[N],hx[N],hy[N],px[N],py[N],tot,pre[N],pr[N]; +char map[205][205]; +struct dian +{ + int date,value,next,cost; +}cun[2000005]; +void add(int a,int b,int c,int d) +{ + cun[++tot].date=b; + cun[tot].value=c; + cun[tot].next=list[a]; + cun[tot].cost=d; + list[a]=tot; + cun[++tot].date=a; + cun[tot].value=0; + cun[tot].next=list[b]; + cun[tot].cost=-d; + list[b]=tot; +} +int abss(int a) +{ + if(a>0) return a; + return -a; +} +int spfa(int s,int t) +{ + queue p; + int vis[N]; + for(int i=0;i<1005;i++) + { + dis[i]=INF; + vis[i]=0; + pre[i]=-1; + } + dis[s]=0; + p.push(s); + int k; + while(!p.empty()) + { + k=p.front(); + p.pop(); + vis[k]=0; + for(int i=list[k];i;i=cun[i].next) + { + int w=cun[i].value; + int c=cun[i].cost; + int to=cun[i].date; + if(w>0&&dis[to]>dis[k]+c) + { + dis[to]=dis[k]+c; + pre[to]=k; + pr[to]=i; + if(!vis[to]) + { + vis[to]=1; + p.push(to); + } + } + } + } + if(dis[t]>=INF) return 0; + return 1; +} +int maxflow(int s,int t) +{ + int min=INF; + int sum=0; + while(spfa(s,t)) + { + for(int i=t;i!=s;i=pre[i]) + { + if(min +#include +#include +#include +#define MAX 100000 +using namespace std; +struct edge +{ + int x,next,value; +}e[20*MAX]; +int cnt,head[MAX],c[MAX],a[MAX],d[MAX]; +bool visited[MAX],flag[MAX]; +void add(int u,int v,int w) +{ + e[cnt].x=v; + e[cnt].value=w; + e[cnt].next=head[u]; + head[u]=cnt++; +} +bool SPFA(int s,int n) +{ + int tnext,tx,temp; + memset(visited,false,sizeof(visited)); + memset(c,0,sizeof(c)); + queueQ; + while(!Q.empty()) Q.pop(); + Q.push(s); + c[s]++; + d[s]=0; + visited[s]=true; + flag[s]=true; + while(!Q.empty()) + { + temp=Q.front();Q.pop(); + tnext=head[temp]; + while(tnext!=-1) + { + tx=e[tnext].x; + if(d[tx]n) return false; + visited[tx]=true; + } + } + tnext=e[tnext].next; + } + visited[temp]=false; + } + return true; +} +int main() +{ + int n,i,u,v,k=1; + string str; + while(cin>>n&&n) + { + cnt=0; + for(i=1;i<=n;i++)cin>>a[i]; + for(i=0;i>str&&str!="#") + { + cin>>u>>v; + if(str=="SAS") add(v,u,0); + if(str=="SAF") add(v,u,a[v]); + if(str=="FAF") add(v,u,a[v]-a[u]); + if(str=="FAS") add(v,u,-a[u]); + } + cout<<"Case "< +#include +#include +#include +#include +#define INF 1000000000 +#define N 1000000+10 +using namespace std; +typedef struct +{ + int to; + int w; + int next; +}node; +node E[N]; +node e[N]; +int head[N],dis[N],visit[N],cnt; +int list[N],len[N],tot; +void ADD(int a,int b,int c) +{ + E[++cnt].to=b; + E[cnt].w=c; + E[cnt].next=head[a]; + head[a]=cnt; +} +void add(int a,int b,int c) +{ + e[++tot].to=b; + e[tot].w=c; + e[tot].next=list[a]; + list[a]=cnt; +} +void spfa(int s,int t) +{ + queueQ; + for(int i=0;iQ; + Q.push(s); + while(!Q.empty()) + { + int k=Q.front(); + Q.pop(); + visit[k]=0; + for(int i=list[k];i;i=e[i].next) + { + int to=e[i].to; + int w=e[i].w; + if(len[k]+w +#include +#include +using namespace std; +int s[101]; +int tt[10001]; +int g(int x , int k) +{ + int mex[101]; + memset(mex,0,sizeof(mex)); + if(tt[x]!=-1) return tt[x]; + if(x-s[0]<0) return tt[x]=0; + for(int i=0;i=0;i++) + { + mex[g(x-s[i] , k)]=1; + } + for(int i=0;;i++) + if(!mex[i]) return tt[x]=i; +} +int main() +{ + int k ; + int n, t ,a , ans; + while(scanf("%d",&k)!=EOF && k) + { + memset(tt,-1,sizeof(tt)); + tt[0]=0; + for(int i=0;i +#include +char a[6][9],s[3]; +int T,cas; +void turn(int i,int j) +{ + char p[9]; + memcpy(p,a[i],sizeof(p)); + if(j==1) + { + for(int k=0,l=0;k<9;k+=3,l++) + a[i][k]=p[6+l],a[i][k+1]=p[3+l],a[i][k+2]=p[l]; + } + else + { + for(int k=0,l=0;k<9;k+=3,l++) + a[i][k]=p[2-l],a[i][k+1]=p[5-l],a[i][k+2]=p[8-l]; + } +} +void go(int P,char &b,char &c,char &d,char &e,char &f,char &g,char &h,char &i,char &j,char &k,char &l,char &m) +{ + char o=k,p=l,q=m; + if(P==1) + { + m=j;l=i;k=h;j=g;i=f;h=e;g=d;f=c;e=b;d=q;c=p;b=o; + } + else + { + k=b;l=c;m=d;b=e;c=f;d=g;e=h;f=i;g=j;h=o;i=p;j=q; + } +} +int main() +{ + scanf("%d",&T); + while(T--) + { + for(int i=0;i<9;i++){scanf("%s",s);a[4][i]=s[0];} + for(int i=0;i<9;i+=3) + for(int j=0;j<4;j++) + for(int k=0;k<3;k++) + {scanf("%s",s);a[j][i+k]=s[0];} + for(int i=0;i<9;i++){scanf("%s",s);a[5][i]=s[0];} + int t,f,p; + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&f,&p); + turn(f,p); + if(f==0) + go(p,a[4][0],a[4][3],a[4][6],a[1][0],a[1][3],a[1][6],a[5][0],a[5][3],a[5][6],a[3][8],a[3][5],a[3][2]); + if(f==1) + go(p,a[4][6],a[4][7],a[4][8],a[2][0],a[2][3],a[2][6],a[5][2],a[5][1],a[5][0],a[0][8],a[0][5],a[0][2]); + if(f==2) + go(p,a[5][8],a[5][5],a[5][2],a[1][8],a[1][5],a[1][2],a[4][8],a[4][5],a[4][2],a[3][0],a[3][3],a[3][6]); + if(f==3) + go(p,a[4][2],a[4][1],a[4][0],a[0][0],a[0][3],a[0][6],a[5][6],a[5][7],a[5][8],a[2][8],a[2][5],a[2][2]); + if(f==4) + go(p,a[3][2],a[3][1],a[3][0],a[2][2],a[2][1],a[2][0],a[1][2],a[1][1],a[1][0],a[0][2],a[0][1],a[0][0]); + if(f==5) + go(p,a[1][6],a[1][7],a[1][8],a[2][6],a[2][7],a[2][8],a[3][6],a[3][7],a[3][8],a[0][6],a[0][7],a[0][8]); + } + printf("Scenario #%d:\n",++cas); + for(int i=0;i<9;i+=3)printf(" %c %c %c\n",a[4][i],a[4][i+1],a[4][i+2]); + for(int i=0;i<9;i+=3) + for(int j=0;j<4;j++) + printf("%c %c %c%c",a[j][i],a[j][i+1],a[j][i+2],j==3?'\n':' '); + for(int i=0;i<9;i+=3)printf(" %c %c %c\n",a[5][i],a[5][i+1],a[5][i+2]); + puts(""); + } +} diff --git a/HDOJ/1538_autoAC.cpp b/HDOJ/1538_autoAC.cpp new file mode 100644 index 0000000..56317ad --- /dev/null +++ b/HDOJ/1538_autoAC.cpp @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#define C 240 +#define TIME 10 +#define inf 1<<25 +#define LL long long +using namespace std; +int fac[15]={2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}; +void slove(int n,int m,int p){ + if(n<=2*m){ + if(n!=p&&(n%2==p%2)) + printf("1\n"); + else if(n==p) + printf("%d\n",m-(n-1)/2); + else + printf("0\n"); + return ; + } + else if(n==2*m+1){ + if(p<2*m&&p&1) + printf("1\n"); + else + printf("0\n"); + return ; + } + int t=n-2*m,i; + for( i=0;i<14;i++){ + if(t==fac[i]&&p==t)//杩搴璇ュ涓p==t + { + printf("0\n"); + return; + } + } + for( i=1;i<14;i++) + if(t2*m+fac[i-1]&&p<2*m+fac[i]) + printf("Thrown\n"); + else + printf("0\n"); + return ; + } +} +int main(){ + int t,n,m,p; + scanf("%d",&t); + while(t--){ + scanf("%d%d%d",&n,&m,&p); + slove(n,m,p); + } + return 0; +} diff --git a/HDOJ/1539_autoAC.cpp b/HDOJ/1539_autoAC.cpp new file mode 100644 index 0000000..ae46404 --- /dev/null +++ b/HDOJ/1539_autoAC.cpp @@ -0,0 +1,56 @@ +#include +#include +#include +using namespace std; +#define MAXN 25 +char str[MAXN]; +int n,len,relen,ans,l,flag; +int path[MAXN]; +int repath[MAXN]; +void dfs(int pos,int sum) +{ + if(sum > n) return ; + if(pos == len) + { + if(sum <= n && sum >= ans) + { + if(sum == ans) flag = 2; + else + { + ans = sum,relen = 0,flag = 1; + for(int i = 0 ; i < l ; i++) + repath[relen++] = path[i]; + } + } + return ; + } + int tmp = 0; + for(int i = pos ; i < len ; i++) + { + tmp = tmp * 10 + str[i] - '0'; + path[l++] = tmp; + dfs(i + 1,sum + tmp); + l--; + } +} +int main() +{ + while(~scanf("%d%s",&n,str) && n && str[0] != '0') + { + len = strlen(str); + memset(path,0,sizeof(path)); + memset(repath,0,sizeof(repath)); + l = 0,ans = 0,flag = 0; + dfs(0,0); + if(flag == 0) printf("error\n"); + else if(flag == 2) printf("rejected\n"); + else + { + printf("%d",ans); + for(int i = 0 ;i < relen ; i++) + printf(" %d",repath[i]); + printf("\n"); + } + } + return 0; +} diff --git a/HDOJ/1540_autoAC.cpp b/HDOJ/1540_autoAC.cpp new file mode 100644 index 0000000..dd824a8 --- /dev/null +++ b/HDOJ/1540_autoAC.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +#define MAX 100010 +#define INF 0x6fffff +typedef struct Node{ + int start; + int end; + int l_space; + int r_space; + int m_space; +}Node; +Node arr[MAX*2]; +int top = -1; +int stack[MAX]; +int fa[MAX]; +void build(int k, int s, int e){ + arr[k].start = s; + arr[k].end = e; + arr[k].l_space = arr[k].r_space = arr[k].m_space = e - s + 1; + if(s == e){ + fa[s] = k; + return; + } + int mid = (s + e) >> 1; + build(k << 1, s, mid); + build((k << 1) + 1, mid + 1, e); +} +void update(int k){ + if(k == 1) + return; + int fa_i = k >> 1; + int b_l = fa_i << 1; + int b_r = b_l | 1; + arr[fa_i].m_space = max(max(arr[b_l].m_space, arr[b_r].m_space), arr[b_l].r_space + arr[b_r].l_space); + if(arr[b_l].l_space == arr[b_l].end - arr[b_l].start + 1) + arr[fa_i].l_space = arr[b_l].l_space + arr[b_r].l_space; + else + arr[fa_i].l_space = arr[b_l].l_space; + if(arr[b_r].r_space == arr[b_r].end - arr[b_r].start + 1){ + arr[fa_i].r_space = arr[b_l].r_space + arr[b_r].r_space; + } + else + arr[fa_i].r_space = arr[b_r].r_space; + update(fa_i); +} +int sum; +void query(int i, int x){ + if(arr[i].start == arr[i].end || arr[i].end - arr[i].start + 1 == arr[i].m_space || arr[i].m_space == 0){ + sum += arr[i].m_space; + return; + } + int mid = (arr[i].start + arr[i].end) >> 1; + if(x <= mid){ + if(x >= arr[i << 1].end - arr[i << 1].r_space + 1) + query((i << 1) + 1, mid + 1); + query(i << 1, x); + } else { + if(x <= arr[(i << 1) + 1].start + arr[(i << 1) + 1].l_space - 1) + query(i << 1, mid); + query((i << 1) + 1, x); + } +} +void dbg_show(){ + int max = 15; + for(int i = 1; i < max; ++i) + cout<>m>>n){ + build(1, 1, m); + //dbg_show(); + while(n--){ + cin>>ch; + switch(ch){ + case 'D': + cin>>dt; + arr[fa[dt]].l_space = arr[fa[dt]].r_space = arr[fa[dt]].m_space = 0; + update(fa[dt]); + stack[++top] = dt; + //dbg_show(); + break; + case 'R': + dt = stack[top--]; + arr[fa[dt]].l_space = arr[fa[dt]].r_space = arr[fa[dt]].m_space = 1; + update(fa[dt]); + break; + case 'Q': + cin>>dt; + sum = 0; + query(1, dt); + cout< +#include +using namespace std; +#define MAXN 320005 +int c[MAXN]; +int lowbit(int x) +{ + return x & -x; +} +int Sum(int n) +{ + int sum = 0; + while (n > 0) { + sum += c[n]; + n -= lowbit(n); + } + return sum; +} +void update(int i, int x) +{ + while (i<=MAXN) { + c[i] += x; + i += lowbit(i); + } +} +int ans[MAXN]; +int main() +{ + int n, x, y; + while (~scanf("%d", &n)) { + memset(c, 0, sizeof(c)); + memset(ans, 0, sizeof(ans)); + for (int i=0; i +#include +using namespace std; +double Y[1000]; +typedef struct +{ + double x,up,down; + int flag; +}node; +node N[1000]; +typedef struct +{ + double x,up,down; + int cover; + int flag; +}tree; +tree T[1000]; +bool cmp(node a,node b) +{ + return a.x=up) + return 0; + if(T[num].flag) + { + if(T[num].cover>0) + { + T[num].cover+=flag; + double xx=T[num].x; + T[num].x=x; + return (T[num].x-xx)*(T[num].up-T[num].down); + } + else + { + T[num].cover+=flag; + T[num].x=x; + return 0; + } + } + double s1=insert(x,down,up,flag,2*num); + double s2=insert(x,down,up,flag,2*num+1); + return s1+s2; +} +int main() +{ + int i,n,k,c_ase=1; + double x1,y1,x2,y2,area; + while(~scanf("%d",&n),n) + { + k=1,area=0; + for(i=1;i<=n;i++) + { + scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); + N[k].x=x1,N[k].up=y2,N[k].down=y1,N[k].flag=1,Y[k++]=y1; + N[k].x=x2,N[k].up=y2,N[k].down=y1,N[k].flag=-1,Y[k++]=y2; + } + sort(Y+1,Y+k); + sort(N+1,N+k,cmp); + buit(1,2*n,1); + for(i=1;i<=2*n;i++) + area+=insert(N[i].x,N[i].down,N[i].up,N[i].flag,1); + printf("Test case #%d\nTotal explored area: %.2lf\n",c_ase++,area); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1543_autoAC.cpp b/HDOJ/1543_autoAC.cpp new file mode 100644 index 0000000..0cf80ed --- /dev/null +++ b/HDOJ/1543_autoAC.cpp @@ -0,0 +1,9 @@ +(0,0) (0,W) +--------------- +| | +| | +| | +| | +| | +--------------- +(H,0) (H,W) diff --git a/HDOJ/1544_autoAC.cpp b/HDOJ/1544_autoAC.cpp new file mode 100644 index 0000000..cbc15e0 --- /dev/null +++ b/HDOJ/1544_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; +int main() +{ + string s; + while(cin>>s) + { + int count=0; + int i,l,r; + for(i=1;i=0&&r=0&&r +using namespace std; +__int64 dp[111][11][11]; +__int64 N,K,temp; +inline void init() +{ + memset(dp,0,sizeof(dp)); + dp[1][1][0]=1; + dp[1][0][1]=1; +} +void dpstart() +{ + init(); + for(int i=2;i<=N;i++) + { + for(int j=1;j<=K;j++) + { + dp[i][0][j]=dp[i-1][1][j-1]+dp[i-1][0][j-1]; + dp[i][j][0]=dp[i-1][j-1][1]+dp[i-1][j-1][0]; + } + for(int x=1;x>N>>K) + { + dpstart(); + } + return 0; +} diff --git a/HDOJ/1546_autoAC.cpp b/HDOJ/1546_autoAC.cpp new file mode 100644 index 0000000..243fec8 --- /dev/null +++ b/HDOJ/1546_autoAC.cpp @@ -0,0 +1,79 @@ +#include +#include +#define INF 1000000000 +#define maxn 1000 +struct idiom +{ + char front[5]; + char back[5]; + int T; +}; +idiom dic[maxn]; +int map[maxn][maxn]; +int dist[maxn]; +int vis[maxn]; +int N; +void dij() +{ + int i,j,k; + for(i=0; i +#include +using namespace std; +int dir[6][2]={-1,1,0,2,1,1,1,-1,0,-2,-1,-1}; +char mat[205][205]; +int n,m,x,y,maxx; +void dfs(int a,int b,char c) +{ + int p,q; + maxx++; + mat[a][b]=0; + for(int i=0;i<6;++i) + { + p=a+dir[i][0];q=b+dir[i][1]; + if(0<=a&&a<=n&&0<=b&&b<=m&&mat[p][q]) + { + if(mat[p][q]==c) + dfs(p,q,c); + if(c=='0') + dfs(p,q,c); + } + } +} +int main() +{ + int ans; + for(;~scanf("%d%d%d%d",&n,&m,&x,&y);) + { + memset(mat,0,sizeof(mat)); + ans=maxx=0; + for(int i=1;i<=n;++i) + scanf("%s",mat[i]); + for(int i=1;i<=n;i+=2) + for(int j=m-1;j>=0;--j) + { + if(mat[i][j]=='E') mat[i][j]=0; + mat[i][j*2+1]=mat[i][j]; + mat[i][j]=0; + } + for(int i=2;i<=n;i+=2) + for(int j=m-2;j>=0;--j) + { + if(mat[i][j]=='E') mat[i][j]=0; + mat[i][j*2+2]=mat[i][j]; + mat[i][j]=0; + } + m=2*m; + if(x&1) y=(y-1)*2+1; + else y=(y-1)*2+2; + dfs(x,y,mat[x][y]); + ans=maxx; + if(ans<3) + ans=0; + else + { + for(int i=1;i<=m;++i) + if(mat[1][i]) + dfs(1,i,'0'); + for(int i=1;i<=n;++i) + for(int j=1;j<=m;++j) + if(mat[i][j]) ans++; + } + printf("%d\n",ans); + } + return 0; +} diff --git a/HDOJ/1548_autoAC.cpp b/HDOJ/1548_autoAC.cpp new file mode 100644 index 0000000..497ec87 --- /dev/null +++ b/HDOJ/1548_autoAC.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#define maxn 200 + 10 +bool vis[maxn]; +int n, a, b,dis[maxn]; +using namespace std; +struct node +{ + int now; + int step; +}; +int bfs(int aa, int bb) +{ + queueq; + vis[aa] = 1; + node start,next; + start.now = aa; + start.step = 0; + q.push(start); + while (!q.empty()) + { + node s = q.front(); + q.pop(); + if (s.now == b) + { + return s.step; + } + for (int i = 0; i < 2; i++) + { + if(i==0) + next.now = s.now+dis[s.now]; + else + next.now = s.now-dis[s.now]; + if(!vis[next.now]&&next.now>=1&&next.now<=n) + { + if(next.now==b) + return s.step+1; + vis[next.now] = 1; + next.step = s.step+1; + q.push(next); + } + } + } + return -1; +} +int main() { + while (scanf("%d", &n) != EOF && n) + { + memset(vis, 0, sizeof(vis)); + cin >> a >> b; + for(int i = 1;i<=n;i++) + cin>>dis[i]; + int ans = bfs(a, 0); + cout< +#include +#include +#include +#include +#define nz 250001 +#define nz1 500 +using namespace std; +double sb[nz]; +double sum; +int a,b; +int cnm(double x) +{ + int cnt = 0; + for(int i = 0; i=b) return 1; + return 0; +} +int main() +{ + int c,d,e,f; + while(scanf("%d%d",&a,&b)&&(a||b)) + { + sum=0; + for(int y=0;y1e-10) + { + double mid; + mid=(r+l)/2.0; + if(cnm(mid)) + { + l=mid; + } + else + { + r=mid; + } + } + printf("%.2lf\n",l); + } + return 0; +} diff --git a/HDOJ/1554_autoAC.cpp b/HDOJ/1554_autoAC.cpp new file mode 100644 index 0000000..1605bc6 --- /dev/null +++ b/HDOJ/1554_autoAC.cpp @@ -0,0 +1,120 @@ +#include +int stack[1001]; +int snum; +int add(int x, int y, int z, int pre) +{ + int i, array[11]; + array[pre] = y; + for(i = 1; i < pre; i ++) + { + array[i] = z % 10; + z /= 10; + } + for(i = pre + 1; i <= 10; i ++) + { + array[i] = x % 10; + x /= 10; + } + stack[++ snum] = 0; + for(i = 10; i >= 1; i --) + { + stack[snum] *= 10; + stack[snum] += array[i]; + } + return 0; +} +int Max(int a, int b) +{ + return a > b ? a : b; +} +int find(int pre, int n) +{ + int i; + int flag = 1; + int max; + if(pre == 0) + return 0; + for(i = 1; i < pre; i ++) + flag *= 10; + if(pre != 1 && n % 2 == 0 || pre == 1) + { + max = Max(flag / 2, 1); + for(i = (n - n / flag * flag) / 2; i < flag; i += max) + { + if(i * 2 >= n) + break; + if((n - i * 2) < flag) + break; + if((n - i * 2) / flag % 11 != 10) + { + add((n - i * 2) / flag / 11, (n - i * 2) / flag % 11, i, pre); + } + } + } + return find(pre - 1, n); +} +int swap(int &a, int &b) +{ + a ^= b; + b ^= a; + a ^= b; + return 0; +} +int sort() +{ + int i, j; + for(i = 1; i < snum; i ++) + for(j = i + 1; j <= snum; j ++) + { + if(stack[i] == stack[j]) + { + stack[j] = stack[snum]; + snum --; + j --; + } + } + for(i = 1; i <= snum; i ++) + { + for(j = i + 1; j <= snum; j ++) + { + if(stack[i] > stack[j]) + { + swap(stack[i], stack[j]); + } + } + } + return 0; +} +int prin(int x, int n) +{ + int y = n - x, i; + int array[11], tail = 0; + printf("%d + ", x); + while(x >= 10) + { + array[++ tail] = y % 10; + y /= 10; + x /= 10; + } + for(i = tail; i >= 1; i --) + printf("%d", array[i]); + printf(" = %d\n", n); + return 0; +} +int main() +{ + int n; + int i; + while(scanf("%d", &n) != EOF) + { + snum = 0; + find(10, n); + sort(); + printf("%d\n", snum); + for(i = 1; i <= snum; i ++) + { + prin(stack[i], n); + } + } + return 0; +} diff --git a/HDOJ/1555_autoAC.cpp b/HDOJ/1555_autoAC.cpp new file mode 100644 index 0000000..4373030 --- /dev/null +++ b/HDOJ/1555_autoAC.cpp @@ -0,0 +1,17 @@ +#include +int main() +{ + int m,k; + while(scanf("%d%d",&m,&k)!=EOF&&m&&k) + { + int sum=0; + while(m-k>=0) + { + sum+=k; + m=m-k+1; + } + sum+=m; + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/1556_autoAC.cpp b/HDOJ/1556_autoAC.cpp new file mode 100644 index 0000000..2b794d7 --- /dev/null +++ b/HDOJ/1556_autoAC.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include +using namespace std; +const int inf=10000000; +int f[100005]; +int main(){ + int n; + while(scanf("%d",&n)!=EOF&&n){ + memset(f,0,sizeof(f)); + for(int i=0,a,b;i +#include +int main () +{ + int a[25],c1[5000],c2[5000]; + int i,j,k,n,m,t,s; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + for(m=0,i=1;i<=n;i++) + { + scanf("%d",&a[i]); + m+=a[i]; + } + for(int ii=1;ii<=n;ii++) + { + memset(c1,0,sizeof(c1)); + memset(c2,0,sizeof(c2)); + c1[0]=1; + for(i=1;i<=n;i++) + { + if(i==ii)continue; + for(j=0;j<=m/2;j++) + for(k=0;k+j<=m/2&&k<=a[i];k+=a[i]) + c2[k+j]+=c1[j]; + for(j=0;j<=m/2;j++) + c1[j]=c2[j],c2[j]=0; + } + for(s=0,i=m/2-a[ii]+1;i<=m/2;i++) + s+=c1[i]; + if(ii==1) + printf("%d",s); + else + printf(" %d",s); + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1558_autoAC.cpp b/HDOJ/1558_autoAC.cpp new file mode 100644 index 0000000..24a795e --- /dev/null +++ b/HDOJ/1558_autoAC.cpp @@ -0,0 +1,80 @@ +#include +using namespace std; +#define max_n 1010 +struct point +{ + double x, y; +}; +struct segment +{ + point s, e; +}; +double dir(point a, point b, point c) +{ + return a.x*b.y + b.x*c.y + c.x*a.y - a.x*c.y - c.x*b.y - b.x*a.y; +} +bool connected(point a, point b, point c, point d) +{ + if (dir(a, b, c)*dir(a, b, d) <= 0 && dir(d, c, a)*dir(d, c, b) <= 0)return 1; + return 0; +} +segment se[max_n]; +int par[max_n], r[max_n]; +int find(int x) +{ + if (x == par[x])return x; + else return par[x] = find(par[x]); +} +void unite(int x, int y) +{ + int a = find(x), b = find(y); + if (a != b) + { + if (r[a] < r[b])par[a] = b; + else par[b] = a; + if (r[a] == r[b])r[a]++; + } + return; +} +void inse(int n) +{ + bool ok = 1; + for (int j = 1; j < n; j++) + { + if (connected(se[j].s, se[j].e, se[n].s, se[n].e)) + unite(n, j); + } + return; +} +int main() +{ + int tes, k, n, m; char c; + cin >> tes; + while (tes--) + { + cin >> n; + k = 0; + for (int i = 1; i <= n; i++)par[i] = i, r[i] = 0; + for (int i = 1; i <= n; i++) + { + cin >> c; + if (c == 'P') + { + k++; + cin >> se[k].s.x >> se[k].s.y >> se[k].e.x >> se[k].e.y; + inse(k); + } + else + { + cin >> m; + int root = find(m), ans = 0; + for (int i = 1; i <= k; i++) + { + if (find(i) == root)ans++; + } + cout << ans << endl; + } + } + if(tes)cout << endl; + } +} diff --git a/HDOJ/1559_autoAC.cpp b/HDOJ/1559_autoAC.cpp new file mode 100644 index 0000000..b78c3c5 --- /dev/null +++ b/HDOJ/1559_autoAC.cpp @@ -0,0 +1,57 @@ +#include +#include +#define INF 0x3f3f3f +#define MAX 1000+10 +int map[MAX][MAX]; +int dp[MAX][MAX]; +int max(int x,int y) +{ + return x>y?x:y; +} +int main() +{ + int t,n,m,x,y,k,l; + int i,j,sum,maxsum,s; + scanf("%d",&t); + while(t--) + { + scanf("%d%d%d%d",&n,&m,&x,&y); + memset(dp,0,sizeof(dp)); + for(i=1;i<=n;i++) + { + for(j=1;j<=m;j++) + { + scanf("%d",&map[i][j]); + if(i==1) + dp[i][j]=map[i][j]; + else + dp[i][j]=map[i][j]+dp[i-1][j]; + } + } + maxsum=-INF; + for(i=1;i<=n;i++) + { + for(j=i;j<=n;j++) + { + if(j-i+1!=x) + continue; + for(k=1;k<=m;k++) + { + sum=dp[j][k]-dp[i-1][k]; + s=0; + for(l=k;lsum) + sum=s; + if(s<0) + s=0; + } + maxsum=max(sum,maxsum); + } + } + } + printf("%d\n",maxsum); + } + return 0; +} diff --git a/HDOJ/1560_autoAC.cpp b/HDOJ/1560_autoAC.cpp new file mode 100644 index 0000000..0f50ec3 --- /dev/null +++ b/HDOJ/1560_autoAC.cpp @@ -0,0 +1,76 @@ +#include +#include +#include +#include +using namespace std; +int n,deep; +char c[10] = "ACGT"; +struct node +{ + char s[10]; + int len; +} a[10]; +int pos[10]; +int get_h() +{ + int ans = 0; + for(int i = 1; i<=n; i++) + ans = max(ans,a[i].len-pos[i]); + return ans; +} +int dfs(int step) +{ + if(step+get_h()>deep) + return 0; + if(!get_h()) + return 1; + int i,j; + int tem[10]; + for(i = 0; i<4; i++) + { + int flag = 0; + for(j = 1; j<=n; j++) + tem[j] = pos[j]; + for(j = 1; j<=n; j++) + { + if(a[j].s[pos[j]] == c[i]) + { + flag = 1; + pos[j]++; + } + } + if(flag) + { + if(dfs(step+1)) + return 1; + for(j = 1; j<=n; j++) + pos[j] = tem[j]; + } + } + return 0; +} +int main() +{ + int t,i,j,maxn; + cin >> t; + while(t--) + { + cin>>n; + maxn = 0; + for(i = 1; i<=n; i++) + { + cin>>a[i].s; + a[i].len = strlen(a[i].s); + maxn = max(maxn,a[i].len); + pos[i] = 0; + } + deep = maxn; + while(1) + { + if(dfs(0))break; + deep++; + } + cout << deep << endl; + } + return 0; +} diff --git a/HDOJ/1561_autoAC.cpp b/HDOJ/1561_autoAC.cpp new file mode 100644 index 0000000..b5291d8 --- /dev/null +++ b/HDOJ/1561_autoAC.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include +using namespace std; +int N,M; +bool vis[205]; +int val[205]; +int dp[205][205]; +vector map[205]; +void dfs(int s) +{ + for(int i=1;i<=M;i++)dp[s][i] = val[s]; + vis[s]=1; + for(int i=0;i=0 ;j--)//m == 2 + for(k=1;k<=j ;k++) + dp[s][j] = max(dp[s][j],dp[s][j-k]+dp[t][k]); + } + else + { + for(j=M;j>=1 ;j--)//m == 2 + for(k=1;k +int main() +{ + int i,a,b,c,n; + scanf("%d",&n); + while(n--) + { + scanf("%d%d%d",&a,&b,&c); + for(i=1000;i<=9999;i++) + { + if(i%a==0&&(i+1)%b==0&&(i+2)%c==0)break; + } + if(i>9999)printf("Impossible\n"); + else printf("%d\n",i); + } + return 0; +} diff --git a/HDOJ/1563_autoAC.cpp b/HDOJ/1563_autoAC.cpp new file mode 100644 index 0000000..40c8af2 --- /dev/null +++ b/HDOJ/1563_autoAC.cpp @@ -0,0 +1,17 @@ +#include +int main() +{ + int n,m,x; + while(scanf("%d",&n)!=EOF&&n) + { + x=0; + while(n--) + { + scanf("%d",&m); + if(x +int main() +{ + int i; + scanf("%d",&i); + if(i!=0) + { + while(i!=0) + { + if(i%2==0) + printf("8600\n"); + else + printf("ailyanlu\n"); + scanf("%d",&i); + } + } + return 0; +} diff --git a/HDOJ/1565_autoAC.cpp b/HDOJ/1565_autoAC.cpp new file mode 100644 index 0000000..557c300 --- /dev/null +++ b/HDOJ/1565_autoAC.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; +const int Max = 25; +int num[Max][Max]; +int s[20000]; +int dp[Max][20000]; +void get_s() +{ + int cnt = 0; + for (int i=0;i<(1<<20);++i) + if ( ( i&(i<<1) )==0) + s[cnt++] = i; +} +int main() +{ + get_s(); + int n; + while (cin>>n) + { + for (int i=0;i>num[i][j]; + memset(dp,0,sizeof(dp)); + for (int i=0;i>k)&1)==1 ) + dp[i][j] += num[i][k]; + if (i) + { + int mx = 0; + for (int k=0;s[k]<(1<mx ) + mx = dp[i-1][k]; + dp[i][j] += mx; + } + } + } + int ans = 0; + for (int i=0;s[i]<(1<ans?dp[n-1][i]:ans; + cout< +short last[60],an[60],temp[60]; +short a[60][4]; +void mult(short *a,short *b,short *c) +{ + int i,j,m,n,k; + if(a[0]==1&&a[1]==0||b[0]==1&&b[1]==0) + { + c[0]=1;c[1]=0;return; + } + m=a[0];n=b[0]; + k=n+m-1; + for(i=0;i<=k;i++)c[i]=0; + for(i=1;i<=m;i++) { + if(a[i])for(j=1;j<=n;j++)if(b[j])c[i+j-1]+=a[i]*b[j]; + } + for(i=k;i>=1;i--)if(c[i]>9){ c[i-1]+=c[i]/10;c[i]%=10;} + if(c[0]>0) + {k++; for(i=k;i>=1;i--)c[i]=c[i-1]; }c[0]=k; +} +void dectoB(int sum,int b,short *S) +{ + int i,j,k=0,t,d[20]; + while(sum>0) { d[++k]=sum%b; sum/=b; } + S[0]=k; + for(i=1,j=k;i<=k;i++,j--) {S[i]=d[j];} +} +void copy(short *a,short *b) +{ + int i; + for(i=0;i<=b[0];i++) + a[i]=b[i]; +} +void answer() +{ + int i; + printf("%d",an[0]); + last[0]=1;last[1]=1; + for(i=1;i<=an[0];i++) + { + printf(" %d",an[i]); + mult(last,a[an[i]],temp); + copy(last,temp); + } + printf("\n"); + for(i=1;i<=last[0];i++) + printf("%d",last[i]); + printf("\n"); +} +int main() +{ + int i,sum,n,res; + for(i=1;i<=50;i++) + dectoB(i,10,a[i]); + while(scanf("%d",&n)!=EOF) + { + if(n<5) {printf("2 1 %d\n%d\n",n-1,n-1);continue;} + an[0]=0;sum=0; + for(i=2;i<=50;i++) + { + if(sum+i>n) break; + sum+=i; + an[++an[0]]=i; + } + res=n-sum; + if(res) + { + while(1) + { + for(i=an[0];i>=1;i--) + {an[i]++;res--;if(res==0) goto loop;} + } + } + loop: answer(); + } + return 0; +} diff --git a/HDOJ/1567_autoAC.cpp b/HDOJ/1567_autoAC.cpp new file mode 100644 index 0000000..3615dc9 --- /dev/null +++ b/HDOJ/1567_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +using namespace std; +bool vis[2010]; +int num[2010]; +int main(){ + int n; + int t1,t2; + bool flag; + char a[7000]; + while(~scanf("%d",&n)){ + memset(num,0,sizeof(num)); + flag=1; + for(int i=1;i<=n-1;i++){ + memset(vis,0,sizeof(vis)); + for(int j=1;j<=n/2;j++){ + scanf("%d-%d",&t1,&t2); + if(vis[t1]||vis[t2]){ + flag=0; + } + vis[t1]=1; + vis[t2]=1; + num[t1]++; + num[t2]++; + } + } + if(flag){ + for(int i=1;i<=n;i++){ + if(num[i]!=n-1){ + flag=0; + break; + } + } + } + if(flag) + cout<<"Yes"< +#include +#include +using namespace std; +const double s = (sqrt(5.0)+1.0)/2; +int main() +{ + int n,i; + double bit; + int fac[21] = { 0 , 1 }; + for(i = 2; i < 21; i++) + fac[i] = fac[i-1] + fac [i-2]; + while(cin >> n) + { + if(n <= 20) { + cout << fac[n] << endl; + continue; + } + else{ + bit = -0.5*log(5.0)/log(10.0)+((double)n)*log(s)/log(10.0); + bit = bit - floor(bit); + bit = pow(10.0,bit); + while(bit < 1000) + bit = 10.0 * bit; + cout << (int)bit << endl; + } + } + return 0; +} diff --git a/HDOJ/1569_autoAC.cpp b/HDOJ/1569_autoAC.cpp new file mode 100644 index 0000000..f7569d5 --- /dev/null +++ b/HDOJ/1569_autoAC.cpp @@ -0,0 +1,99 @@ +#include +#include +#include +#include +#include +#include +#define MAXN 3005 +#define MAXM 500005 +#define oo 1000000007 +#define ll long long +using namespace std; +struct Dinic +{ + struct node + { + int x,y,c,next; + }line[MAXM]; + int Lnum,_next[MAXN],dis[MAXN]; + void initial(int n) + { + for (int i=0;i<=n;i++) _next[i]=-1; + Lnum=-1; + } + void addline(int x,int y,int c) + { + line[++Lnum].next=_next[x],_next[x]=Lnum; + line[Lnum].x=x,line[Lnum].y=y,line[Lnum].c=c; + line[++Lnum].next=_next[y],_next[y]=Lnum; + line[Lnum].x=y,line[Lnum].y=x,line[Lnum].c=0; + } + bool BFS(int s,int e) + { + queue Q; + while (!Q.empty()) Q.pop(); + memset(dis,0,sizeof(dis)); + dis[s]=1; + Q.push(s); + while (!Q.empty()) + { + int h,k; + h=Q.front(),Q.pop(); + if (h==e) return dis[e]; + for (k=_next[h];k!=-1;k=line[k].next) + if (line[k].c && !dis[line[k].y]) + dis[line[k].y]=dis[h]+1,Q.push(line[k].y); + } + return false; + } + int dfs(int x,int flow,int e) + { + if (x==e) return flow; + int temp,cost=0; + for (int k=_next[x];k!=-1;k=line[k].next) + if (line[k].c && dis[line[k].y]==dis[x]+1) + { + temp=dfs(line[k].y,min(flow-cost,line[k].c),e); + if (temp) + { + line[k].c-=temp,line[k^1].c+=temp; + cost+=temp; + if (flow==cost) return cost; + }else dis[line[k].y]=-1; + } + return cost; + } + int MaxFlow(int s,int e) + { + int MaxFlow=0; + while (BFS(s,e)) + MaxFlow+=dfs(s,oo,e); + return MaxFlow; + } +}T; +int main() +{ + int R,C,i,j,s,e,v,sum; + while (~scanf("%d%d",&R,&C)) + { + T.initial(R*C+5); + s=R*C+1,e=R*C+2,sum=0; + for (i=0;i +int jc(int n) +{ + int i,t=1; + if(n==0) return 1; + for(i=n;i>0;i--) t *= i; + return t; +} +int main() +{ + int k,t,n,m; + char lt; + scanf("%d",&t); + while(t--) + { + scanf(" %c%d%d",<,&n,&m); + if(lt=='A') k = jc(n)/jc(n-m); + else k = jc(n)/(jc(m)*jc(n-m)); + printf("%d\n",k); + } + return 0; +} diff --git a/HDOJ/1571_autoAC.cpp b/HDOJ/1571_autoAC.cpp new file mode 100644 index 0000000..07f8260 --- /dev/null +++ b/HDOJ/1571_autoAC.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +using namespace std; +int i,j,n,t,dist,pep,stat; +int way[35][35]; +char req[5]; +struct passeger +{ + int end; + passeger *next; +}*p1,*p2; +void UP() +{ + int k; + scanf("%d",&k); + if(stat==k||pep==7)return ; + if(p1==NULL){p1=new passeger;p1->end=k;p2=p1;pep++;p1->next=NULL;} + else{p2->next=new passeger;p2=p2->next;p2->end=k;pep++;p2->next=NULL;} +} +void GO() +{ + int k,z; + passeger *p,*q,*r; + if(!pep)return ; + k=p1->end; + z=pep; + p=p1; + while(z--) + { + if(p->end==k) + { + if(p==p1) + { + p1=p->next; + delete p; + p=p1; + pep--; + } + else + { + r=q->next; + q->next=p->next; + delete r; + p=q->next; + pep--; + } + } + else q=p,p=p->next; + } + dist+=way[stat][k]; + stat=k; + if(pep) + { + p=p1; + while(p->next!=NULL) + { + p=p->next; + } + p2=p; + } + else p1=p2=NULL; +} +int main() +{ + while(scanf("%d",&n),n) + { + dist=0,stat=0,pep=0; + p1=p2=NULL; + for(i=0;inext; + delete p1; + p1=p2; + } + } + return 0; +} diff --git a/HDOJ/1572_autoAC.cpp b/HDOJ/1572_autoAC.cpp new file mode 100644 index 0000000..9412053 --- /dev/null +++ b/HDOJ/1572_autoAC.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +using namespace std; +#define MAXN 33 +#define inf 1<<30 +int map[MAXN][MAXN]; +int n,MIN,k; +int num[MAXN]; +bool mark[MAXN]; +void dfs(int start,int count,int dist){ + if(count==k){ + MIN=min(dist,MIN); + return ; + } + for(int i=1;i<=k;i++){ + if(!mark[i]){ + mark[i]=true; + dfs(num[i],count+1,dist+map[start][num[i]]); + mark[i]=false; + } + } +} +int main(){ + int _case; + while(~scanf("%d",&n)&&n){ + for(int i=0;i +#include +#include +typedef __int64 ll; +ll n,k; +ll m[15],c[15],N; +bool check; +ll exgcd(ll a,ll b,ll &x,ll &y) +{ + if(!b) + { + x=1; + y=0; + return a; + } + else + { + ll res=exgcd(b,a%b,x,y); + ll t=x; + x=y; + y=t-(a/b)*y; + return res; + } +} +ll mod(ll x,ll y) +{ + ll res=x%y; + if(res<=0) + res=res+y; + return res; +} +void solve() +{ + ll i; + check=true; + ll ans=c[1],lcm=m[1],x,y,g; + if(ans==0) + ans=m[1]; + for(i=2;i<=n;i++) + { + g=exgcd(lcm,m[i],x,y); + if((c[i]-ans)%g) + { + check=false; + break; + } + ans=mod(ans+lcm*mod((c[i]-ans)/g*x,m[i]/g),lcm/g*m[i]); + lcm=lcm/g*m[i]; + } + if(check) + { + if(N>=ans) + { + printf("%I64d\n",(N-ans)/lcm+1); + } + else + { + printf("0\n"); + } + } + else + { + printf("0\n"); + } +} +int main() +{ + ll i,t; + scanf("%I64d",&t); + while(t--) + { + scanf("%I64d%I64d",&N,&n); + for(i=1;i<=n;i++) + scanf("%I64d",&m[i]); + for(i=1;i<=n;i++) + scanf("%I64d",&c[i]); + solve(); + } + return 0; +} diff --git a/HDOJ/1574_autoAC.cpp b/HDOJ/1574_autoAC.cpp new file mode 100644 index 0000000..9cad416 --- /dev/null +++ b/HDOJ/1574_autoAC.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +using namespace std; +const int maxa=21000; +const int maxn=1002; +int a[maxn]; +int b[maxn]; +int c[maxn]; +int p[maxa]; +int N,l,r; +void dp() +{ + for(int i=0;i0) + { + for(int j=b[i];j>=l;--j) + if(p[j]!=INT_MIN) + p[j+a[i]]=max(p[j+a[i]],p[j]+c[i]); + r+=a[i]; + } + else if(a[i]<0) + { + for(int j=b[i];j<=r;++j) + if(p[j]!=INT_MIN) + p[j+a[i]]=max(p[j+a[i]],p[j]+c[i]); + l+=a[i]; + } + } +} +int main() +{ + int T; + cin>>T; + while(T--) + { + cin>>N; + for(int i=0;i>a[i]>>b[i]>>c[i]; + b[i]+=10000; + } + dp(); + cout<<*max_element(p,p+maxa)< +#include +#include +#include +#include +const int MAX=101; +int n; +using namespace std; +typedef struct Matrix +{ + int mat[MAX][MAX]; +}matrix; +matrix A,B; +Matrix matrix_mul(matrix a,matrix b) +{ + matrix c; + memset(c.mat,0,sizeof(c.mat)); + int i,j,k; + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + for(k=1;k<=n;k++) + { + c.mat[i][j]+=a.mat[i][k]*b.mat[k][j]; + c.mat[i][j]%=9973; + } + } + } + return c; +} +Matrix matrix_quick_power(matrix a,int k) +{ + int i; + matrix b; + memset(b.mat,0,sizeof(b.mat)); + for(i=1;i<=n;i++) + b.mat[i][i]=1; + while(k) + { + if(k&1) + { + b=matrix_mul(a,b); + k-=1; + } + else + { + a=matrix_mul(a,a); + k>>=1; + } + } + return b; +} +int main() +{ + int i,j,sum,k,t; + cin>>t; + while(t--) + { + cin>>n>>k; + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + cin>>A.mat[i][j]; + A.mat[i][j]%=9973; + } + } + B=matrix_quick_power(A,k); + sum=0; + for(i=1;i<=n;i++) + { + sum+=B.mat[i][i]; + sum%=9973; + } + cout< +int main() +{ + int T,n,i; + long long int B; + scanf("%d",&T); + while(T--) + { + scanf("%d%lld",&n,&B); + for(i=0;i<=10000;i++) + if((B*i-n)%9973==0) break; + printf("%d\n",i); + } + return 0; + } diff --git a/HDOJ/1577_autoAC.cpp b/HDOJ/1577_autoAC.cpp new file mode 100644 index 0000000..cf2ed16 --- /dev/null +++ b/HDOJ/1577_autoAC.cpp @@ -0,0 +1,58 @@ +#include +using namespace std; +int main() +{ + int len; + double x1,y1,x2,y2; + while(cin>>len) + { + if(len==0) + break; + cin>>x1>>y1>>x2>>y2; + if(x2>len||y2>len||(-x2)>len||(-y2)>len) + cout<<"Out Of Range"<1.0||y2-y1>1.0) + flag=1; + else + { + flag=0; + } + } + else if(y1==y2) + { + if(x1-x2>1.0||x2-x1>1.0) + flag=1; + else + { + flag=0; + } + } + else + { + double k=(y2-y1)*1.0/(x2*1.0-x1*1.0); + double b=y1*1.0-k*x1; + double minx=x1>x2?x2:x1; + double maxx=x1>x2?x1:x2; + for(double i=minx+1;i + #include + #include + #include + using namespace std; + #define CLR(x) memset(x, 0, sizeof(x)) + int n, m; + int d[505][505][2]; + int x[505][505][2]; + int nor[505][505], wes[505][505]; + void init() + { + for (int t = 0; t < 2; ++ t) + for (int i = 0; i < n; ++ i) + for (int j = 0; j < m; ++ j) + scanf ("%d", &x[i][j][t]); + CLR (nor); CLR (wes); + for (int i = 0; i < n; ++ i) + for (int j = 0; j < m; ++ j){ + wes[i][j] = (j ? x[i][j][0]+wes[i][j-1] : x[i][j][0]); + nor[i][j] = (i ? x[i][j][1]+nor[i-1][j] : x[i][j][1]); + } + } + int DP() + { + CLR (d); + d[0][0][0] = x[0][0][0]; d[0][0][1] = x[0][0][1]; + for (int i = 0; i < n; ++ i) + for (int j = 0; j < m; ++ j){ + if (!i && !j) continue; + d[i][j][0] = wes[i][j]; + if (i) + d[i][j][0] += max(d[i-1][j][0], d[i-1][j][1]); + d[i][j][1] = nor[i][j]; + if (j) + d[i][j][1] += max(d[i][j-1][0], d[i][j-1][1]); + } + return max(d[n-1][m-1][0], d[n-1][m-1][1]); + } + int main() + { + while (scanf ("%d%d", &n, &m) != EOF && n){ + init(); + printf ("%d\n", DP()); + } + return 0; + } diff --git a/HDOJ/1579_autoAC.cpp b/HDOJ/1579_autoAC.cpp new file mode 100644 index 0000000..28d6e2e --- /dev/null +++ b/HDOJ/1579_autoAC.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +using namespace std; +int w[23][23][23]; +int get(int i,int j,int k) +{ + if(w[i][j][k]!=-1) + return w[i][j][k]; + if(i<=0||j<=0||k<=0) return 1; + if(i>=20||j>=20||k>=20) return 1048576; + if(i>a>>b>>c) + { + if(a==-1&&b==-1&&c==-1) break; + printf("w(%d, %d, %d) = ",a,b,c); + if(a<=0||b<=0||c<=0) printf("%d\n",w[0][0][0]); + else if(a>20||b>20||c>20) printf("%d\n",w[20][20][20]); + else + printf("%d\n",w[a][b][c]); + } + return 0; +} diff --git a/HDOJ/1580_autoAC.cpp b/HDOJ/1580_autoAC.cpp new file mode 100644 index 0000000..b51bd5f --- /dev/null +++ b/HDOJ/1580_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define ll long long +#define eps 1e-7 +#define inf 0xfffffff +const ll INF = 1ll<<61; +using namespace std; +int n,k; +int dp[10 + 5][1000 + 5]; +int travel[10 + 5][1000 + 5]; +int cost[10 + 5][10 + 5][1000 + 5]; +void clear() { + memset(dp,-1,sizeof(dp)); + memset(travel,0,sizeof(travel)); + memset(cost,0,sizeof(cost)); +} +int main() { + int Case = 0; + while(scanf("%d %d",&n,&k),n + k) { + clear(); + for(int i=1;i<=n;i++) { + for(int j=1;j<=n;j++) { + if(i != j) { + scanf("%d",&travel[i][j]); + for(int l=0;l dp[l][j - 1] + cost[l][i][tmp]) + minn = dp[l][j - 1] + cost[l][i][tmp]; + } + dp[i][j] = minn; + } + } + printf("Scenario #%d\n",++Case); + if(dp[n][k] < 0) + printf("No flight possible.\n\n"); + else + printf("The best flight costs %d.\n\n",dp[n][k]); + } + return 0; +} diff --git a/HDOJ/1581_autoAC.cpp b/HDOJ/1581_autoAC.cpp new file mode 100644 index 0000000..afe9be3 --- /dev/null +++ b/HDOJ/1581_autoAC.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include +using namespace std; +int dp[524289]; +int get_solve(int state,int x) +{ + int ret=state; + for(int i=x;i<=20;i+=x) + ret&=~(1<<(i-2)); + for(int i=2;i<=20;i++) + { + if(ret&(1<<(i-2))) + for(int j=x;i-j-2>=0;j+=x) + { + if(!(ret&(1<<(i-j-2)))) + { + ret&=~(1<<(i-2)); + break; + } + } + } + return ret; +} +int dfs(int state) +{ + if(dp[state]!=-1) return dp[state]; + for(int i=2;i<=20;i++) + { + if(state&(1<<(i-2))) + { + if(dfs(get_solve(state,i))==0) + return dp[state]=1; + } + } + return dp[state]=0; +} +int main() +{ + int t,n,a[21]; + int count=1; + memset(dp,-1,sizeof(dp)); + dp[0]=0; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + int state=0; + for(int i=0;i +using namespace std; +char mp[60][60]; +int num; +void bfs(int x,int y) +{ + if(x<0||x>51||y<0||y>51) return; + if('*'==mp[x][y]) return; + mp[x][y]='*'; + bfs(x-1,y); + bfs(x,y-1); bfs(x,y+1); + bfs(x+1,y); +} +bool readin() +{ + bool flag=1; + int i,j,n; + char temp; + for(i=0;i<=51;i++) + for(j=0;j<=51;j++) + mp[i][j]=' '; + if(scanf("%c",&temp)==EOF) return 0; + else mp[1][1]=temp; + for(j=2;scanf("%c",&temp)&&temp!=10;mp[1][j++]=temp); + for(n=2;j!=1;n++) + for(j=1;scanf("%c",&temp)&&temp!=10;mp[n][j++]=temp); + return 1; +} +int main() +{ + int i,j,k,n; + char temp; + while(readin()) + { + for(num=0,i=0;i<=51;i++) + for(j=0;j<=51;j++) + if(' '==mp[i][j]) + { + num++; + bfs(i,j); + } + printf("%c\n",num==2?'A':'C'); + } + return 0; +} diff --git a/HDOJ/1583_autoAC.cpp b/HDOJ/1583_autoAC.cpp new file mode 100644 index 0000000..585e8c9 --- /dev/null +++ b/HDOJ/1583_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +using namespace std; +string str_merge(string a, string b) +{ + if (a == "") + { + return b; + } + int i; + int flag = 0; + int pos; + int alen = a.length(); + int blen = b.length(); + for (i = 1; i <= alen; i++) + { + if (b.substr(0, i) == a.substr(alen - i, i)) + { + flag = 1; + pos = i; + } + } + if (flag) + { + return a + b.substr(pos, blen - pos); + } + else + { + return a + b; + } +} +int main() +{ + int n; + int ans; + int d[10]; + string str[10]; + string a; + while (cin >> n) + { + int i; + for (i = 0; i < n; i++) + { + cin >> str[i]; + d[i] = i; + } + ans = 1000; + do + { + string total = ""; + for (i = 0; i < n; i++) + { + total = str_merge(total, str[d[i]]); + } + if (total.length() < ans) + { + ans = total.length(); + a = total; + } + } while (next_permutation(d, d + n)); + cout << ans << endl; + } + return 0; +} diff --git a/HDOJ/1584_autoAC.cpp b/HDOJ/1584_autoAC.cpp new file mode 100644 index 0000000..03c911c --- /dev/null +++ b/HDOJ/1584_autoAC.cpp @@ -0,0 +1,62 @@ +#include +int a[10][2]; +int s,min; +int abs(int i,int j) +{ + i-=j; + if(i>0) return i; + else return -i; +} +void DFS() +{ + int i,j,flog=0; + int i0,i1,j0,j1; + for(i=0;i<10;i++) + { + if(a[i][0]!=-1&&a[i][0]!=10) + { + flog=1; + for(j=0;j<10;j++) + { + if(a[j][1]==a[i][0]&&s+abs(i,j)s) min=s; + } +} +int main() +{ + int n,i; + scanf("%d",&n); + while(n--) + { + for(i=0;i<10;i++) + { + scanf("%d",&a[i][0]); + a[i][1]=a[i][0]-1; + } + min=99999; + s=0; + DFS(); + printf("%d\n",min); + } + return 0; +} diff --git a/HDOJ/1587_autoAC.cpp b/HDOJ/1587_autoAC.cpp new file mode 100644 index 0000000..7835313 --- /dev/null +++ b/HDOJ/1587_autoAC.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +using namespace std; +int main() +{ + int n,m; + while(cin>>n>>m) + { + vector v; + int t; + while(n--) + { + cin>>t; + v.push_back(t); + } + sort(v.begin(),v.end()); + cout<<(m/v[0])< +#include +#include +using namespace std; +int k,b,n,m; +struct Matrix { + __int64 map[2][2]; +}; +Matrix matrix,matk,matb,smat; +Matrix Mul(Matrix &a,Matrix &b){ + Matrix c; + for(int i=0;i<2;i++){ + for(int j=0;j<2;j++){ + c.map[i][j]=0; + for(int k=0;k<2;k++){ + c.map[i][j]+=a.map[i][k]*b.map[k][j]; + c.map[i][j]%=m; + } + } + } + return c; +} +Matrix Pow(int k,Matrix &temp){ + if(k==1)return temp; + else if(k&1){ + return Mul(temp,Pow(k-1,temp)); + }else { + Matrix tmp=Pow(k>>1,temp); + return Mul(tmp,tmp); + } +} +Matrix Sum(Matrix &a,Matrix &b){ + Matrix c; + for(int i=0;i<2;i++){ + for(int j=0;j<2;j++){ + c.map[i][j]=a.map[i][j]+b.map[i][j]; + c.map[i][j]%=m; + } + } + return c; +} +Matrix Binary_Sum(int k){ + if(k==1)return matk; + else if(k&1){ + return Sum(Binary_Sum(k-1),Pow(k,matk)); + }else { + Matrix tmp1=Binary_Sum(k>>1); + Matrix tmp2=Mul(Pow(k>>1,matk),tmp1); + return Sum(tmp1,tmp2); + } +} +int main(){ + matrix.map[0][0]=1,matrix.map[0][1]=1; + matrix.map[1][0]=1,matrix.map[1][1]=0; + while(scanf("%d%d%d%d",&k,&b,&n,&m)!=EOF){ + matk=Pow(k,matrix); + smat=Binary_Sum(n-1); + if(b){ + matb=Pow(b,matrix); + smat=Mul(matb,smat); + smat=Sum(matb,smat); + } + printf("%I64d\n",smat.map[1][0]); + } + return 0; +} diff --git a/HDOJ/1589_autoAC.cpp b/HDOJ/1589_autoAC.cpp new file mode 100644 index 0000000..dc13177 --- /dev/null +++ b/HDOJ/1589_autoAC.cpp @@ -0,0 +1,162 @@ +#include +#include +#include +#include +using namespace std; +const int M=50005; +typedef struct Point +{ +double x; +double y; +}Point; +Point p[M]; +Point pp[M]; +bool bo[M]; +int stack[M]; +double dis(Point A,Point B) +{ +return sqrt((B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y)); +} +bool cmp(Point a,Point b) +{ +if(a.xb.x) + return false; +if(a.y1&&p[i].x==p[i-1].x&&p[i].y==p[i-1].y) + continue; + p[++t]=p[i]; +} +n=t; +t=0; +memset(bo+1,true,n*sizeof(bo[0])); +if(n>0) +{ + stack[++t]=1; + bo[stack[t]]=false; +} +if(n>1) +{ + stack[++t]=2; + bo[stack[t]]=false; +} +if(n>2) +{ + for(i=3;i=0) + { + stack[++t]=i; + bo[i]=false; + } + else + { + while(t>=2&&Xdet(p[stack[t-1]],p[stack[t]],p[i])<0) + { + bo[stack[t]]=true; + t--; + } + stack[++t]=i; + bo[stack[t]]=false; + } + for(i=n;i>=1;i--) + if(bo[i]&&Xdet(p[stack[t-1]],p[stack[t]],p[i])>=0) + { + stack[++t]=i; + bo[i]=false; + } + else + { + while(t>=2&&Xdet(p[stack[t-1]],p[stack[t]],p[i])<0) + { + bo[stack[t]]=true; + t--; + } + stack[++t]=i; + bo[stack[t]]=false; + } + t--; +} +for(i=1;i<=t;i++) + pp[i]=p[stack[i]]; +memcpy(p+1,pp+1,t*sizeof(Point)); +n=t; +} +int n,o[M],on; +int dcmp(double a,double b) +{ + if(a-b<1e-10&&b-a<1e-10) + return 0; + if(a>b) + return 1; + return -1; +} +bool cmp1(const Point &a,Point &b) +{ + return dcmp(a.x,b.x)<0; +} +bool cmp2(const int&a,const int&b) +{ + return dcmp(p[a].y,p[b].y)<0; +} +double min(double a,double b) +{ + return a=t) + return ret; + for(i=mid;i>=s&&!dcmp(p[i].x,p[mid].x);i--);ret=search(s,i); + for(i=mid;i<=t&&!dcmp(p[i].x,p[mid].x);i++);ret=min(ret,search(i,t));on=0; + for(i=mid;i>=s&&dcmp(p[mid].x-p[i].x,ret)<=0;i--)o[++on]=i; + for(i=mid+1;i<=t&&dcmp(p[i].x-p[mid].x,ret)<=0;i++)o[++on]=i; + sort(o+1,o+on+1,cmp2); + for(i=1;i<=on;i++) + for(j=1;j<=10;j++) + if(i+j<=on) + ret=min(ret,dis(p[o[i]],p[o[i+j]])); + return ret; +} +int main() +{ + int n,i,count=0,j; + double shortdis,longdis; + while(scanf("%d",&n),n) + { + for(i=1;i<=n;i++) + scanf("%lf%lf",&p[i].x,&p[i].y); + sort(p+1,p+n+1,cmp1); + shortdis=search(1,n); + longdis=0; + Gram_Scan(p,n); + for(i=1;i<=n-1;i++) + for(j=i+1;j<=n;j++) + if(dis(p[i],p[j])>longdis) + longdis=dis(p[i],p[j]); + printf("Case %d:\n",++count); + printf("Distance of the nearest couple is %.3lf\n",shortdis); + printf("Distance of the most distant couple is %.3lf\n\n",longdis); + } + return 0; +} diff --git a/HDOJ/1590_autoAC.cpp b/HDOJ/1590_autoAC.cpp new file mode 100644 index 0000000..42fb7bd --- /dev/null +++ b/HDOJ/1590_autoAC.cpp @@ -0,0 +1,16 @@ +#include +#include +const double EPS = 10e-6; +int main() { + double a, b, r, x, y, A, k, c, d; + while(scanf("%lf %lf %lf %lf", &x, &y, &A, &k) != EOF) { + A = A * acos(-1)/180.0; + a = 1.0 - k * cos(A); + b = -k * sin(A); + c = x * a + y * b; + d = y * a - x * b; + r = a * a + b * b; + printf("(%.3lf,%.3lf)\n", c/r+EPS, d/r+EPS); + } + return 0; +} diff --git a/HDOJ/1591_autoAC.cpp b/HDOJ/1591_autoAC.cpp new file mode 100644 index 0000000..686bcde --- /dev/null +++ b/HDOJ/1591_autoAC.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +using namespace std; +int main() +{ + string lib; + cin >> lib; + for(char c = 'Z'; c >= 'A'; --c) + {if(lib.find(c) == string::npos){lib += c;}} + string line; + cin.ignore(1); + while(getline(cin , line)) + { + for(size_ i = 0; i < line.size(); ++i) + { + if(isupper(line[i])) + {line[i] = 'A' + lib.find(line[i]);} + else if(islower((line[i]))) + {line[i] = 'a' + lib.find(toupper(line[i]));} + } + cout << line << endl; + } + return 0; +} diff --git a/HDOJ/1592_autoAC.cpp b/HDOJ/1592_autoAC.cpp new file mode 100644 index 0000000..bc8327e --- /dev/null +++ b/HDOJ/1592_autoAC.cpp @@ -0,0 +1,38 @@ +#include +#include +int num[1010][1010]; +int main() +{ + int i,n,j; + memset(num,0,sizeof(num)); + num[0][1]=1; + for(i=1;i<1010;i++) + { + for(j=1;j<1010;j++) + { + if(j==1) + num[i][j]+=(num[i-1][j])*2+1; + else + num[i][j]+=num[i-1][j]*2; + } + for(j=2;j<1010;j++) + { + if(num[i][j-1]>9) + num[i][j]+=num[i][j-1]/10; + num[i][j-1]%=10; + } + } + while(scanf("%d",&n)!=EOF) + { + for(i=1010;i>=1;i--) + if(num[n][i]!=0) + { + printf("%d",num[n][i]); + break; + } + for(j=i-1;j>=1;j--) + printf("%d",num[n][j]); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1593_autoAC.cpp b/HDOJ/1593_autoAC.cpp new file mode 100644 index 0000000..1cac41a --- /dev/null +++ b/HDOJ/1593_autoAC.cpp @@ -0,0 +1,12 @@ +#include +#define PI 3.1415926 +int main() +{ + double R, v1, v2, r; + while(~scanf("%lf%lf%lf", &R, &v1, &v2)) + { + r = R * v1 / v2; + printf((R - r) / v1 < PI * R / v2 ? "Yes\n" : "No\n"); + } + return 0; +} diff --git a/HDOJ/1594_autoAC.cpp b/HDOJ/1594_autoAC.cpp new file mode 100644 index 0000000..f9fbaa2 --- /dev/null +++ b/HDOJ/1594_autoAC.cpp @@ -0,0 +1,31 @@ +#include +#include +using namespace std; +int abs(int a) +{ + if(a<0)return -a; + return a; +} +int main() +{ + int i,n; + while(scanf("%d",&n)!=EOF) + { + int x,y,max; + scanf("%d%d",&x,&y); + max=abs(y-x); + int xx=1,yy=2; + for(i=2;imax) + { + max=abs(y-x); + xx=i;yy=i+1; + } + } + printf("%d %d\n",xx,yy); + } + return 0; +} diff --git a/HDOJ/1595_autoAC.cpp b/HDOJ/1595_autoAC.cpp new file mode 100644 index 0000000..1638797 --- /dev/null +++ b/HDOJ/1595_autoAC.cpp @@ -0,0 +1,113 @@ +#include +#include +#include +using namespace std; +int map[1005][1005]; +int pre[1005]; +int dis[1005]; +bool s[1005]; +class path +{ +public: + int start, end; +}; +vectorp; +void dijkstra(int n) +{ + memset(s,false,sizeof(s)); + int i, j, k; + for (i = 2; i <= n; i++) + { + dis[i] = map[1][i]; + if (map[1][i] != -1) + { + pre[i] = 1; + } + else + { + pre[i] = -1; + } + } + pre[1] = -1; + dis[1] = 0; + s[1] = true; + for (j = 2; j <= n; j++) + { + int min = 100000; + int u; + for (i = 1; i <= n; i++) + { + if (!s[i] && dis[i] != -1) + { + if (min > dis[i]) + { + min = dis[i]; + u = i; + } + } + } + s[u] = true; + for (k = 1; k <= n;k++) + { + if (!s[k] && map[u][k]!=-1) + { + if ((dis[k] > dis[u] + map[u][k])||dis[k]==-1) + { + dis[k] = dis[u] + map[u][k]; + pre[k] = u; + } + } + } + } +} +void findpath(int n) +{ + p.clear(); + int i = n; + while (pre[i]!=-1) + { + path tmp; + tmp.start = pre[i]; + tmp.end = i; + p.push_back(tmp); + i=pre[i]; + } +} +int main() +{ + int n, m; + while (cin>>n>>m) + { + int i,k; + int start, end, weight; + for (i = 1; i <= n;i++) + for (k = 1; k <= n; k++) + { + map[i][k] = -1; + } + for (i = 0; i < m; i++) + { + cin >> start >> end >> weight; + map[start][end] = weight; + map[end][start] = weight; + } + dijkstra(n); + findpath(n); + int num,max=-1; + for (num = 0; num < p.size(); num++) + { + path tmp = p[num]; + int t; + t = map[tmp.start][tmp.end]; + map[tmp.start][tmp.end] = -1; + map[tmp.end][tmp.start] = -1; + dijkstra(n); + if (dis[n]>max) + max = dis[n]; + map[tmp.start][tmp.end] = t; + map[tmp.end][tmp.start] = t; + } + cout << max << endl; + } + return 0; +} diff --git a/HDOJ/1596_autoAC.cpp b/HDOJ/1596_autoAC.cpp new file mode 100644 index 0000000..5dfcceb --- /dev/null +++ b/HDOJ/1596_autoAC.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +#define N 1002 +using namespace std; +int n; +double map[N][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(map[i][j] < map[i][k]*map[k][j]) + map[i][j] = map[i][k]*map[k][j]; +} +int main(){ + int Q,a,b; + while(~scanf("%d",&n)){ + memset(map,0,sizeof(map)); + for(int i = 1;i<=n;i++) + for(int j = 1;j<=n;j++) + scanf("%lf",&map[i][j]); + scanf("%d",&Q); + floyd(); + for(int i = 0;i +#include +int main() +{ + __int64 i,t,n,m; + scanf("%I64d",&t); + while(t--) + { + scanf("%I64d",&n); + m=((__int64)sqrt(1+8*(n-1))-1)/2; + n-=m*(m+1)/2; + printf("%I64d\n",n%9!=0?n%9:9); + } + return 0; +} diff --git a/HDOJ/1598_autoAC.cpp b/HDOJ/1598_autoAC.cpp new file mode 100644 index 0000000..5419400 --- /dev/null +++ b/HDOJ/1598_autoAC.cpp @@ -0,0 +1,47 @@ +#include +#include +using namespace std; +static const int max_speed = 1000000; +int m,n,root[201],ct; +struct speed{ + int b,e,s; + friend bool operator < (const speed& lf, const speed& rt){ + return lf.s < rt.s; + } +}speeds[2048]; +int find(int t){ + return root[t] == t ? t : root[t] = find(root[t]); +} +inline void merge(int u, int v){ + root[find(u)] = find(v); +} +int foo(int begin, int end){ + int ret = max_speed+1; + for (int i = 0; i < m; ++i){ + for (int k = 1; k <= n; ++k) root[k] = k; + for (int j = i; j < m; ++j){ + merge(speeds[j].b, speeds[j].e); + if (find(begin) != find(end)) continue; + int delta = speeds[j].s - speeds[i].s; + if (delta < ret) ret = delta; + } + } + return ret <= max_ ? ret : -1; +} +int main(){ + ios::sync_with_stdio(false); + while (cin >> n >> m){ + int q,b,e; + for (int i = 0; i < m; ++i){ + speed& s = speeds[i]; + cin >> s.b >> s.e >> s.s; + } + sort(speeds,speeds+m); + cin >> q; + while (q--){ + cin >> b >> e; + cout << foo(b,e) << endl; + } + } + return 0; +} diff --git a/HDOJ/1599_autoAC.cpp b/HDOJ/1599_autoAC.cpp new file mode 100644 index 0000000..00548c7 --- /dev/null +++ b/HDOJ/1599_autoAC.cpp @@ -0,0 +1,81 @@ +#include +#include +int map[300][300]; +int dist[300][300]; +int n,m; +int ans; +void floyd() +{ + for(int i=1;i<=n;i++) + { + for(int j=1;j<=n;j++) + { + dist[i][j]=map[i][j]; + } + } + for(int k=1;k<=n;k++) + { + for(int i=1;i<=n;i++) + { + for(int j=1;j<=n;j++) + { + if(i!=j&&j!=k&&k!=i&&dist[i][j]!=2000000000&&map[j][k]!=2000000000&&map[k][i]!=2000000000&&ans>dist[i][j]+map[j][k]+map[k][i]) + { + ans=dist[i][j]+map[j][k]+map[k][i]; + } + } + } + for(int i=1;i<=n;i++) + { + for(int j=1;j<=n;j++) + { + if(dist[i][k]!=2000000000&&dist[k][j]!=2000000000&&dist[i][j]>dist[i][k]+dist[k][j]) + { + dist[i][j]=dist[i][k]+dist[k][j]; + } + } + } + } + return; +} +int main() +{ + while(scanf("%d%d",&n,&m)!=EOF) + { + for(int i=1; i<=n; i++) + { + for(int j=1; j<=n; j++) + { + if(i!=j) + { + map[i][j]=2000000000; + } + else + { + map[i][j]=0; + } + } + } + while(m--) + { + int a,b,c; + scanf("%d%d%d",&a,&b,&c); + if(a!=b&&map[a][b]>c) + { + map[a][b]=c; + map[b][a]=c; + } + } + ans=2000000000; + floyd(); + if(ans==2000000000) + { + printf("It's impossible.\n"); + } + else + { + printf("%d\n",ans); + } + } + return 0; +}