From bd4f730b168d00cc87139e8f376b2da65f6eb15b Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Fri, 19 Aug 2016 10:57:19 +0800 Subject: [PATCH] Powered By HC TECH : AutoACer Engine 1900-1999 --- HDOJ/1901_autoAC.cpp | 45 ++++++++++ HDOJ/1902_autoAC.cpp | 39 +++++++++ HDOJ/1903_autoAC.cpp | 33 +++++++ HDOJ/1904_autoAC.cpp | 40 +++++++++ HDOJ/1905_autoAC.cpp | 41 +++++++++ HDOJ/1907_autoAC.cpp | 21 +++++ HDOJ/1908_autoAC.cpp | 50 +++++++++++ HDOJ/1911_autoAC.cpp | 63 ++++++++++++++ HDOJ/1912_autoAC.cpp | 54 ++++++++++++ HDOJ/1913_autoAC.cpp | 28 ++++++ HDOJ/1914_autoAC.cpp | 93 ++++++++++++++++++++ HDOJ/1915_autoAC.cpp | 53 ++++++++++++ HDOJ/1916_autoAC.cpp | 58 +++++++++++++ HDOJ/1920_autoAC.cpp | 29 +++++++ HDOJ/1922_autoAC.cpp | 107 +++++++++++++++++++++++ HDOJ/1923_autoAC.cpp | 136 +++++++++++++++++++++++++++++ HDOJ/1924_autoAC.cpp | 103 ++++++++++++++++++++++ HDOJ/1925_autoAC.cpp | 55 ++++++++++++ HDOJ/1926_autoAC.cpp | 30 +++++++ HDOJ/1930_autoAC.cpp | 81 +++++++++++++++++ HDOJ/1934_autoAC.cpp | 115 +++++++++++++++++++++++++ HDOJ/1936_autoAC.cpp | 93 ++++++++++++++++++++ HDOJ/1937_autoAC.cpp | 67 +++++++++++++++ HDOJ/1939_autoAC.cpp | 26 ++++++ HDOJ/1940_autoAC.cpp | 66 ++++++++++++++ HDOJ/1941_autoAC.cpp | 59 +++++++++++++ HDOJ/1943_autoAC.cpp | 20 +++++ HDOJ/1944_autoAC.cpp | 46 ++++++++++ HDOJ/1945_autoAC.cpp | 42 +++++++++ HDOJ/1949_autoAC.cpp | 72 ++++++++++++++++ HDOJ/1950_autoAC.cpp | 36 ++++++++ HDOJ/1951_autoAC.cpp | 74 ++++++++++++++++ HDOJ/1954_autoAC.cpp | 71 +++++++++++++++ HDOJ/1955_autoAC.cpp | 84 ++++++++++++++++++ HDOJ/1956_autoAC.cpp | 127 +++++++++++++++++++++++++++ HDOJ/1957_autoAC.cpp | 201 +++++++++++++++++++++++++++++++++++++++++++ HDOJ/1959_autoAC.cpp | 69 +++++++++++++++ HDOJ/1960_autoAC.cpp | 69 +++++++++++++++ HDOJ/1962_autoAC.cpp | 74 ++++++++++++++++ HDOJ/1963_autoAC.cpp | 39 +++++++++ HDOJ/1964_autoAC.cpp | 181 ++++++++++++++++++++++++++++++++++++++ HDOJ/1965_autoAC.cpp | 89 +++++++++++++++++++ HDOJ/1966_autoAC.cpp | 57 ++++++++++++ HDOJ/1967_autoAC.cpp | 102 ++++++++++++++++++++++ HDOJ/1969_autoAC.cpp | 39 +++++++++ HDOJ/1970_autoAC.cpp | 59 +++++++++++++ HDOJ/1971_autoAC.cpp | 78 +++++++++++++++++ HDOJ/1972_autoAC.cpp | 48 +++++++++++ HDOJ/1973_autoAC.cpp | 113 ++++++++++++++++++++++++ HDOJ/1975_autoAC.cpp | 44 ++++++++++ HDOJ/1976_autoAC.cpp | 24 ++++++ HDOJ/1977_autoAC.cpp | 18 ++++ HDOJ/1978_autoAC.cpp | 25 ++++++ HDOJ/1979_autoAC.cpp | 9 ++ HDOJ/1981_autoAC.cpp | 39 +++++++++ HDOJ/1982_autoAC.cpp | 46 ++++++++++ HDOJ/1983_autoAC.cpp | 145 +++++++++++++++++++++++++++++++ HDOJ/1984_autoAC.cpp | 22 +++++ HDOJ/1985_autoAC.cpp | 23 +++++ HDOJ/1986_autoAC.cpp | 51 +++++++++++ HDOJ/1987_autoAC.cpp | 59 +++++++++++++ HDOJ/1988_autoAC.cpp | 72 ++++++++++++++++ HDOJ/1990_autoAC.cpp | 29 +++++++ HDOJ/1992_autoAC.cpp | 15 ++++ HDOJ/1993_autoAC.cpp | 145 +++++++++++++++++++++++++++++++ HDOJ/1994_autoAC.cpp | 17 ++++ HDOJ/1995_autoAC.cpp | 11 +++ HDOJ/1996_autoAC.cpp | 19 ++++ HDOJ/1997_autoAC.cpp | 46 ++++++++++ HDOJ/1998_autoAC.cpp | 13 +++ HDOJ/1999_autoAC.cpp | 35 ++++++++ 71 files changed, 4282 insertions(+) create mode 100644 HDOJ/1901_autoAC.cpp create mode 100644 HDOJ/1902_autoAC.cpp create mode 100644 HDOJ/1903_autoAC.cpp create mode 100644 HDOJ/1904_autoAC.cpp create mode 100644 HDOJ/1905_autoAC.cpp create mode 100644 HDOJ/1907_autoAC.cpp create mode 100644 HDOJ/1908_autoAC.cpp create mode 100644 HDOJ/1911_autoAC.cpp create mode 100644 HDOJ/1912_autoAC.cpp create mode 100644 HDOJ/1913_autoAC.cpp create mode 100644 HDOJ/1914_autoAC.cpp create mode 100644 HDOJ/1915_autoAC.cpp create mode 100644 HDOJ/1916_autoAC.cpp create mode 100644 HDOJ/1920_autoAC.cpp create mode 100644 HDOJ/1922_autoAC.cpp create mode 100644 HDOJ/1923_autoAC.cpp create mode 100644 HDOJ/1924_autoAC.cpp create mode 100644 HDOJ/1925_autoAC.cpp create mode 100644 HDOJ/1926_autoAC.cpp create mode 100644 HDOJ/1930_autoAC.cpp create mode 100644 HDOJ/1934_autoAC.cpp create mode 100644 HDOJ/1936_autoAC.cpp create mode 100644 HDOJ/1937_autoAC.cpp create mode 100644 HDOJ/1939_autoAC.cpp create mode 100644 HDOJ/1940_autoAC.cpp create mode 100644 HDOJ/1941_autoAC.cpp create mode 100644 HDOJ/1943_autoAC.cpp create mode 100644 HDOJ/1944_autoAC.cpp create mode 100644 HDOJ/1945_autoAC.cpp create mode 100644 HDOJ/1949_autoAC.cpp create mode 100644 HDOJ/1950_autoAC.cpp create mode 100644 HDOJ/1951_autoAC.cpp create mode 100644 HDOJ/1954_autoAC.cpp create mode 100644 HDOJ/1955_autoAC.cpp create mode 100644 HDOJ/1956_autoAC.cpp create mode 100644 HDOJ/1957_autoAC.cpp create mode 100644 HDOJ/1959_autoAC.cpp create mode 100644 HDOJ/1960_autoAC.cpp create mode 100644 HDOJ/1962_autoAC.cpp create mode 100644 HDOJ/1963_autoAC.cpp create mode 100644 HDOJ/1964_autoAC.cpp create mode 100644 HDOJ/1965_autoAC.cpp create mode 100644 HDOJ/1966_autoAC.cpp create mode 100644 HDOJ/1967_autoAC.cpp create mode 100644 HDOJ/1969_autoAC.cpp create mode 100644 HDOJ/1970_autoAC.cpp create mode 100644 HDOJ/1971_autoAC.cpp create mode 100644 HDOJ/1972_autoAC.cpp create mode 100644 HDOJ/1973_autoAC.cpp create mode 100644 HDOJ/1975_autoAC.cpp create mode 100644 HDOJ/1976_autoAC.cpp create mode 100644 HDOJ/1977_autoAC.cpp create mode 100644 HDOJ/1978_autoAC.cpp create mode 100644 HDOJ/1979_autoAC.cpp create mode 100644 HDOJ/1981_autoAC.cpp create mode 100644 HDOJ/1982_autoAC.cpp create mode 100644 HDOJ/1983_autoAC.cpp create mode 100644 HDOJ/1984_autoAC.cpp create mode 100644 HDOJ/1985_autoAC.cpp create mode 100644 HDOJ/1986_autoAC.cpp create mode 100644 HDOJ/1987_autoAC.cpp create mode 100644 HDOJ/1988_autoAC.cpp create mode 100644 HDOJ/1990_autoAC.cpp create mode 100644 HDOJ/1992_autoAC.cpp create mode 100644 HDOJ/1993_autoAC.cpp create mode 100644 HDOJ/1994_autoAC.cpp create mode 100644 HDOJ/1995_autoAC.cpp create mode 100644 HDOJ/1996_autoAC.cpp create mode 100644 HDOJ/1997_autoAC.cpp create mode 100644 HDOJ/1998_autoAC.cpp create mode 100644 HDOJ/1999_autoAC.cpp diff --git a/HDOJ/1901_autoAC.cpp b/HDOJ/1901_autoAC.cpp new file mode 100644 index 0000000..f10878f --- /dev/null +++ b/HDOJ/1901_autoAC.cpp @@ -0,0 +1,45 @@ +#include +#include +#include +using namespace std; +char s[10005]; +int cur, len; +double solve(){ + double c = 1; + while(!(s[cur] == '(' || s[cur] >= '0' && s[cur] <= '9' || s[cur] == '-') && cur < len) + cur++; + if(s[cur] == '-') + c = -1, cur++; + if(s[cur] == '('){ + double w = 0.1, p = 0; + if(s[++cur] == '.' || s[cur+1] == '.'){ + if(s[cur+1] == '.') + cur++; + for(int i = cur + 1; s[i] >= '0' && s[i] <= '9' && s[i]; i++, cur = i) + p = p + (s[i] - '0') * w, w *= 0.1; + } + else + p = s[cur++] - '0'; + double a, b; + a = solve(); + b = solve(); + return (a+b)*p + (a-b) * (1-p); + } + else{ + double p = 0; + for(int i = cur; s[i] >= '0' && s[i] <= '9'; i++, cur=i) + p = p * 10 + (s[i]-'0'); + return c * p; + } +} +int main() +{ + double p, a, b; + while(gets(s)&& strcmp(s, "()")) + { + len = strlen(s); + cur = 0; + printf("%.2lf\n", solve()); + } + return 0; +} diff --git a/HDOJ/1902_autoAC.cpp b/HDOJ/1902_autoAC.cpp new file mode 100644 index 0000000..c28f9a6 --- /dev/null +++ b/HDOJ/1902_autoAC.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +const int MAX = 20000+5; +int main() +{ + int n,m,d[MAX],a[MAX]; + while(std::cin>>n>>m,(n+m)) + { + for(int i = 0;i < n;i++) + std::cin>>d[i]; + for(int i = 0;i < m;i++) + std::cin>>a[i]; + if(n>m) + { + std::cout<<"Loowater is doomed!"<=d[i]){ + tot += a[j]; + j++,i++; + }else + { + j++; + } + } + if(i>=n) + std::cout< +#include +using namespace std; +int const MAX =0x3f3f3f3f; +double dp[2][366]; +double exchange[366]; +double commissionRate = 0.97; +int mask =100; +int main() +{ + int days=0; + while(scanf("%d",&days) && days !=0 ) + { + memset(dp,-MAX,sizeof(dp)); + dp[0][1]=100000.0; + for(int i=1;i<=days;i++ ) + scanf("%lf",&exchange[i]); + dp[1][1] = (dp[0][1]/exchange[1])*commissionRate; + for(int i=2;i<=days;i++) + { + if(dp[0][i-1] > dp[1][i-1]*exchange[i]*commissionRate) + dp[0][i] = (int)dp[0][i-1]+0.0; + else + dp[0][i] =(int)(dp[1][i-1]*exchange[i]*commissionRate)+0.0; + if(dp[1][i-1] > (dp[0][i-1]/exchange[i])*commissionRate) + dp[1][i] = (int)(dp[1][i-1])+0.0; + else + dp[1][i] =(int)((dp[0][i-1]/exchange[i])*commissionRate)+0.0; + } + printf("%.2lf\n",dp[0][days]/100); + } + return 0; +} diff --git a/HDOJ/1904_autoAC.cpp b/HDOJ/1904_autoAC.cpp new file mode 100644 index 0000000..0cf673d --- /dev/null +++ b/HDOJ/1904_autoAC.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +using namespace std; +int s[10001][6]; +int main() +{ + int n,i,j,sum,max,num; + map::iterator it; + mapans; + while(scanf("%d",&n),n) + { + ans.clear(); + for(i=1;i<=n;i++) + for(j=0;j<5;j++) + scanf("%d",&s[i][j]); + for(i=1;i<=n;i++) + sort(s[i],s[i]+5); + for(i=1;i<=n;i++) + { + string str; + for(j=0;j<5;j++) + { + char a[5]; + itoa(s[i][j],a,10); + str+=a; + } + ans[str]++; + } + max=num=0; + for(it=ans.begin();it!=ans.end();it++) + if(it->second>max)max=it->second; + for(it=ans.begin();it!=ans.end();it++) + if(it->second==max)num++; + printf("%d\n",num*max); + } + return 0; +} diff --git a/HDOJ/1905_autoAC.cpp b/HDOJ/1905_autoAC.cpp new file mode 100644 index 0000000..6d5c6e8 --- /dev/null +++ b/HDOJ/1905_autoAC.cpp @@ -0,0 +1,41 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +bool prime(__int64 a) +{ + __int64 i; + for(i=2;i*i<=a;i++) + { + if(a%i == 0)return false; + } + return true; +} +bool q_pow(__int64 a,__int64 b) +{ + __int64 res=1,mod=b,carry=a; + while(b) + { + if(b%2) + { + res=res*a%mod; + } + a=a*a%mod; + b>>=1; + } + if(res == carry)return true; + else return false; +} +int main() +{ + __int64 p,a; + while(~scanf("%I64d %I64d",&p,&a),p+a) + { + if(!prime(p) && q_pow(a,p))puts("yes"); + else puts("no"); + } + return 0; +} diff --git a/HDOJ/1907_autoAC.cpp b/HDOJ/1907_autoAC.cpp new file mode 100644 index 0000000..8460cdf --- /dev/null +++ b/HDOJ/1907_autoAC.cpp @@ -0,0 +1,21 @@ +#include +int main() +{ + int temp,t,n,s,x,i; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + for(i=s=temp=0;i1) temp=1; + s^=x; + } + if((s&&temp)||(!s&&!temp)) + puts("John"); + else + puts("Brother"); + } + return 0; +} diff --git a/HDOJ/1908_autoAC.cpp b/HDOJ/1908_autoAC.cpp new file mode 100644 index 0000000..3db64e8 --- /dev/null +++ b/HDOJ/1908_autoAC.cpp @@ -0,0 +1,50 @@ +#include +#include +using namespace std; +struct node +{ + node(int a,int b):num(a),p(b){} + int num; + int p; + bool operator < (const node a)const + { + return p s; + while(cin>>com&&com) + { + switch(com) + { + case 1: + { + cin>>k>>p; + s.insert(node(k,p)); + }break; + case 2: + { + if(s.empty()) + cout<<0< +#include +#include +#include +using namespace std; +const long long inf=1LL<<35; +const long long maxn=1e6+100; +char str[110]; +long long x[maxn],y[maxn],z[maxn],cnt; +long long Sum(long long val) +{ + long long sum=0; + for(int i=0;i>1; + if(Sum(mid)&1) + { + r=mid-1; + ans=mid; + } + else + l=mid+1; + } + if(ans==-1) + { + printf("no corruption\n"); + return; + } + printf("%I64d %I64d\n",ans,Sum(ans)-Sum(ans-1)); +} +int main() +{ + cnt=0; + while(gets(str)!=NULL) + { + if(strlen(str)==0) + { + if(cnt==0) + continue; + solve(); + cnt=0; + } + else + { + sscanf(str,"%I64d%I64d%I64d",&x[cnt],&y[cnt],&z[cnt]); + cnt++; + } + } + if(cnt) + solve(); + return 0; +} diff --git a/HDOJ/1912_autoAC.cpp b/HDOJ/1912_autoAC.cpp new file mode 100644 index 0000000..0a34df3 --- /dev/null +++ b/HDOJ/1912_autoAC.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +using namespace std; +int L,d; +struct I +{ + double l,r; +}inter[10000]; +bool cmp(I a ,I b) +{ + if(a.rb.l) + return true; + return false; + } + return false; +} +int main() +{ + double x,y; + while(scanf("%d",&L)!=EOF) + { + scanf("%d",&d); + int n; + cin>>n; + for(int i=1;i<=n;i++) + { + scanf("%lf%lf",&x,&y); + inter[i].l=x-sqrt(d*d-y*y); + inter[i].r=x+sqrt(d*d-y*y); + } + sort(inter+1,inter+1+n,cmp); + int ans=1; + double temp=inter[1].r; + for(int i=2;i<=n;i++) + { + if(temp>L) + temp=L; + if(temp +#define N 1000 +int sum[N][N]; +int main() +{ + int c,n,i,j; + while (scanf("%d",&c)!=EOF) + { + scanf("%d",&n); + for(i=0;i +#include +#include +#include +#include +#include +using namespace std; +const int maxn=50; +int g[maxn][maxn], b[maxn][maxn], visit[maxn][maxn]; +int bf[maxn], gf[maxn]; +char ch[maxn], str[maxn]; +mapG,M; +mapGG,MM; +queueq; +int n, T; +void init() +{ + G.clear(), M.clear(), GG.clear(), MM.clear(); + memset(visit,0,sizeof(visit)); + memset(bf,0,sizeof(bf)); + while(!q.empty()) q.pop(); +} +void find(int x) +{ + for(int i=n; i>=1; i--) + { + if(visit[x][i]) continue; + visit[x][i]=1; + int y=b[x][i]; + if(!bf[y]) + { + bf[y]=x; + gf[x]=y; + return ; + } + else + { + if(g[y][x]>g[y][ bf[y] ]) + { + q.push(bf[y]); + bf[y]=x; + gf[x]=y; + return ; + } + } + } +} +void Solve() +{ + for(int i=1; i<=n; i++) q.push(i); + while(!q.empty()) + { + int x=q.front(); + q.pop(); + find(x); + } + sort(ch+1,ch+n+1); + for(int i=1; i<=n; i++) + printf("%c %c\n",ch[i],MM[ gf[ G[ch[i]] ] ]); +} +int main() +{ + cin >> T; + while(T--) + { + cin >> n; + init(); + for(int i=1; i<=n; i++) cin >> ch[i], G[ ch[i] ]=i, GG[i]=ch[i]; + for(int i=1; i<=n; i++) cin >> ch[n+i], M[ ch[n+i] ]=i, MM[i]=ch[n+i]; + for(int i=1; i<=n; i++) + { + scanf("%s",str+1); + int x=G[ str[1] ]; + for(int j=3; j<=n+2; j++) + { + int y=M[ str[j] ]; + b[x][n-j+3]=y; + } + } + for(int i=1; i<=n; i++) + { + scanf("%s",str+1); + int x=M[ str[1] ]; + for(int j=3; j<=n+2; j++) + { + int y=G[ str[j] ]; + g[x][y]=n-j+3; + } + } + Solve(); + if(T)puts(""); + } +} diff --git a/HDOJ/1915_autoAC.cpp b/HDOJ/1915_autoAC.cpp new file mode 100644 index 0000000..29f73fa --- /dev/null +++ b/HDOJ/1915_autoAC.cpp @@ -0,0 +1,53 @@ +#include +#include +using namespace std; +char date[1000][1000]; +char strings[2000]; +int main () +{ + int num; + int i,j; + int len; + int pos=0; + while(cin>>num) + { + pos=0; + for(i=0;i>date[i]; + len=strlen(date[0]); + int flag=0; + for(j=0;j +#include +#include +using namespace std; +int a[100]; +void solve(int n){ + while(n>=10){ + a[n%10]++; + n/=10; + } + a[n]++; +} +int main() +{ + int T; + cin>>T; + getchar(); + while(T--){ + memset(a,0,sizeof(a)); + char name[600];int n;char tmp[60];char temp[100]; + gets(name); + cin>>n>>tmp; + getchar(); + int i=0; + while(i +#define ll long long +using namespace std; +ll gcd(ll a,ll b){ + return b?gcd(b,a%b):a; +} +ll lcm(ll a,ll b){ + return a*b/gcd(a,b); +} +int main() +{ + int T,n; + cin>>T; + while(T--){ + cin>>n; + ll t=0; + cin>>t; + for(int i=2;i<=n;i++){ + ll tmp; + cin>>tmp; + t=lcm(t,tmp); + } + if(t<=1e9) + cout< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define eps 1e-8 +#define pi acos(-1.0) +#define inf 107374182 +#define inf64 1152921504606846976 +#define lc l,m,tr<<1 +#define rc m + 1,r,tr<<1|1 +#define iabs(x) ((x) > 0 ? (x) : -(x)) +#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (SIZE)) +#define clearall(A, X) memset(A, X, sizeof(A)) +#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE)) +#define memcopyall(A, X) memcpy(A , X ,sizeof(X)) +#define max( x, y ) ( ((x) > (y)) ? (x) : (y) ) +#define min( x, y ) ( ((x) < (y)) ? (x) : (y) ) +using namespace std; +struct node1 +{ + double x,y,l,r; + bool operator <(const node1 a)const + { + return l0)now=0.5*pi; + else now=1.5*pi; + } + else if(Point[i].y==0) + { + if(Point[i].x>0)now=0; + else now=pi; + } + else + { + now=asin(iabs(Point[i].y)/temp); + if(Point[i].x<0&&Point[i].y>=0)now=pi-now; + else if(Point[i].x<=0&&Point[i].y<0)now+=pi; + else if(Point[i].x>0&&Point[i].y<=0)now=2*pi-now; + } + drift=asin(d/temp); + //printf("*%lf %lf\n",now,drift); + Point[i].l=now-drift; + Point[i].r=now+drift; + } + } + if(n==0) + { + puts("0"); + continue; + } + sort(Point,Point+n); + for(int i=n; i<2*n; i++) + { + Point[i]=Point[i-n]; + Point[i].l+=2*pi; + Point[i].r+=2*pi; + } + ans=inf; + for(int i=0; iPoint[j].r)r=Point[j].r; + else if(r +#include +#include +#include +using namespace std; +#include +#define SSS 6000 +#define SIZE 1000000 +#define INF 2000000000 +#define NUM 200 +__int64 aa[300]; +__int64 rr[50000]; +int pri[NUM]; +int sub[SIZE]; +int pdsu(__int64 n) +{ + __int64 i; + if(n<=0||n==1 ) + return 0; + if( n==2) + return 1; + else{ + for(i=2; i*i<=n; i++) + if(n%i==0) + return 0; + } + return 1; +} +void sf(){ + int temp,n; + for(int i=0;i INF){ + continue; + } + if(next <0 ) + continue; + if(next >= SIZE){ + if(!pdsu(next)) + continue ; + } + else{ + if(!sub[next]) + continue ; + } + res = res * next; + if(res >INF) continue; + while(1){ + next2 = next * a +b; + if(next2 == next ) break; + if(res * next2 > INF){ + break; + } + if(next2 <0 ) + break; + if(next2 >= SIZE){ + if(!pdsu(next2)) + break ; + } + else{ + if(!sub[next2]) + break ; + } + res = res * next2; + if(res >INF) break; + rr[t++] = res ; + next = next2 ; + } + } + } + for(int i = 0 ; irr[j]){ + int temp = rr[i]; + rr[i] = rr[j]; + rr[j] = temp; + } + } + int ccc = 0; + for(int i = 0 ; i =aa[i]) + ans++; + } + printf("%d\n",ans); + } + return 0 ; +} diff --git a/HDOJ/1924_autoAC.cpp b/HDOJ/1924_autoAC.cpp new file mode 100644 index 0000000..959c4e7 --- /dev/null +++ b/HDOJ/1924_autoAC.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +mapmy; +mapmy2; +int turn1(string ss1) +{ + int num1=0; + int car=0; + int last=1000000; + for(int i=0;i=3&&nw<=5) + { + int tem=5-nw; + ans=my2[i*5]+ans;//hou + while(tem--) + ans=my2[i]+ans; + } + else if(nw<=8) + { + int tem=nw-5; + while(tem--) + ans=my2[i]+ans; + ans=my2[i*5]+ans; + } + else + { + int tem=10-nw; + ans=my2[i*10]+ans; + while(tem--) + ans=my2[i]+ans; + } + } + return ans; +} +int main() +{ + my["I"]=1; + my["V"]=5; + my["X"]=10; + my["L"]=50; + my["C"]=100; + my["D"]=500; + my["M"]=1000; + my2[1]="I"; + my2[5]="V"; + my2[10]="X"; + my2[50]="L"; + my2[100]="C"; + my2[500]="D"; + my2[1000]="M"; + string ss1,ss2; + int n; + int cas=1; + while(cin>>n,n) + { + int ans=0; + for(int i=0;i>ss1; + ans+=turn1(ss1); + } + cout<<"Case "< +#include +#include +#include +#include +using namespace std; +#define nMax 40 +char s[nMax]; +int m; +class P { +public: + int x,y; + P() {}; + P(int x,int y):x(x),y(y) {}; + void out() { printf("(%d,%d)\n",x,y); } +}; +P rotate(P p,int k) { + if(k==1) return P(p.y,-p.x); // turn right + else return P(-p.y,p.x); // turn left +} +P rotate(P T,P p,int k) { + P tmp(p.x-T.x,p.y-T.y); + P ret = rotate(tmp,k); + return P(ret.x+T.x,ret.y+T.y); +} +P p[40]; +int r[40]; +P dfs(int m) { + if(m==0) return p[0]; + long long i=1LL; + int j=1; + while(m>=i) { + i <<= 1; + j += 1; + } + i >>= 1;j--; + if(m==i) return p[j]; + m -= i; + return rotate(p[j],dfs(i-m),r[j]); +} +int main() { + int t; + scanf("%d",&t); + while(t--) { + scanf("%s%d",s,&m); + int l = strlen(s); + p[0]=P(0,0); + p[1]=P(1,0); + for(int j=1,i=l-1;i>=0;i--,j++) r[j] = (s[i]=='U'?1:0); + for(int i=2;i<=l+1;i++) p[i] = rotate(p[i-1],p[0],r[i-1]); + P ret = dfs(m); + ret.out(); + } + return 0; +} diff --git a/HDOJ/1926_autoAC.cpp b/HDOJ/1926_autoAC.cpp new file mode 100644 index 0000000..5c318d1 --- /dev/null +++ b/HDOJ/1926_autoAC.cpp @@ -0,0 +1,30 @@ +#include +#include +#include +using namespace std; +int tran[]={0,2,4,6,30,32,34,36,40,42,44,46,50,52,54,56,60,62,64,66}; +int main() +{ + int t,dig[15],pd,inp; + while(scanf("%d",&inp),inp!=0) + { + pd=0; + while(inp) + { + dig[pd++]=inp%20; + inp/=20; + } + bool flag=false; + if(pd>=8) + flag=true; + printf("%d",tran[dig[--pd]]); + for(t=pd-1;t>=0;t--) + { + if(t==6 && flag) + printf(",000,000"); + printf(",%.3d",tran[dig[t]]); + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1930_autoAC.cpp b/HDOJ/1930_autoAC.cpp new file mode 100644 index 0000000..cf4f7ec --- /dev/null +++ b/HDOJ/1930_autoAC.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +using namespace std; +__int64 carry[100],yuan[100]; +__int64 t,n,m1,m2,m3,m4,i,j; +__int64 a,b,c,d; +__int64 ex_gcd(__int64 a,__int64 b,__int64 &x, __int64 &y) +{ + if(b == 0) + { + x=1; + y=0; + return a; + } + __int64 result = ex_gcd(b,a%b,x,y); + __int64 t=x; + x=y; + y=t-a/b*y; + return result; +} +void china(__int64 num) +{ + __int64 M,t,x,y,res=0; + M=m1*m2*m3*m4; + t=M/m1; + ex_gcd(t,m1,x,y); + res=(res+t*a*x)%M; + t=M/m2; + ex_gcd(t,m2,x,y); + res=(res+t*b*x)%M; + t=M/m3; + ex_gcd(t,m3,x,y); + res=(res+t*c*x)%M; + t=M/m4; + ex_gcd(t,m4,x,y); + res=(res+t*d*x)%M; + yuan[num]=(res%M+M)%M; +} +void chu(__int64 ji) +{ + if(ji == 27)printf(" "); + else printf("%c",ji+'A'-1); +} +int main() +{ + scanf("%I64d",&t); + while(t--) + { + scanf("%I64d",&n); + scanf("%I64d %I64d %I64d %I64d",&m1,&m2,&m3,&m4); + for(i=0;i +#include +#include +#include +#include +#include +using namespace std; +char mm[10] = {"ACMIP"}; +char a[10]; +char b[10]; +__int64 n; +int check(char c[]) +{ + int len = strlen(c); + bool isok2 = true; + bool isok1 = true; + for(int i=0;i<3;i++) + { + if(c[i] <'A' || c[i] >'Z') + { + isok1 = false; + break; + } + } + for(int i=3;i<7;i++) + { + if(c[i] <'0' || c[i] >'9') + { + isok1 = false; + break; + } + } + for(int i=0;i<5;i++) + { + if(c[i] <'B' || c[i] > 'Z' || c[i] == 'C' || c[i] == 'M' || c[i] == 'I' || c[i] == 'P') + { + isok2 = false; + break; + } + } + for(int i=5;i<7;i++) + { + if(c[i] <'0' || c[i] > '9') + { + isok2 = false; + break; + } + } + if(isok1) return 1; + else if(isok2) return 2; + return 0; +} +__int64 cal_old(char s[]) +{ + __int64 sum = 0; + for(int i=0;i<3;i++) + { + sum = sum * 26 + (s[i]-'A'); + } + for(int i=3;i<7;i++) + { + sum = sum *10 + (s[i] -'0'); + } + return sum; +} +char dir[27] = {"BDEFGHJKLNOQRSTUVWXYZ"}; +int cal_new(char s[]) +{ + __int64 sum = 0; + for(int i=0;i<5;i++) + { + int res = -1; + while(s[i] != dir[++res]); + sum = sum *21 + res; + } + int tmp = 0; + for(int i=5;i<7;i++) + { + tmp = tmp* 10 + (s[i] - '0'); + } + sum *= 100; + sum += tmp; + sum = sum + cal_old("ZZZ99999") + 1; + return sum; +} +int main() +{ + while(~scanf("%s %s %d",a,b,&n)) + { + getchar(); + if(a[0] == '*' && b[0] == '*' && n == 0) break; + int res = check(a); + int tmp = check(b); + if(res == 0 || tmp == 0) + { + printf("N\n"); + continue; + } + __int64 sum_a = 0; + __int64 sum_b = 0; + if(res == 1) + sum_a = cal_old(a); + else + sum_a = cal_new(a); + if(tmp == 1) + sum_b = cal_old(b); + else + sum_b = cal_new(b); + if(sum_b > sum_a && sum_a + n >= sum_b) + printf("Y\n"); + else + printf("N\n"); + } + return 0; +} diff --git a/HDOJ/1936_autoAC.cpp b/HDOJ/1936_autoAC.cpp new file mode 100644 index 0000000..4f4763d --- /dev/null +++ b/HDOJ/1936_autoAC.cpp @@ -0,0 +1,93 @@ +#include +#include +#include +#include +using namespace std; +int n, m; +string A[1050], B[1050]; +struct pos +{ + int L, R; +} p[10050]; +bool cmp(pos A, pos B) +{ + if (A.L != B.L) + { + return A.L < B.L; + } + return A.R < B.R; +} +void solve() +{ + int cnt = 0; + for (int i = 1; i <= m; i++) + { + int lenB = B[i].length(); + int q = 1; + for (int j = 0; j < lenB; j++) + { + for (int k = 1; k <= n; k++) + { + int lenA = A[k].length(); + if (j+lenA-1 >= lenB) continue; + if (A[k][0] == B[i][j] && A[k][lenA-1] == B[i][j+lenA-1]) + { + bool ok = true; + for (int l = 0; l < lenA; l++) + { + if (A[k][l] != B[i][j+l]) + { + ok = false; + break; + } + } + if (ok) + { + p[q].L = j; + p[q++].R = j+lenA-1; + } + } + } + } + p[0].L = p[0].R = -100; + sort(p+1, p+q, cmp); + for (int i = q-1; i >= 1; i--) + { + if (p[i].L > p[i-1].R) + { + cnt++; + } + else + { + for (int j = i-1; j >= 1; j--) + { + if (p[i].L <= p[j].R) ; + else + { + i = j+1; + cnt++; + break; + } + } + } + } + } + cout << cnt << endl; +} +int main() +{ + while (cin >> n >> m && (n && m)) + { + for (int i = 1; i <= n; i++) + { + cin >> A[i]; + } + getchar(); + for (int i = 1; i <= m; i++) + { + getline(cin, B[i]); + } + solve(); + } + return 0; +} diff --git a/HDOJ/1937_autoAC.cpp b/HDOJ/1937_autoAC.cpp new file mode 100644 index 0000000..5a8dd45 --- /dev/null +++ b/HDOJ/1937_autoAC.cpp @@ -0,0 +1,67 @@ +#include +#include +#include +using namespace std; +const int INF=1<<31-1; +char a[310][310]; +int mmap[310][310]; +int r,c,k; +void chuli() +{ + int i,j; + for(i=1;i<=r;i++) + mmap[i][1]=(a[i][1]=='.'); + for(j=1;j<=c;j++) + mmap[1][j]=(a[1][j]=='.'); + for(i=1;i<=r;i++) + { + for(j=1;j<=c;j++) + { + mmap[i][j]=(mmap[i-1][j]+mmap[i][j-1]-mmap[i-1][j-1]+(a[i][j]=='.')); + } + } +} +int check(int x1,int y1,int x2,int y2) +{ + if(mmap[x2][y2]+mmap[x1-1][y1-1]-mmap[x1-1][y2]-mmap[x2][y1-1]>=k) + return 0; + else + return 1; +} +int main() +{ + while(scanf("%d%d%d",&r,&c,&k)!=EOF) + { + memset(mmap,0,sizeof(mmap)); + if(r==c&&r==k&&k==0) + { + break; + } + int i,j; + for(i=1;i<=r;i++) + scanf("%s",a[i]+1); + chuli(); + int t1,t2; + int min=INF; + for(i=1;i<=r;i++) + { + for(j=i;j<=r;j++) + { + for(t1=1,t2=1;t1<=c;t1++) + { + while(check(i,t1,j,t2)==1&&t2(j-i+1)*(t2-t1+1)) + min=(j-i+1)*(t2-t1+1); + } + } + } + } + printf("%d\n",min); + } + return 0; +} diff --git a/HDOJ/1939_autoAC.cpp b/HDOJ/1939_autoAC.cpp new file mode 100644 index 0000000..826f130 --- /dev/null +++ b/HDOJ/1939_autoAC.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +using namespace std; +int t1[10000],t2[10000]; +int main(){ + int a,b; + while(scanf("%d%d",&a,&b)!=EOF){ + if(a==0&&b==0) + break; + memset(t1,0,sizeof(t1)); + memset(t2,0,sizeof(t2)); + for(int i=0;i +#include +#include +using namespace std; +int t, p; +int tp[200], fa[200], ac[200]; +int min(int a, int b){ + if(ab) return a;return b; +} +void solve() +{ + for(int i = 1; i <= t; i++) + { + tp[i] = 0; fa[i] = 0; ac[i] = 0; + } + for(int i = 1; i <= t; i++) + for(int j = 1; j <= p; j++) + { + int x; + int y; + char s[5]; + cin >> x >> s; + if(s[1] != '-'){ + ac[i]++; + fa[i]+=x; + y = 0; + for(int k = 1; k 20) + biggest = min(biggest, int(floor(x-1e-2))); + else + least = max(least, int(ceil(x + 1e-2))); + } + cout << least <<' '; + if(biggest == 2000000000) + cout << '*'; + else + cout << biggest; + cout << endl; +} +int main() +{ + cin >> t >> p; + while(t!=0 || p != 0) + { + solve(); + cin >> t >> p; + } +} diff --git a/HDOJ/1941_autoAC.cpp b/HDOJ/1941_autoAC.cpp new file mode 100644 index 0000000..fbb383a --- /dev/null +++ b/HDOJ/1941_autoAC.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#define MAXD 50010 +#define MAXM 200010 +#define INF 0x3f3f3f3f +int N, M, first[MAXD], e, next[MAXM], v[MAXM], dgr[MAXD], isin[MAXD], r[MAXD]; +bool cmp(const int &x, const int &y) +{ + return dgr[x] < dgr[y]; +} +void add(int x, int y) +{ + v[e] = y; + next[e] = first[x], first[x] = e ++; +} +void init() +{ + int i, x, y; + memset(first, -1, sizeof(first[0]) * (N + 1)), e = 0; + memset(dgr, 0, sizeof(dgr[0]) * (N + 1)); + for(i = 0; i < M; i ++) + { + scanf("%d%d", &x, &y); + ++ dgr[x], ++ dgr[y]; + add(x, y), add(y, x); + } +} +void solve() +{ + int i, j, x, cnt = 0, min = INF; + memset(isin, 0, sizeof(isin[0]) * (N + 1)); + for(i = 1; i <= N; i ++) r[i] = i; + std::sort(r + 1, r + 1 + N, cmp); + for(i = 1; i <= N; i ++) + if(!isin[x = r[i]]) + { + for(j = first[x]; j != -1; j = next[j]) + -- dgr[v[j]], isin[v[j]] = 1; + } + for(i = 1; i <= N; i ++) + if(isin[x = r[i]]) + ++ cnt, min = std::min(min, dgr[x]); + printf("%s\n", cnt == min + 1 ? "Y" : "N"); +} +int main() +{ + while(scanf("%d%d", &N, &M), N) + { + if(M == 0) + { + printf("Y\n"); + continue; + } + init(); + solve(); + } + return 0; +} diff --git a/HDOJ/1943_autoAC.cpp b/HDOJ/1943_autoAC.cpp new file mode 100644 index 0000000..1ac5d8b --- /dev/null +++ b/HDOJ/1943_autoAC.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +using namespace std; +const double PI=acos(-1.0); +#define eps 1e-3 +int main() +{ + int T; + double D,d,s; + scanf("%d",&T); + while(T--) + { + scanf("%lf%lf%lf",&D,&d,&s); + double temp=asin((d+s)/(D-d)); + double tt=(2*PI)/(2*temp); + printf("%d\n",(int)tt); + } + return 0; +} diff --git a/HDOJ/1944_autoAC.cpp b/HDOJ/1944_autoAC.cpp new file mode 100644 index 0000000..1f6ca90 --- /dev/null +++ b/HDOJ/1944_autoAC.cpp @@ -0,0 +1,46 @@ +#include +#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 +int H[2][2]={{1,1},{1,-1}}; +long long dfs(long long x,long long y) +{ + if(x<2&&y<2)return H[x][y]; + int i=0,j=0; + if(x>=2) + { + i=1; + while(i*2<=x) + i*=2; + x-=i; + } + if(y>=2) + { + j=1; + while(j*2<=y) + j*=2; + y-=j; + } + if(i==j)return -dfs(x,y); + else if(i>j)return dfs(x,y+j); + else return dfs(x+i,y); +} +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + long long n,x,y,w,h,i,j; + scanf("%I64d%I64d%I64d%I64d%I64d",&n,&x,&y,&w,&h); + for(i=y;i +#include +#include +using namespace std; +#define maxn 218 +#define max(a,b) a>b?a:b; +#define min(a,b) a>b?b:a; +#define inf 0x3f3f3f3f +int dp[maxn][maxn][maxn]; +char map[maxn][maxn]; +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + memset(map,'#',sizeof(map)); + int r,c; + scanf("%d%d",&c,&r); + for(int i = 0;i < r;i++) + scanf("%s",map[i]); + int len = r+c-2; + for(int i = 0;i <= len;i++) + for(int j = 0;j < r;j++) + for(int k = 0;k < r;k++) + dp[i][j][k] = -inf; + dp[0][0][0] = (map[0][0] == '*'?1:0); + for(int i = 0;i <= c;i++) map[r][i] = '#'; + for(int i = 0;i <= r;i++) map[i][c] = '#'; + for(int k = 0;k < len;k++) + { + for(int i = 0;i <= k;i++) + { + if(i >= r) break; + if(k - i >= c) continue; + for(int j = 0;j <= k;j++) + { + if(j >= r) break; + if(k - j >= c) continue; + if(dp[k][i][j] < 0 || map[i][k-i] == '#' || map[j][k-j] == '#') continue; + if(map[i+1][k-i] != '#' && map[j+1][k-j] != '#') + { + int key = dp[k][i][j]+(map[i+1][k-i]=='*')+(map[j+1][k-j]=='*'); + if(i == j && map[i+1][k-i] == '*') key--; + dp[k+1][i+1][j+1] = max(dp[k+1][i+1][j+1],key); + } + if(map[i+1][k-i] != '#' && map[j][k+1-j] != '#') + { + int key = dp[k][i][j]+(map[i+1][k-i]=='*')+(map[j][k+1-j]=='*'); + if(i+1 == j && map[i+1][k-i] == '*') key--; + dp[k+1][i+1][j] = max(dp[k+1][i+1][j],key); + } + if(map[i][k+1-i] != '#' && map[j+1][k-j] != '#') + { + int key = dp[k][i][j]+(map[i][k+1-i]=='*')+(map[j+1][k-j]=='*'); + if(i == j+1 && map[i][k+1-i] == '*') key--; + dp[k+1][i][j+1] = max(dp[k+1][i][j+1],key); + } + if(map[i][k+1-i] != '#' && map[j][k+1-j] != '#') + { + int key = dp[k][i][j]+(map[i][k+1-i]=='*')+(map[j][k+1-j]=='*'); + if(i == j && map[i][k+1-i] == '*') key--; + dp[k+1][i][j] = max(dp[k+1][i][j],key); + } + } + } + } + if(dp[r+c-2][r-1][r-1] < 0) dp[r+c-2][r-1][r-1] = 0; + printf("%d\n",dp[r+c-2][r-1][r-1]); + } + return 0; +} diff --git a/HDOJ/1950_autoAC.cpp b/HDOJ/1950_autoAC.cpp new file mode 100644 index 0000000..2ed75fb --- /dev/null +++ b/HDOJ/1950_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; +int a[44000]; +int main() +{ + int t; + int m; + int i; + int position; + int n; + int top; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + scanf("%d",&a[0]); + top=0; + for(i=1;ia[top]) + { + top++; + a[top]=m; + } + else + { + position=lower_bound(a,a+top,m)-a; + a[position]=m; + } + } + printf("%d\n",top+1); + } + return 0; +} diff --git a/HDOJ/1951_autoAC.cpp b/HDOJ/1951_autoAC.cpp new file mode 100644 index 0000000..f7e1d46 --- /dev/null +++ b/HDOJ/1951_autoAC.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +const int BORDER = (1<<20)-1; +const int MAXSIZE = 37; +const int MAXN = 250100; +const int INF = 0x4ffffff; +#define CLR(x,y) memset(x,y,sizeof(x)) +#define ADD(x) x=((x+1)&BORDER) +#define IN(x) scanf("%d",&x) +#define OUT(x) printf("%d\n",x) +#define MIN(m,v) (m)<(v)?(m):(v) +#define MAX(m,v) (m)>(v)?(m):(v) +#define ABS(x) (x>0?x:-x) +bitset state[MAXSIZE]; +int n,cur_n; +int init() +{ + int i,j; + for(i = 0; i < MAXSIZE; ++i) + state[i].reset(); + return 0; +} +bool dfs(const int& match,const int& cur,const int& sel, + bitset mask) +{ + if(mask.count() < match) + return false; + else if(sel == match) + return true; + else if(sel + 36 - cur < match) + return false; + return dfs(match,cur+1,sel,mask) || + dfs(match,cur+1,sel+1,mask&state[cur]); +} +int input() +{ + int i,a,b; + IN(n); + for(i = 0; i < n; ++i) + { + scanf("%d%d",&a,&b); + state[a-1].set(b-1); + } + return 0; +} +int work() +{ + int i,j; + bitset mask; + mask.set(); + for(cur_n = 2; cur_n*cur_n <= n&& dfs(cur_n,0,0,mask); ++cur_n) + ; + OUT(cur_n-1); + return 0; +} +int main() +{ + int i,j,tt; + IN(tt); + while(tt--) + { + init(); + input(); + work(); + } + return 0; +} diff --git a/HDOJ/1954_autoAC.cpp b/HDOJ/1954_autoAC.cpp new file mode 100644 index 0000000..fe62b0e --- /dev/null +++ b/HDOJ/1954_autoAC.cpp @@ -0,0 +1,71 @@ +#include +#include +#include +#include +#include +using namespace std; +#define maxn 3005 +struct Tree +{ + int l, r; +} tree[maxn]; +char st1[maxn], st2[maxn], temp[maxn], st[maxn]; +bool operator<(const Tree &a, const Tree &b) +{ + int len = min(a.r - a.l, b.r - b.l); + for (int i =0; i < len; i++) + if (st[a.l + i] != st[b.l + i]) + return st[a.l + i] < st[b.l + i]; + return a.r - a.l < b.r - b.l; +} +void make(int l, int r, Tree *tree) +{ + int zcount =0; + int tcount =0; + int s = l; + for (int i = l; i < r; i++) + { + if (st[i] =='0') + zcount++; + else + zcount--; + if (zcount ==0) + { + make(s +1, i, &tree[tcount]); + tree[tcount].l = s; + tree[tcount].r = i +1; + tcount++; + s = i +1; + } + } + sort(tree, tree + tcount); + s = l; + for (int i =0; i < tcount; i++) + { + for (int j = tree[i].l; j < tree[i].r; j++) + temp[j - tree[i].l + s] = st[j]; + s += tree[i].r - tree[i].l; + } + for (int i = l; i < r; i++) + st[i] = temp[i]; +} +int main() +{ + int t; + scanf("%d", &t); + getchar(); + while (t--) + { + gets(st); + make(0, strlen(st), tree); + strcpy(st1, st); + gets(st); + make(0, strlen(st), tree); + strcpy(st2, st); + if (strcmp(st1, st2) ==0) + printf("same\n"); + else + printf("different\n"); + } + return 0; +} diff --git a/HDOJ/1955_autoAC.cpp b/HDOJ/1955_autoAC.cpp new file mode 100644 index 0000000..644ad7a --- /dev/null +++ b/HDOJ/1955_autoAC.cpp @@ -0,0 +1,84 @@ +#include +#include +using namespace std; +int n,m; +int cnt=0; +typedef struct e{ + int data; + e *next; +}e; +e edge[401]; +int v[401]; +int a[402],b[402]; +int dp[402][402]; +void dfs(int s){ + v[s]=1; + if(s<=n) + a[cnt]++; + else + b[cnt]++; + e *p=edge[s].next; + while(p){ + if(!v[p->data]) + dfs(p->data); + p=p->next; + } +} +void solve(){ + int i,j,k; + memset(dp,0,sizeof(dp)); + dp[0][0]=1; + for(k=1;k<=cnt;k++) + for(i=n/2;i>=a[k];i--) + for(j=n/2;j>=b[k];j--) + dp[i][j]=dp[i][j]||dp[i-a[k]][j-b[k]]; + for(i=n/2;i>=0;i--) + if(dp[i][i]) + break; + cout<>K; + while(K--) + { + cin>>n>>m; + for(i=1;i<=2*n;i++) + { + edge[i].data=i; + edge[i].next=0; + } + for(i=1;i<=m;i++) + { + cin>>j>>k; + e *p=new e; + p->data=k+n; + p->next=edge[j].next; + edge[j].next=p; + e *q=new e; + q->data=j; + q->next=edge[k+n].next; + edge[k+n].next=q; + } + bfs(); + solve(); + } +} +int main(){ + read(); + return 0; +} diff --git a/HDOJ/1956_autoAC.cpp b/HDOJ/1956_autoAC.cpp new file mode 100644 index 0000000..6945e7f --- /dev/null +++ b/HDOJ/1956_autoAC.cpp @@ -0,0 +1,127 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +#define N 205 +#define M 4050 +#define inf 0x3f3f3f3f +struct edge +{ + int v,flow,next; +}; +edge e[M]; +int head[N],total; +int in[N];//搴 +int dis[N]; +void init() +{ + memset(head,-1,sizeof(head)); + memset(in,0,sizeof(in)); + total=0; +} +void add(int u,int v,int val) +{ + e[total].v=v,e[total].flow=val,e[total].next=head[u],head[u]=total++; + e[total].v=u,e[total].flow=0,e[total].next=head[v],head[v]=total++; +} +bool bfs(int st,int en) +{ + memset(dis,0,sizeof(dis)); + queueq; + q.push(st); + dis[st]=1; + while(!q.empty()) + { + int u=q.front();q.pop(); + if(u==en) return true; + for(int i=head[u];i>=0;i=e[i].next) + { + int v=e[i].v; + if(e[i].flow && dis[v]==0) + { + dis[v]=dis[u]+1; + q.push(v); + } + } + } + return false; +} +int dfs(int u,int cur_flow,int en) +{ + if(u==en) return cur_flow; + int sum=0; + for(int i=head[u];i>=0 && sum0 && dis[v]==dis[u]+1) + { + int tmp=dfs(v,min(cur_flow-sum,e[i].flow),en); + e[i].flow-=tmp; + e[i^1].flow+=tmp; + sum+=tmp; + } + } + if(!sum) dis[u]=0; + return sum; +} +int dinic(int st,int en) +{ + int ans=0; + int tmp; + while(bfs(st,en)) + { + while(tmp=dfs(st,inf,en)) + ans+=tmp; + } + return ans; +} +int main() +{ + int tcase,n,m,sum,flag; + int u,v,c; + scanf("%d",&tcase); + while(tcase--) + { + init(); + sum=0; + scanf("%d%d",&n,&m); + while(m--) + { + scanf("%d%d%d",&u,&v,&c); + --in[u],++in[v]; + if(!c) + add(u,v,1); + } + flag=true; + for(int i=1;i<=n;i++) + { + if(in[i]&1) + { + flag=false; + break; + } + } + if(flag) + { + for(int i=1;i<=n;i++) + { + if(in[i]<0) + add(0,i,(-in[i])>>1); + if(in[i]>0) + { + add(i,n+1,in[i]>>1); + sum+=(in[i]>>1); + } + } + flag=(sum==dinic(0,n+1)); + } + if(flag) + puts("possible"); + else + puts("impossible"); + } + return 0; +} diff --git a/HDOJ/1957_autoAC.cpp b/HDOJ/1957_autoAC.cpp new file mode 100644 index 0000000..5554aed --- /dev/null +++ b/HDOJ/1957_autoAC.cpp @@ -0,0 +1,201 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define clr(a) memset(a,0,sizeof(a)); +const int maxsize=1000007,inf=0x7fffffff; +template +void show(T a[],int n){ + for(int i=0;i +void show(const vector& t){ + for(int i=0;i +class hashmap{ +struct hashnode{ +Tk key; +Tv value; +hashnode *next; +}; +hashnode mem[hashsize]; +int mem_end; +hashnode *entry[hashsize]; +hashnode* getmem(){mem_end++; return mem+mem_end-1;} +int culhash(const state& a){ +int h =0; +for(int i=0;inext){ +if(p->key==k){ +v=p->value; +return true; +} +} +return false; +} +bool insert(const Tk& key,const Tv& v){ +if(mem_end>=hashsize)return false; +int h=culhash(key); +hashnode *p=getmem(); +p->key=key;p->value=v;p->next=entry[h]; +entry[h]=p; +return true; +} +}; +hashmap hhh; +int maxstate; +node get(state s){ +sort(s.s,s.s+s.cnt); +state os =s; +node ret ; +if(!hhh.get(s,ret)){ +if(s.cnt==1&&isprime[s.s[0]]){ +s.s[0]--; +ret =get(s); +swap(ret.a,ret.b); +ret.a++; +}else{ +int i,j,k=0,l; +for(i=0;iret.a){ +ret=tmp; +} +} +} +} +} +if(k%2) swap(ret.a,ret.b); +} +ret.a+=k/2+k%2; +ret.b+=k/2; +} +hhh.insert(os,ret); +} +return ret; +} +void test(int n){ +clock_t t0=clock(); +for(int i=2;i>n;n;--n){ +scanf("%d",s.s); +s.cnt=1; +ans =get(s); +printf("%d %d\n",ans.a,ans.b); +} + return 0; +} diff --git a/HDOJ/1959_autoAC.cpp b/HDOJ/1959_autoAC.cpp new file mode 100644 index 0000000..13f3def --- /dev/null +++ b/HDOJ/1959_autoAC.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +typedef __int64 lld; +const int MAX=51; +const int INF=1000000001; +const double PI=acos(-1.0); +const double EPS=1.0e-8; +const int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}}; +bool used[MAX][MAX]; +struct Point +{ + int x,y; +}p[MAX]; +bool ok(int x,int y,int len,int n) +{ + int i,tx,ty; + for(i=0;ilen)return false; + } + return true; +} +int main() +{ + int n,m; + int T; + scanf("%d",&T); + while(T--) + { + scanf("%d%d",&n,&m); + memset(used,false,sizeof(used)); + int i,j; + for(i=0;i +#include +#include +#include +#include +using namespace std; +#define N 510 +struct node{ + int nt; + int cost; + int x1,x2,y1,y2; +}s[N]; +vector g[N]; +int linker[N]; +bool vis[N]; +bool dfs(int u){ + for(int i=0;i +#include +using namespace std; +#define N 60 +#define MM N*N +struct node{ + int next,v; + node(){}; + node(int a,int b){ + next=a;v=b; + } +}E[MM]; +char card1[N][5]; +char card2[N][5]; +map M; +int head[N],NE,pre[N]; +bool h[N]; +void init(){ + NE=0; + for(int i=0;i<=9;i++) + M[i+'0']=i; + M['T']=10;M['J']=11;M['Q']=12; + M['K']=13;M['A']=14; + M['C']=15;M['D']=16; + M['S']=17;M['H']=18; + memset(head,-1,sizeof(head)); + memset(pre,-1,sizeof(pre)); +} +void insert(int u,int v){ + E[NE]=node(head[u],v); + head[u]=NE++; +} +bool dfs(int u){ + for(int i=head[u];i!=-1;i=E[i].next){ + int v=E[i].v; + if(!h[v]){ + h[v]=1; + if(pre[v]==-1||dfs(pre[v])){ + pre[v]=u; + return true; + } + } + } + return false; +} +bool bigger(char *p,char *q){ + if(M[p[0]]==M[q[0]]) + return M[p[1]]>M[q[1]]; + return M[p[0]]>M[q[0]]; +} +int main(void){ + int t; + scanf("%d",&t); + while(t--){ + int n; + init(); + scanf("%d",&n); + for(int i=1;i<=n;i++) + scanf("%s",card1[i]); + for(int i=1;i<=n;i++){ + scanf("%s",card2[i]); + for(int j=1;j<=n;j++) + if(bigger(card2[i],card1[j])) + insert(i,j+n); + } + int cn=0; + for(int i=1;i<=n;i++){ + memset(h,0,sizeof(h)); + if(dfs(i)) + cn++; + } + printf("%d\n",cn); + } +} diff --git a/HDOJ/1963_autoAC.cpp b/HDOJ/1963_autoAC.cpp new file mode 100644 index 0000000..8520a10 --- /dev/null +++ b/HDOJ/1963_autoAC.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +using namespace std; +struct node +{ + int v,w; +}a[20]; +int dp[100000]; +int main() +{ + int t,n,i,j,k,val,y; + scanf("%d",&t); + while(t--) + { + scanf("%d%d",&val,&y); + scanf("%d",&n); + for(i = 1;i<=n;i++) + { + scanf("%d%d",&a[i].v,&a[i].w); + a[i].v/=1000; + } + for(i = 1;i<=y;i++) + { + int s = val/1000; + memset(dp,0,sizeof(dp)); + for(j = 1;j<=n;j++) + { + for(k = a[j].v;k<=s;k++) + { + dp[k]=max(dp[k],dp[k-a[j].v]+a[j].w); + } + } + val+=dp[s]; + } + printf("%d\n",val); + } + return 0; +} diff --git a/HDOJ/1964_autoAC.cpp b/HDOJ/1964_autoAC.cpp new file mode 100644 index 0000000..4682b33 --- /dev/null +++ b/HDOJ/1964_autoAC.cpp @@ -0,0 +1,181 @@ +#include +#include +#include +#include +using namespace std; +const int MAXD=15; +const int HASH=10007; +const int STATE=1000010; +struct Node +{ + int down,right; +}node[MAXD][MAXD]; +int N,M; +int maze[MAXD][MAXD]; +int code[MAXD]; +int ch[MAXD]; +int ex,ey; +struct HASHMAP +{ + int head[HASH],next[STATE],size; + int dp[STATE]; + long long state[STATE]; + void init() + { + size=0; + memset(head,-1,sizeof(head)); + } + void push(long long st,int ans) + { + int i,h=st%HASH; + for(i=head[h];i!=-1;i=next[i]) + if(state[i]==st) + { + if(dp[i]>ans)dp[i]=ans; + return; + } + dp[size]=ans; + state[size]=st; + next[size]=head[h]; + head[h]=size++; + } +}hm[2]; +void decode(int *code,int m,long long st) +{ + for(int i=m;i>=0;i--) + { + code[i]=st&7; + st>>=3; + } +} +long long encode(int *code,int m) +{ + int cnt=1; + memset(ch,-1,sizeof(ch)); + ch[0]=0; + long long st=0; + for(int i=0;i<=m;i++) + { + if(ch[code[i]]==-1)ch[code[i]]=cnt++; + code[i]=ch[code[i]]; + st<<=3; + st|=code[i]; + } + return st; +} +void shift(int *code,int m) +{ + for(int i=m;i>0;i--)code[i]=code[i-1]; + code[0]=0; +} +void dpblank(int i,int j,int cur) +{ + int k,left,up; + for(k=0;k +#include +#include +using namespace std; +#define N 100 +int P,n; +int matrix[N][N],ans[N]; +char str[N]; +void init() +{ + int i,j,k; + for(i = 0; i < n; i++) + if(str[i] == '*') + matrix[i][n] = 0; + else matrix[i][n] = str[i] - 'a' + 1; + for(i = 0; i < n; i++) + { + k = 1; + for(j = 0; j < n; j++) + { + matrix[i][j] = k; + k = (k*(i+1))%P; + } + } +} +int find(int a, int y,int P=100000) +{ + int i; + a = (a%P + P) % P; y = (y%P + P)%P; + for(i = 0; i < P; i++) + if((a*i)%P == y) + return i; +} +void gauss(int P=100000) +{ + int i,j,k; + int row,col; + int a,b,c,sum; + row = 0; col = 0; + while(row < n && col < n) + { + for(i = row, j = -1; i < n; i++) + if(matrix[i][col] != 0) + { + j = i; break; + } + for(i = col; i < n; i++) + { + k = matrix[row][i]; + matrix[row][i] = matrix[j][i]; + matrix[j][i] = k; + } + a = matrix[row][col]; + for(i = row+1; i < n; i++) + { + b = matrix[i][col]; + for(j = col; j <= n; j++) + matrix[i][j] = (matrix[i][j]*a - matrix[row][j]*b)%P; + } + row++; col++; + } + for(i = n-1; i >= 0; i--) + { + sum = 0; + for(j = i+1; j < n; j++) + sum = (sum + matrix[i][j]*ans[j])%P; + ans[i] = find(matrix[i][i],matrix[i][n]-sum,P); + } + for(i = 0; i < n; i++) + { + printf("%d",ans[i]); + if(i == n-1) printf("\n"); + else printf(" "); + } +} +int main() +{ + int i,j,k; + int cases; + scanf("%d",&cases); + while(cases--) + { + scanf("%d %s",&P,str); + n = strlen(str); + init(); + gauss(P); + } + return 0; +} diff --git a/HDOJ/1966_autoAC.cpp b/HDOJ/1966_autoAC.cpp new file mode 100644 index 0000000..cfc7648 --- /dev/null +++ b/HDOJ/1966_autoAC.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#define min(a,b) ((a)<(b)?(a):(b)) +#define max(a,b) ((a)>(b)?(a):(b)) +#define INF 0x3f3f3f3f +const int N = 55; +const double eps = 1e-6; +int t, n; +double dp[N][N]; +struct Point { + double x, y; + void read() { + scanf("%lf%lf", &x, &y); + } +} p[N]; +double area(Point a, Point b, Point c) { + return fabs((b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y)) / 2.0; +} +void init() { + scanf("%d", &n); + for (int i = 0; i < n; i++) + p[i].read(); +} +bool judge(int i, int j, int k) { + double s = area(p[i], p[j], p[k]); + for (int x = 0; x < n; x++) { + if (x == i || x == j || x == k) continue; + double sum = area(p[i], p[j], p[x]) + area(p[i], p[k], p[x]) + area(p[k], p[j], p[x]); + if (fabs(sum - s) < eps) return false; + } + return true; +} +double solve() { + double ans = INF; + for (int len = 2; len < n; len++) { + for (int l = 0; l < n; l++) { + int r = (l + len) % n; + dp[l][r] = INF; + for (int k = (l + 1) % n; k != r; k = (k + 1) % n) { + if (!judge(l, k, r)) continue; + dp[l][r] = min(dp[l][r], max(max(dp[l][k], dp[k][r]), area(p[l], p[k], p[r]))); + } + if (len == n - 1) + ans = min(ans, dp[l][r]); + } + } + return ans; +} +int main() { + scanf("%d", &t); + while (t--) { + init(); + printf("%.1lf\n", solve()); + } + return 0; +} diff --git a/HDOJ/1967_autoAC.cpp b/HDOJ/1967_autoAC.cpp new file mode 100644 index 0000000..71dec97 --- /dev/null +++ b/HDOJ/1967_autoAC.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include +using namespace std; +int b1[9][9], b2[9][9]; +int p3[][3] = { + {0,1,2}, + {0,2,1}, + {1,0,2}, + {1,2,0}, + {2,0,1}, + {2,1,0} +}; +int *colseg, *rowseg; +int *col[3]; +int check3(int r, int *m); +int check4(int r, int *p, int *m) +{ + int i, j, k, l; + int r1, c1, r2, c2; + int v1, v2; + int m2[10]; + memcpy(m2, m, sizeof(int)*10); + for (j = 0; j < 3; j++) + for (k = 0; k < 3; k++) + for (l = 0; l < 3; l++) { + r1 = p[j] + rowseg[r]*3; + c1 = colseg[k]*3 + col[k][l]; + r2 = j + r*3; + c2 = k*3 + l; + v1 = b1[r1][c1]; + v2 = b2[r2][c2]; + if (v2) { + if (!m2[v2]) + m2[v2] = v1; + else if (m2[v2] != v1) + return 0; + } + } + return check3(r + 1, m2); +} +int check3(int r, int *m) +{ + int i; + if (r == 3) + return 1; + for (i = 0; i < 6; i++) + if (check4(r, p3[i], m)) + return 1; + return 0; +} +int check2() +{ + int i, j, k; + for (i = 0; i < 6; i++) + for (j = 0; j < 6; j++) + for (k = 0; k < 6; k++) { + int m[10] = {}; + col[0] = p3[i]; + col[1] = p3[j]; + col[2] = p3[k]; + if (check3(0, m)) + return 1; + } + return 0; +} +int check() +{ + int i, j; + for (i = 0; i < 6; i++) { + for (j = 0; j < 6; j++) { + colseg = p3[i]; + rowseg = p3[j]; + if (check2()) + return 1; + } + } + return 0; +} +int solve() +{ + int i, j, b[9][9]; + if (check()) + return 1; + for (i = 0; i < 9; i++) + for (j = 0; j < 9; j++) + b[i][j] = b1[8-j][i]; + memcpy(b1, b, sizeof(b)); + return check(); +} +int main() +{ + int T, i; + scanf("%d", &T); + for (; T--; ) { + for (i = 0; i < 81; ++i) scanf(" %1d", b1[i/9]+i%9); + for (i = 0; i < 81; ++i) scanf(" %1d", b2[i/9]+i%9); + printf(solve() ? "Yes\n" : "No\n"); + } + return 0; +} diff --git a/HDOJ/1969_autoAC.cpp b/HDOJ/1969_autoAC.cpp new file mode 100644 index 0000000..01e4c85 --- /dev/null +++ b/HDOJ/1969_autoAC.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#define pi acos(-1.0) +#define eps 1e-7 +int main() +{ + int n,t,f,i,r,pep; + double s[10005]; + double max,min,mid; + scanf("%d",&t); + while(t--) + { + min=0;max=0; + scanf("%d%d",&n,&f); + f++; + for(i=0; ieps) + { + mid=(max+min)/2; + pep=0; + for(i=0;i=f) + min=mid; + else + max=mid; + } + printf("%.4lf\n",mid); + } +return 0; +} diff --git a/HDOJ/1970_autoAC.cpp b/HDOJ/1970_autoAC.cpp new file mode 100644 index 0000000..1b2f886 --- /dev/null +++ b/HDOJ/1970_autoAC.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include +using namespace std; +int main() +{ + int INF=99999999,N,K,d[30][30],i,j,k,x,y,z,dp[256][30],e[8],v[30],c,b; + string s,t; + while (cin >> N >> K && N) { + map cityMap; + for(i=0;i> s; + cityMap[s]=i; + } + if (K) + while(cin >> s >> t >> z, x=cityMap[s], + y=cityMap[t], + d[x][y]=d[y][x]=min(d[y][x],z), --K); + for(k=0;k> s; + e[i]=cityMap[s]; + for(j=0;j>k&3)==j) + y+=3< +#include +#include +#include +using namespace std; +#define N 71 +#define M 31 +#define Max 999999 +int dp[N*M][N*M]; +struct Book +{ + int h, w; +}; +int cmp(Book x, Book y) +{ + if(x.h!=y.h) + return x.h>y.h; + return x.w=0; j--) + { + for(k=noww; k>=0; k--) + { + if(dp[j][k]==Max) + continue; + if(noww-j-k<0) + continue; + int a=0; + if(j==0) + a=book[i].h; + dp[j+book[i].w][k]=min(dp[j+book[i].w][k], dp[j][k]+a); + a=0; + if(k==0) + a=book[i].h; + dp[j][k+book[i].w]=min(dp[j][k+book[i].w], dp[j][k]+a); + } + } + noww+=book[i].w; + } + int minnum=Max; + for(j=1; j<=noww; j++) + { + for(k=1; k<=noww; k++) + { + if(dp[j][k]==Max) + continue; + if(sum-j-k<=0) + continue; + int maxw=max(j, k); + maxw=max(maxw, sum-j-k); + minnum=min(minnum, maxw*(dp[j][k]+book[1].h)); + } + } + printf("%d\n", minnum); + } +} diff --git a/HDOJ/1972_autoAC.cpp b/HDOJ/1972_autoAC.cpp new file mode 100644 index 0000000..5e80749 --- /dev/null +++ b/HDOJ/1972_autoAC.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +using namespace std; +struct point +{ + int pla, num; +}; +int cmp(int x, int y) +{ + return x>y; +} +int main() +{ + int T, i, n, m; + scanf("%d", &T); + while(T--) + { + point p[105]; + int a[105]; + queueQ; + scanf("%d%d", &n, &m); + for(i=0; i +#include +#include +#include +#include +using namespace std; +struct item +{ + int num[4]; +} a, b; +int prime[100], primenum, cost[10000]; +int toint(item &a) +{ + int ans = 0; + for (int i = 0; i < 4; i++) + ans = ans * 10 + a.num[i]; + return ans; +} +void makeprime() +{ + primenum = 1; + prime[0] = 2; + for (int i = 3; i < 100; i++) + { + bool ok = true; + for (int j = 0; prime[j] * prime[j] <= i; j++) + if (i % prime[j] == 0) + { + ok = false; + break; + } + if (ok) + { + prime[primenum++] = i; + } + } +} +void init() +{ + memset(cost, -1, sizeof(cost)); + for (int i = 0; i < 4; i++) + { + char ch; + scanf("%c", &ch); + a.num[i] = ch - '0'; + } + getchar(); + for (int i = 0; i < 4; i++) + { + char ch; + scanf("%c", &ch); + b.num[i] = ch - '0'; + } + getchar(); +} +bool isprime(int a) +{ + for (int i = 0; i < primenum && prime[i] * prime[i] <= a; i++) + if (a % prime[i] == 0) + return false; + return true; +} +void work() +{ + cost[toint(a)] = 0; + queue q; + q.push(a); + while (!q.empty()) + { + item temp = q.front(); + int costnow = cost[toint(temp)]; + q.pop(); + for (int i = 0; i < 4; i++) + { + int x = temp.num[i]; + for (int j = 0; j < 10; j++) + { + if (i == 0 && j == 0) + continue; + if (j == x) + continue; + temp.num[i] = j; + int inttemp = toint(temp); + if (cost[inttemp] == -1 && isprime(inttemp)) + { + cost[inttemp] = costnow + 1; + if (inttemp == toint(b)) + { + printf("%d\n", cost[inttemp]); + return; + } + q.push(temp); + } + } + temp.num[i] = x; + } + } +} +int main() +{ + int t; + makeprime(); + scanf("%d", &t); + getchar(); + while (t--) + { + init(); + if (toint(a) == toint(b)) + printf("0\n"); + work(); + } + return 0; +} diff --git a/HDOJ/1975_autoAC.cpp b/HDOJ/1975_autoAC.cpp new file mode 100644 index 0000000..b649670 --- /dev/null +++ b/HDOJ/1975_autoAC.cpp @@ -0,0 +1,44 @@ +#include +#include +#include +#include +using namespace std; +char str[30]; +bool vis[30]; +int cnt[30]; +bool confirm(){ + bool flag=true; + for(int i=1;i<=26;i++) + if(i%2==0){ + if(cnt[i]%2){ + flag=false; + break; + } + } + return flag; +} +int main(){ + int T,cnted; + scanf("%d",&T); + while(T--){ + scanf("%s",str); + memset(vis,false,sizeof(vis)); + memset(cnt,0,sizeof(cnt)); + for(int i=0;i<26;i++){ + if(!vis[i]){ + int k=i; + cnted=0; + while(!vis[k]){ + vis[k]=true; + k=str[k]-'A'; + cnted++; + } + cnt[cnted]++; + } + } + if(confirm()) + printf("Yes\n"); + else printf("No\n"); + } + return 0; +} diff --git a/HDOJ/1976_autoAC.cpp b/HDOJ/1976_autoAC.cpp new file mode 100644 index 0000000..800ffa5 --- /dev/null +++ b/HDOJ/1976_autoAC.cpp @@ -0,0 +1,24 @@ +#include +int main() +{ + int a[6],i,t; + scanf("%d",&t); + while(t--) + { + for(i=0;i<6;i++) + scanf("%d",&a[i]); + for(i=0;i<3;i++) + { + if(a[i]>a[i+3]) + { + printf("First\n"); + break; + }else if(a[i] +#include +#include +using namespace std; +typedef long long LL; +const int MS=1001; +int main() +{ + LL n; + int T; + cin>>T; + while(T--) + { + cin>>n; + cout< +#include +int main() +{ + int T,i,j,ii,jj,n,m,mark[105][105],dp[105][105],t,sum; + scanf("%d",&T); + while(T--) + { + memset(mark,0,sizeof(mark)); + scanf("%d%d",&n,&m); + for(i=1;i<=n;i++) + for(j=1;j<=m;j++) + scanf("%d",&dp[i][j]); + mark[1][1]=1; + for(i=1;i<=n;i++) + for(j=1;j<=m&&!(i==n&&j==m);j++) + { + t=dp[i][j];sum=mark[i][j]%10000; + for(ii=i;ii<=i+t&&ii<=n;ii++) + for(jj=j;jj<=j+t-ii+i&&jj<=m;jj++) + mark[ii][jj]+=sum; + } + printf("%d\n",mark[n][m]%10000); + } +} diff --git a/HDOJ/1979_autoAC.cpp b/HDOJ/1979_autoAC.cpp new file mode 100644 index 0000000..f0cea03 --- /dev/null +++ b/HDOJ/1979_autoAC.cpp @@ -0,0 +1,9 @@ +#include +#include +#include +using namespace std; +int main() +{ + string s="1193\n1009\n9221\n3191\n\n1193\n1021\n9029\n3911\n\n1193\n1201\n9209\n3911\n\n1193\n1229\n9001\n3191\n\n1193\n7043\n3697\n3911\n\n1193\n7253\n3821\n3319\n\n1193\n7253\n3851\n3319\n\n1193\n7457\n3821\n3719\n\n1193\n7963\n3407\n3911\n\n1193\n9001\n1229\n3191\n\n1193\n9011\n1669\n3911\n\n1193\n9013\n1669\n3911\n\n1193\n9029\n1021\n3911\n\n1193\n9041\n1399\n3371\n\n1193\n9209\n1201\n3911\n\n1193\n9221\n1009\n3191\n\n1193\n9257\n3821\n3319\n\n1193\n9257\n3851\n3319\n\n1193\n9479\n1381\n3917\n\n1193\n9661\n1109\n3911\n\n1193\n9661\n3109\n3911\n\n1193\n9923\n1009\n3191\n\n1733\n1069\n9491\n3371\n\n1733\n1283\n9521\n3319\n\n1733\n1283\n9551\n3319\n\n1733\n1487\n9521\n3719\n\n1733\n1949\n9601\n3371\n\n1733\n9227\n1021\n3719\n\n1733\n9931\n1409\n3911\n\n1913\n1009\n9221\n3911\n\n1913\n1021\n9029\n3191\n\n1913\n1033\n9497\n3191\n\n1913\n1069\n9161\n3191\n\n1913\n1069\n9161\n3391\n\n1913\n1201\n9209\n3191\n\n1913\n1229\n9001\n3911\n\n1913\n1439\n9781\n3917\n\n1913\n1619\n9601\n3191\n\n1913\n1901\n9209\n3391\n\n1913\n7207\n3221\n3719\n\n1913\n7949\n3301\n3191\n\n1913\n9001\n1229\n3911\n\n1913\n9001\n3299\n3911\n\n1913\n9029\n1021\n3191\n\n1913\n9173\n3389\n3391\n\n1913\n9209\n1201\n3191\n\n1913\n9221\n1009\n3911\n\n1933\n1283\n9521\n3719\n\n1933\n1283\n9551\n3719\n\n1933\n1619\n9601\n3191\n\n1933\n9029\n1091\n3191\n\n1933\n9133\n1789\n3391\n\n1933\n9833\n3719\n3191\n\n1933\n9871\n3319\n3391\n\n3191\n1009\n9221\n1193\n\n3191\n1009\n9923\n1193\n\n3191\n1021\n9029\n1913\n\n3191\n1091\n9029\n1933\n\n3191\n1201\n9209\n1913\n\n3191\n1229\n9001\n1193\n\n3191\n3301\n7949\n1913\n\n3191\n3719\n9833\n1933\n\n3191\n7027\n1223\n9173\n\n3191\n9001\n1229\n1193\n\n3191\n9029\n1021\n1913\n\n3191\n9161\n1069\n1913\n\n3191\n9209\n1201\n1913\n\n3191\n9221\n1009\n1193\n\n3191\n9341\n1879\n7193\n\n3191\n9497\n1033\n1913\n\n3191\n9601\n1619\n1913\n\n3191\n9601\n1619\n1933\n\n3319\n3821\n7253\n1193\n\n3319\n3821\n9257\n1193\n\n3319\n3851\n7253\n1193\n\n3319\n3851\n9257\n1193\n\n3319\n9521\n1283\n1733\n\n3319\n9551\n1283\n1733\n\n3371\n1399\n9041\n1193\n\n3371\n3821\n1259\n9133\n\n3371\n3821\n1559\n9133\n\n3371\n7229\n1201\n9173\n\n3371\n7841\n1259\n9173\n\n3371\n9491\n1069\n1733\n\n3371\n9601\n1949\n1733\n\n3391\n1789\n9133\n1933\n\n3391\n3319\n9871\n1933\n\n3391\n3389\n9173\n1913\n\n3391\n3821\n1259\n9173\n\n3391\n3821\n1559\n9173\n\n3391\n9161\n1069\n1913\n\n3391\n9209\n1901\n1913\n\n3719\n1021\n9227\n1733\n\n3719\n3221\n7207\n1913\n\n3719\n3821\n7457\n1193\n\n3719\n9521\n1283\n1933\n\n3719\n9521\n1487\n1733\n\n3719\n9551\n1283\n1933\n\n3911\n1009\n9221\n1913\n\n3911\n1021\n9029\n1193\n\n3911\n1109\n9661\n1193\n\n3911\n1201\n9209\n1193\n\n3911\n1229\n9001\n1913\n\n3911\n1409\n9931\n1733\n\n3911\n1669\n9011\n1193\n\n3911\n1669\n9013\n1193\n\n3911\n3109\n9661\n1193\n\n3911\n3299\n9001\n1913\n\n3911\n3407\n7963\n1193\n\n3911\n3527\n1283\n9133\n\n3911\n3527\n1583\n9133\n\n3911\n3697\n7043\n1193\n\n3911\n7529\n1283\n9133\n\n3911\n7529\n1583\n9133\n\n3911\n7547\n1283\n9173\n\n3911\n9001\n1229\n1913\n\n3911\n9029\n1021\n1193\n\n3911\n9209\n1201\n1193\n\n3911\n9221\n1009\n1913\n\n3911\n9749\n1831\n7193\n\n3917\n1381\n9479\n1193\n\n3917\n9781\n1439\n1913\n\n7193\n1831\n9749\n3911\n\n7193\n1879\n9341\n3191\n\n9133\n1259\n3821\n3371\n\n9133\n1283\n3527\n3911\n\n9133\n1283\n7529\n3911\n\n9133\n1559\n3821\n3371\n\n9133\n1583\n3527\n3911\n\n9133\n1583\n7529\n3911\n\n9173\n1201\n7229\n3371\n\n9173\n1223\n7027\n3191\n\n9173\n1259\n3821\n3391\n\n9173\n1259\n7841\n3371\n\n9173\n1283\n7547\n3911\n\n9173\n1559\n3821\n3391"; + cout< +#include +#include +#include +#include +int main() +{ + int T, i, n, len, a, b, temp,j, k; + char str[28] = "bcdefghijklmnopqrstuvwxyza", ch[2], letter[90010]; + scanf("%d",&T); + while(T--) + { + scanf("%d%d%s",&len,&n,letter + 1); + for(i = 0;i < n; i++) + { + scanf("%s",ch); + if(ch[0] == 'Q') + { + scanf("%d",&a); + printf("%c\n",letter[a]); + } + else if(ch[0] == 'R') + { + scanf("%d%d",&a,&b); + for(j = a, k = b;j <= k; j++, k-- ){ + temp = letter[j], letter[j] = letter[k], letter[k] = temp;} + } + else if(ch[0] == 'S') + { + scanf("%d%d",&a,&b); + for(j = a; j <= b; j++) + { + letter[j] = str[letter[j] - 'a']; + } + } + } + } + return 0; +} diff --git a/HDOJ/1982_autoAC.cpp b/HDOJ/1982_autoAC.cpp new file mode 100644 index 0000000..3f6ce07 --- /dev/null +++ b/HDOJ/1982_autoAC.cpp @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +using namespace std; +void process(string s) +{ + replace(s.begin(),s.end(),'-',' '); + stringstream m(s); + int t; + while(m>>t) + { + cout<<(char)('A'+t-1); + } +} +void run() +{ + string s,t=""; + cin>>s; + for(int i=0; i>T; + while(T--) run(); + return 0; +} diff --git a/HDOJ/1983_autoAC.cpp b/HDOJ/1983_autoAC.cpp new file mode 100644 index 0000000..171bc07 --- /dev/null +++ b/HDOJ/1983_autoAC.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include +using namespace std; +typedef struct S { + int order, time, J; +} STEP; +char map[100], s[10]; +int m, n, start; +int dx[] = {0, 0, 1, -1}; +int dy[] = {1, -1, 0, 0}; +int vis[2][100]; +int t; +int bfs() { + int k, i, j, xx, yy, temp; + STEP now, next; + now.order = start; + now.time = 0; + now.J = 0; + queue q; + memset(vis, 0, sizeof (vis)); + vis[0][start] = 1; + q.push(now); + while (!q.empty()) { + now = q.front(); + q.pop(); + if (now.time >= t) + continue; + i = now.order / n; + j = now.order % n; + for (k = 0; k < 4; ++k) { + xx = i + dx[k]; + yy = j + dy[k]; + temp = xx * n + yy; + next.time = now.time + 1; + if (xx >= 0 && xx < m && yy >= 0 && yy < n) { + if (map[temp] == 'E') { + if (now.J) + return 0; + } + if (map[temp] != '#') { + if (map[temp] == 'J') + next.J = 1; + else + next.J = now.J; + if (!vis[now.J][temp]) { + vis[now.J][temp] = 1; + next.order = temp; + q.push(next); + } + } + } + } + } + return 1; +} +int main() { + int i, j, jd, T, ans; + scanf("%d", &T); + while (T--) { + scanf("%d%d%d", &m, &n, &t); + scanf("%*c"); + jd = 0; + for (i = 0; i < m; ++i) { + scanf("%s", s); + for (j = 0; j < n; ++j) { + map[jd + j] = s[j]; + if (s[j] == 'S') + start = jd + j; + } + jd += n; + } + int k; + if (bfs()) { + ans = 0; + goto L; + } + char ch[3]; + for (i = 0; i < m * n; ++i) { + if (map[i] == '#' || map[i] == 'S' || map[i] == 'E') { + continue; + } + ch[0] = map[i]; + map[i] = '#'; + if (bfs()) { + ans = 1; + goto L; + } + map[i] = ch[0]; + } + for (i = 0; i < m * n; ++i) { + if (map[i] == '#' || map[i] == 'S' || map[i] == 'E') { + continue; + } + ch[0] = map[i]; + map[i] = '#'; + for (j = i + 1; j < m * n; ++j) { + if (map[j] == '#' || map[j] == 'S' || map[j] == 'E') { + continue; + } + ch[1] = map[j]; + map[j] = '#'; + if (bfs()) { + ans = 2; + goto L; + } + map[j] = ch[1]; + } + map[i] = ch[0]; + } + for (i = 0; i < m * n; ++i) { + if (map[i] == '#' || map[i] == 'S' || map[i] == 'E') { + continue; + } + ch[0] = map[i]; + map[i] = '#'; + for (j = i + 1; j < m * n; ++j) { + if (map[j] == '#' || map[j] == 'S' || map[j] == 'E') { + continue; + } + ch[1] = map[j]; + map[j] = '#'; + for (k = j + 1; k < m * n; ++k) { + if (map[k] == '#' || map[k] == 'S' || map[k] == 'E') { + continue; + } + ch[2] = map[k]; + map[k] = '#'; + if (bfs()) { + ans = 3; + goto L; + } + map[k] = ch[2]; + } + map[j] = ch[1]; + } + map[i] = ch[0]; + } + ans = 4; +L: + printf("%d\n", ans); + } + return 0; +} diff --git a/HDOJ/1984_autoAC.cpp b/HDOJ/1984_autoAC.cpp new file mode 100644 index 0000000..ad89453 --- /dev/null +++ b/HDOJ/1984_autoAC.cpp @@ -0,0 +1,22 @@ +#include +#include +int main() +{ + int tot=0,t,i,n,len; + char a[100]; + scanf("%d",&n); + getchar(); + while(n--) + { + tot++; + scanf("%d",&t); + getchar(); + gets(a); + len=strlen(a); + printf("%d ",tot); + for(i=0;i +#include +int main() +{ + double n; + int t,i; + char a[3]; + scanf("%d",&t); + i=1; + while(t--) + { + scanf("%lf %s",&n,a); + if(strcmp(a,"kg")==0) + printf("%d %.4lf lb\n",i,n*2.2046); + else if(strcmp(a,"lb")==0) + printf("%d %.4lf kg\n",i,n*0.4536); + else if(strcmp(a,"l")==0) + printf("%d %.4lf g\n",i,n*0.2642); + else if(strcmp(a,"g")==0) + printf("%d %.4lf l\n",i,n*3.7854); + i++; + } +} diff --git a/HDOJ/1986_autoAC.cpp b/HDOJ/1986_autoAC.cpp new file mode 100644 index 0000000..0271ead --- /dev/null +++ b/HDOJ/1986_autoAC.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +using namespace std; +const char biao[27][6]={{"00000"},{"00001"},{"00010"},{"00011"},{"00100"},{"00101"},{"00110"},{"00111"},{"01000"},{"01001"},{"01010"},{"01011"},{"01100"},{"01101"},{"01110"},{"01111"},{"10000"},{"10001"},{"10010"},{"10011"},{"10100"},{"10101"},{"10110"},{"10111"},{"11000"},{"11001"},{"11010"}}; +int map[30][30]; +string s; +bool m[1000]; +int main() +{ + int T,r,c; + scanf("%d",&T); + for(int t=1;t<=T;t++) + { + memset(m,0,sizeof(m)); + memset(map,-1,sizeof(map)); + scanf("%d%d",&r,&c); + getchar(); + getline(cin,s); + int sum=0; + for( int i = 0; s[i]!='\0' ; i++ ) + { + int k=0; + if(s[i]>='A' && s[i]<='Z') k=(int)(s[i]-'A')+1; + for(int j=0;j<5;j++){ + m[++sum] = biao[k][j]-'0'; + } + } + int tot=0,x,y; + x=0;y=0; + map[0][0] = m[++tot]; + while( tot < sum ) + { + while(y+1=0&& map[x][y-1]==-1) map[x][--y] = m[++tot]; + while(x-1>=0&& map[x-1][y]==-1) map[--x][y] = m[++tot]; + } + printf("%d ",t); + for(int i=0;i +#include +#include +using namespace std; +typedef pair P; +const int dx[] = {0 , 1 , 0 , -1} , dy[] = {1 , 0 , -1 , 0}; +const int MAX = 30; +int array[MAX][MAX]; +int main() +{ + int t; + cin >> t; + for(int s = 1; s <= t; ++s) + { + int r , c; + string cipher; + cin >> r >> c >> cipher; + fill(*array , *array + MAX * MAX , -1); + size_t cnt = 0; + for(int i = 0; cnt < cipher.size() && i < r; ++i) + for(int j = 0; cnt < cipher.size() && j < c; ++j) + {array[i][j] = cipher[cnt ++] - '0';} + //decode + cout << s << ' '; + P pos(0 , 0); + int direc = 0; + string decode; + for(int i = 1; i <= (r * c / 5); ++i) + { + int val = 0; + for(int k = 1; k <= 5; ++k) + { + int x = pos.first , y = pos.second; + if(array[x][y] == -1 || x < 0 || x >= r || y < 0 || y >= c) + { + int px = x + dx[direc] , py = y + dy[direc]; + while(array[px][py] == -1 || px < 0 || px >= r || py < 0 || py >= c) + { + ++direc; + direc %= 4; + px = x + dx[direc] , py = y + dy[direc]; + } + x = px;y = py; + } + val = 2 * val + array[x][y]; + array[x][y] = -1; + pos.first = x;pos.second = y; + } + if(val == 0) + {decode += ' ';} + else{decode += static_cast(val - 1 + 'A');} + } + int end = decode.size() - 1; + while(decode[end] == ' '){--end;} + for(int i = 0; i <= end; ++i){cout << decode[i];} + cout << endl; + } + return 0; +} diff --git a/HDOJ/1988_autoAC.cpp b/HDOJ/1988_autoAC.cpp new file mode 100644 index 0000000..68c7140 --- /dev/null +++ b/HDOJ/1988_autoAC.cpp @@ -0,0 +1,72 @@ +#include +#include +int a[47]; +void reserve (int pos) +{ + int tt; + for(int i = 1, j = pos; i < j; i++,j--) + { + tt = a[i],a[i] = a[j],a[j] = tt; + } + for(int i = 1; i <= pos; i++) + { + a[i] = -a[i]; + } +} +int main() +{ + int t; + int n; + int cas = 0; + int b[147]; + scanf("%d",&t); + while(t--) + { + int k = 0; + scanf("%d",&n); + for(int i = 1; i <= n; i++) + { + scanf("%d",&a[i]); + } + int p = 0; + for(int i = n; i >= 1; i--) + { + if(a[i] == i) + continue; + for(int j = 1; j <= n; j++) + { + if(fabs(a[j]) == i) + { + p = j; + } + } + if(p != 1) + { + reserve(p); + b[k++] = p; + } + if(a[1] > 0) + { + a[1] = -a[1]; + b[k++] = 1; + } + if(i != 1) + { + b[k++] = i; + reserve(i); + } + else + { + b[k++] = 1; + a[1] = -a[1]; + } + } + printf("%d %d",++cas,k); + for(int i = 0; i < k; i++) + { + printf(" %d",b[i]); + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1990_autoAC.cpp b/HDOJ/1990_autoAC.cpp new file mode 100644 index 0000000..10bfc72 --- /dev/null +++ b/HDOJ/1990_autoAC.cpp @@ -0,0 +1,29 @@ +#include +#include +int main() +{ + int t; + int cas = 0; + char s[1117]; + scanf("%d",&t); + getchar(); + while(t--) + { + //scanf("%s",s); + gets(s); + int len = strlen(s); + int k = 0; + int maxx = 0; + for(int i = 0; i < len; i++) + { + if(s[i] == '[') + k++; + else + k--; + if(k > maxx) + maxx = k; + } + printf("%d %d\n",++cas,1< +int dp[25] = {1,1,5,11} ; +int main () +{ + int T, i, nCase = 1, n; + for(i = 4 ; i <= 22 ; i++) + dp[i] = dp[i-1]+dp[i-2]*5+dp[i-3]-dp[i-4] ; + scanf ("%d", &T) ; + while (T--) + { + scanf ("%d", &n) ; + printf ("%d %d\n", nCase++, dp[n]) ; + } + return 0 ; +} diff --git a/HDOJ/1993_autoAC.cpp b/HDOJ/1993_autoAC.cpp new file mode 100644 index 0000000..0cf06f6 --- /dev/null +++ b/HDOJ/1993_autoAC.cpp @@ -0,0 +1,145 @@ +#include +#include +using namespace std; + class face + { + public: + char C; + int dir; + void rotate(int k) + { + dir = (dir + k) % 4; + } + }; + class state + { + public: + face link[4]; + face mid; + public: + void rotate() + { + mid.rotate(1); + face temp = link[3]; + for (int i = 3; i > 0; i--) + link[i] = link[i-1]; + link[0] = temp; + for (int i = 0; i < 4; i++) + link[i].rotate(1); + } + bool Compare(state a) + { + if (mid.C != a.mid.C || mid.dir != a.mid.dir) return false; + for (int i = 0; i < 4; i++) + { + if (a.link[i].C == '*' || (a.link[i].C == link[i].C && a.link[i].dir == link[i].dir)) continue; + return false; + } + return true; + } + }; + face cube[6]; + state P[6]; + bool Find(state ans) + { + for (int i = 0; i < 6; i++) + { + for (int j = 0; j < 4; j++) + { + ans.rotate(); + if (P[i].Compare(ans)) return true; + } + } + return false; + } + int main() + { + int T; + scanf("%d", &T); + getchar(); + for (int ctr = 1; ctr <= T; ctr++) + { + vector ret; + ret.clear(); + int tot = 0; + for (int i = 0; i < 6; i++) + { + char ch; + int d; + scanf("%c%d", &ch, &d); + d--; + cube[i].C = ch; + cube[i].dir = d; + } + getchar(); + P[0].mid = cube[0]; + P[0].link[0] = cube[4],P[0].link[0].rotate(2); + P[0].link[1] = cube[3],P[0].link[1].rotate(3); + P[0].link[2] = cube[2]; + P[0].link[3] = cube[1],P[0].link[3].rotate(1); + P[1].mid = cube[1]; + P[1].link[0] = cube[0],P[1].link[0].rotate(3); + P[1].link[1] = cube[2]; + P[1].link[2] = cube[5],P[1].link[2].rotate(1); + P[1].link[3] = cube[4]; + P[2].mid = cube[2]; + P[2].link[0] = cube[0]; + P[2].link[1] = cube[3]; + P[2].link[2] = cube[5]; + P[2].link[3] = cube[1]; + P[3].mid = cube[3]; + P[3].link[0] = cube[0],P[3].link[0].rotate(1); + P[3].link[1] = cube[4]; + P[3].link[2] = cube[5],P[3].link[2].rotate(3); + P[3].link[3] = cube[2]; + P[4].mid = cube[4]; + P[4].link[0] = cube[0],P[4].link[0].rotate(2); + P[4].link[1] = cube[1]; + P[4].link[2] = cube[5],P[4].link[2].rotate(2); + P[4].link[3] = cube[3]; + P[5].mid = cube[5]; + P[5].link[0] = cube[2]; + P[5].link[1] = cube[3],P[5].link[1].rotate(1); + P[5].link[2] = cube[4],P[5].link[2].rotate(2); + P[5].link[3] = cube[1],P[5].link[3].rotate(3); + for (int i = 0; i < 5; i++) + { + state ans; + for (int j = 0; j < 3; j++) + { + char ch; + int d; + scanf("%c%d", &ch, &d); + d--; + if (j == 0) + { + ans.mid.C = ch; + ans.mid.dir = d; + } + else + { + ans.link[j].C = ch; + ans.link[j].dir = d; + } + } + getchar(); + ans.mid.rotate (2); + ans.link[1].rotate(3); + ans.link[2].rotate(1); + ans.link[0].C = '*'; + ans.link[3].C = '*'; + if (Find(ans)) tot+=1, ret.push_back(1); + else + ret.push_back(0); + } + printf("%d ", ctr); + printf("%d", tot); + for (int i = 0; i < 5; i++) + if (ret[i]) + printf(" Y"); + else + printf(" N"); + printf("\n"); + } + return 0; + } diff --git a/HDOJ/1994_autoAC.cpp b/HDOJ/1994_autoAC.cpp new file mode 100644 index 0000000..6e774d8 --- /dev/null +++ b/HDOJ/1994_autoAC.cpp @@ -0,0 +1,17 @@ +#include +int main() +{ + int T,q; + double y,e,f,g; + scanf("%d",&T); + while(T--) + { + scanf("%lf%d%lf%lf%lf",&y,&q,&e,&f,&g); + double sum1=y*(1+(f*(q+365))/36500); + double sum2; + sum2=y*(1+(e*q)/36500); + sum2=sum2*(1+g/100); + printf("%.1lf\n%.1lf\n",sum2,sum1); + } + return 0; +} diff --git a/HDOJ/1995_autoAC.cpp b/HDOJ/1995_autoAC.cpp new file mode 100644 index 0000000..bac75c8 --- /dev/null +++ b/HDOJ/1995_autoAC.cpp @@ -0,0 +1,11 @@ +#include +int main() +{ + int t,n,k; + scanf("%d",&t); + while(t--){ + scanf("%d%d",&n,&k); + printf("%I64d\n",1LL< +long long save[30]={1}; +void work() +{ + for(int i=1;i<30;i++) + save[i]=save[i-1]*3; +} +int main() +{ + int test,n; + work(); + scanf("%d",&test); + while(test--) + { + scanf("%d",&n); + printf("%I64d\n",save[n]); + } + return 0; +} diff --git a/HDOJ/1997_autoAC.cpp b/HDOJ/1997_autoAC.cpp new file mode 100644 index 0000000..64ba704 --- /dev/null +++ b/HDOJ/1997_autoAC.cpp @@ -0,0 +1,46 @@ +#include +#include +using namespace std; +int main() +{ + int t, n, i, j, x, m, p, q, num; + bool flag = 1; + cin >> t; + while(t--) + { + flag = 1; + cin >> n; + x = n % 2; + cin >> m; + while(m--) + { + cin >> num; + if( num % 2 != x ) + flag = 0; + x ^= 1; + } + x = n % 2; + cin >> p; + while( p -- ) + { + cin >> num; + x ^= 1; + if( num % 2 != x ) + flag = 0; + } + x = n % 2; + cin >> q; + while( q -- ) + { + cin >> num; + if( num % 2 != x ) + flag = 0; + x ^= 1; + } + if( flag ) + cout << "true" << endl; + else + cout << "false" << endl; + } + return 0; +} diff --git a/HDOJ/1998_autoAC.cpp b/HDOJ/1998_autoAC.cpp new file mode 100644 index 0000000..7170259 --- /dev/null +++ b/HDOJ/1998_autoAC.cpp @@ -0,0 +1,13 @@ +#include +int main(){ + int n,m,i,j; + scanf("%d",&n); + while(n-->0){ + scanf("%d",&m); + for(i=0;i +using namespace std; +bool f(int n) +{ + for(int i=2;i<=n/2;i++) + if(n%i==0) + return false; + return true; +} +int main() +{ + int T; + cin>>T; + while(T--) + { + int i,n,x; + cin>>n; + if(n==2||n==5)cout<<"yes"<