Powered By HC TECH : AutoACer Engine

1900-1999
This commit is contained in:
KiritoTRw 2016-08-19 10:57:19 +08:00 committed by GitHub
parent e71b430537
commit bd4f730b16
71 changed files with 4282 additions and 0 deletions

45
HDOJ/1901_autoAC.cpp Normal file
View File

@ -0,0 +1,45 @@
#include<stdio.h>
#include<string.h>
#include<iostream>
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;
}

39
HDOJ/1902_autoAC.cpp Normal file
View File

@ -0,0 +1,39 @@
#include <iostream>
#include <cstdio>
#include <algorithm>
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!"<<std::endl;
continue;
}
std::sort(d,d+n);
std::sort(a,a+m);
int tot = 0;
int i = 0,j=0;
while(i<n&&j<m)
{
if(a[j]>=d[i]){
tot += a[j];
j++,i++;
}else
{
j++;
}
}
if(i>=n)
std::cout<<tot<<std::endl;
else
std::cout<<"Loowater is doomed!"<<std::endl;
}
return 0;
}

33
HDOJ/1903_autoAC.cpp Normal file
View File

@ -0,0 +1,33 @@
#include<iostream>
#include<math.h>
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;
}

40
HDOJ/1904_autoAC.cpp Normal file
View File

@ -0,0 +1,40 @@
#include<stdio.h>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;
int s[10001][6];
int main()
{
int n,i,j,sum,max,num;
map<string,int>::iterator it;
map<string,int>ans;
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;
}

41
HDOJ/1905_autoAC.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <iostream>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
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;
}

21
HDOJ/1907_autoAC.cpp Normal file
View File

@ -0,0 +1,21 @@
#include<stdio.h>
int main()
{
int temp,t,n,s,x,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=s=temp=0;i<n;i++)
{
scanf("%d",&x);
if(x>1) temp=1;
s^=x;
}
if((s&&temp)||(!s&&!temp))
puts("John");
else
puts("Brother");
}
return 0;
}

50
HDOJ/1908_autoAC.cpp Normal file
View File

@ -0,0 +1,50 @@
#include<iostream>
#include<set>
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<a.p;
}
};
int main()
{
int com,k,p;
set<node> 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<<endl;
else
{
cout<<(*(--s.end())).num<<endl;
s.erase(--s.end());
}
}break;
case 3:
{
if(s.empty())
cout<<0<<endl;
else
{
cout<<(*s.begin()).num<<endl;
s.erase(s.begin());
}
}break;
}
}
return 0;
}

63
HDOJ/1911_autoAC.cpp Normal file
View File

@ -0,0 +1,63 @@
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
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<cnt;i++)
{
if(val<x[i])
continue;
sum+=(min(val,y[i])-x[i])/z[i]+1;
}
return sum;
}
void solve()
{
long long l=1,r=inf,ans=-1;
while(l<=r)
{
long long mid=(l+r)>>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;
}

54
HDOJ/1912_autoAC.cpp Normal file
View File

@ -0,0 +1,54 @@
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <string.h>
using namespace std;
int L,d;
struct I
{
double l,r;
}inter[10000];
bool cmp(I a ,I b)
{
if(a.r<b.r)
return true;
else if(a.r==b.r)
{
if(a.l>b.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<inter[i].l)
{
ans++;
temp=inter[i].r;
}
}
cout<<ans<<endl;
}
return 0;
}

28
HDOJ/1913_autoAC.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <stdio.h>
#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<n;i++)
{
for(j=i;j<n;j++)
scanf("%d",&sum[i][j]);
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(i==0)
sum[i][j]=c+sum[i][j];
else
sum[i][j]=(sum[i-1][i-1]+c+sum[i][j])<(sum[i-1][j])?(sum[i-1][i-1]+c+sum[i][j]):(sum[i-1][j]);
}
}
printf("%d\n",sum[n-1][n-1]);
}
return 0;
}

93
HDOJ/1914_autoAC.cpp Normal file
View File

@ -0,0 +1,93 @@
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include <queue>
#include <map>
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];
map<char,int>G,M;
map<int,char>GG,MM;
queue<int>q;
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("");
}
}

53
HDOJ/1915_autoAC.cpp Normal file
View File

@ -0,0 +1,53 @@
#include <iostream>
#include <algorithm>
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<num;i++)
cin>>date[i];
len=strlen(date[0]);
int flag=0;
for(j=0;j<len;j++)
{
for(i=0;i<num;i++)
{
if(date[i][j]!='_')
flag=1;
if(flag==1)
{
strings[pos]=date[i][j];
pos++;
}
}
}
strings[pos]='\0';
reverse(strings,strings+pos);
for(i=0;i<pos;i++)
{
if(strings[i]=='_')
{
printf(" ");
strings[i]=' ';
continue;
}
else if(strings[i]=='\\')
{
cout<<'\n';
continue;
}
else
cout<<strings[i];
}
cout<<endl<<endl;
}
return 0;
}

58
HDOJ/1916_autoAC.cpp Normal file
View File

@ -0,0 +1,58 @@
#include <iostream>
#include <cstdio>
#include <cstring>
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<n){
gets(temp);
if(temp[0]=='+'){
int u,v,c;
char t;
sscanf(temp,"%c%d%d%d",&t,&u,&v,&c);
i+=(v-u)/c+1;
while(u<=v){
solve(u);
u+=c;
}
}
else{
i++;
int u;
sscanf(temp,"%d",&u);
solve(u);
}
}
cout<<name<<endl;
cout<<n<<" "<<tmp<<endl;
int tot=0;
for(i=0;i<=9;i++){
tot+=a[i];
cout<<"Make "<<a[i]<<" digit "<<i<<endl;
}
if(tot==1){
cout<<"In total 1 digit"<<endl;
}
else
printf("In total %d digits\n",tot);
}
return 0;
}

29
HDOJ/1920_autoAC.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <iostream>
#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<<t<<endl;
else
cout<<"More than a billion."<<endl;
}
return 0;
}

107
HDOJ/1922_autoAC.cpp Normal file
View File

@ -0,0 +1,107 @@
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#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 l<a.l;
}
} Point[1005];
int main()
{
int n,T,ans,cnt;
double d,temp,now,drift,r;
scanf("%d",&T);
while(T--)
{
scanf("%d%lf",&n,&d);
for(int i=0; i<n; i++)
{
scanf("%lf%lf",&Point[i].x,&Point[i].y);
temp=sqrt(Point[i].x*Point[i].x+Point[i].y*Point[i].y);
if(temp<=d)
{
n--;
i--;
}
else
{
if(Point[i].x==0)
{
if(Point[i].y>0)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; i<n; i++)
{
r=Point[i].r;
cnt=1;
for(int j=i+1; j<n+i; j++)
{
if(r>Point[j].r)r=Point[j].r;
else if(r<Point[j].l)
{
cnt++;
r=Point[j].r;
}
}
ans=min(ans,cnt);
}
printf("%d\n",ans);
}
return 0;
}

136
HDOJ/1923_autoAC.cpp Normal file
View File

@ -0,0 +1,136 @@
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<iostream>
using namespace std;
#include<string.h>
#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<SIZE;i++)
sub[i]=1;
sub[0]=sub[1]=0;
for(int i=2;i<=sqrt(SIZE);i++){
if(sub[i]==1){
temp=2*i;
while(temp<=SIZE){
sub[temp]=0;
temp+=i;
}
}
}
}
int init(){
int j = 0 ;
pri[j++] = 2 ;
pri[j++] = 3 ;
for( int i = 3 ; i<SSS ;i++ ){
if(sub[i]){
pri[j++]=i;
}
}
return j;
}
int main(){
int num;
int t = 0 ;
__int64 res , next ,next2 ;
int b;
sf();
num = init();
sf();
for(int a = 1 ; a< 600 ; a++ ){
for(int i = 0; i<NUM ;i++ ){
res = pri[i] ;
b = pri[i] - a;
if(b == 0 ) continue;
next = a * pri[i] + b ;
if(next == pri[i]) continue;
if(res * next > 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 ; i<t ;i++ )
for(int j = i+1 ; j <t ;j++)
{
if(rr[i]>rr[j]){
int temp = rr[i];
rr[i] = rr[j];
rr[j] = temp;
}
}
int ccc = 0;
for(int i = 0 ; i <t ; i++)
{
if(rr[i]!= rr[i+1])
aa[ccc++]=rr[i];
}
int N;
__int64 zuo ,you ;
scanf("%d",&N);
while(N--){
scanf("%I64d%I64d",&zuo,&you);
int ans = 0 ;
for(int i = 0 ; i <243 ;i++){
if(zuo<=aa[i] && you>=aa[i])
ans++;
}
printf("%d\n",ans);
}
return 0 ;
}

103
HDOJ/1924_autoAC.cpp Normal file
View File

@ -0,0 +1,103 @@
#include<stdio.h>
#include<string.h>
#include<queue>
#include<map>
#include<string>
#include<iostream>
using namespace std;
map<string,int>my;
map<int,string>my2;
int turn1(string ss1)
{
int num1=0;
int car=0;
int last=1000000;
for(int i=0;i<ss1.size();i++)
{
string ch="";
ch+=ss1[i];
if(my[ch]!=last)
{
if(my[ch]<last)
num1+=car;
else
num1-=car;
car=0;
car+=my[ch];
}
else
car+=my[ch];
last=my[ch];
}
num1+=car;
return num1;
}
string turn2(int n)
{
string ans="";
for(int i=1;n;i*=10)
{
int nw=n%10;
n/=10;
if(nw<=3||i==1000)
{
while(nw--)
{
ans=my2[i]+ans;
}
}
else if(nw>=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<n;i++)
{
cin>>ss1;
ans+=turn1(ss1);
}
cout<<"Case "<<turn2(cas++)<<": "<<turn2(ans)<<endl;
}
return 0;
}

55
HDOJ/1925_autoAC.cpp Normal file
View File

@ -0,0 +1,55 @@
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
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;
}

30
HDOJ/1926_autoAC.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <iostream>
#include <cstdlib>
#include <string>
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;
}

81
HDOJ/1930_autoAC.cpp Normal file
View File

@ -0,0 +1,81 @@
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
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<n;i++)
{
scanf("%I64d",&carry[i]);
a=carry[i]/1000000;
b=carry[i]/10000%100;
c=carry[i]/100%100;
d=carry[i]%100;
china(i);
a=yuan[i]/10000;
b=yuan[i]/100%100;
c=yuan[i]%100;
if(i == n-1)
{
chu(a);
if(b != 27)chu(b);
if(c != 27)chu(c);
}
else
{
chu(a);
chu(b);
chu(c);
}
}
puts("");
}
return 0;
}

115
HDOJ/1934_autoAC.cpp Normal file
View File

@ -0,0 +1,115 @@
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cmath>
#include <stdio.h>
#include <queue>
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;
}

93
HDOJ/1936_autoAC.cpp Normal file
View File

@ -0,0 +1,93 @@
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
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;
}

67
HDOJ/1937_autoAC.cpp Normal file
View File

@ -0,0 +1,67 @@
#include<iostream>
#include<cstdio>
#include<cstring>
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<c)
{
t2++;
}
if(check(i,t1,j,t2)==0)
{
if(min>(j-i+1)*(t2-t1+1))
min=(j-i+1)*(t2-t1+1);
}
}
}
}
printf("%d\n",min);
}
return 0;
}

26
HDOJ/1939_autoAC.cpp Normal file
View File

@ -0,0 +1,26 @@
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
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<a;i++)
scanf("%d",&t1[i]);
for(int i=0;i<b;i++)
scanf("%d",&t2[i]);
sort(t1,t1+a);
sort(t2,t2+b);
if(t1[0]<t2[1])
printf("Y\n");
else
printf("N\n");
}
return 0;
}

66
HDOJ/1940_autoAC.cpp Normal file
View File

@ -0,0 +1,66 @@
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int t, p;
int tp[200], fa[200], ac[200];
int min(int a, int b){
if(a<b) return a;return b;
}
int max(int a, int b){
if(a>b) 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 <strlen(s); k++)
y = y * 10 + s[k] - 48;
tp[i] += y;
}
}
int least = 1;
int biggest = 2000000000;
for(int i = 1; i <= t; i++)
for(int j = 1; j <= t; j++)
if(i != j && ac[i] == ac[j] && fa[i] != fa[j])
{
double x = (tp[i] - tp[j] +0.0) / (fa[j]-fa[i] +0.0);
if(x-20 < 1e-6 && 20-x < 1e-6)
{
biggest = 20;least = 20;
}
else if(x > 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;
}
}

59
HDOJ/1941_autoAC.cpp Normal file
View File

@ -0,0 +1,59 @@
#include<stdio.h>
#include<string.h>
#include<algorithm>
#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;
}

20
HDOJ/1943_autoAC.cpp Normal file
View File

@ -0,0 +1,20 @@
#include<stdio.h>
#include<math.h>
#include<iostream>
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;
}

46
HDOJ/1944_autoAC.cpp Normal file
View File

@ -0,0 +1,46 @@
#include<iostream>
#include<string.h>
#include<algorithm>
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<k && x-s[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<k;i++) scanf("%d",&s[i]);
sort(s,s+k);
scanf("%d",&t);
while(t--)
{
ans=0;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a);
ans^=g(a , k);
}
if(!ans) printf("L");
else printf("W");
}
printf("\n");
}
return 0;
}

42
HDOJ/1945_autoAC.cpp Normal file
View File

@ -0,0 +1,42 @@
#include<stdio.h>
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<y+h;i++)
{
for(j=x;j<x+w-1;j++)
printf("%d ",dfs(i,j));
printf("%d\n",dfs(i,j));
}
printf("\n");
}
return 0;
}

72
HDOJ/1949_autoAC.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <iostream>
#include <cstdio>
#include <cstring>
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;
}

36
HDOJ/1950_autoAC.cpp Normal file
View File

@ -0,0 +1,36 @@
#include<cstdio>
#include<algorithm>
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;i<n;i++)
{
scanf("%d",&m);
if(m>a[top])
{
top++;
a[top]=m;
}
else
{
position=lower_bound(a,a+top,m)-a;
a[position]=m;
}
}
printf("%d\n",top+1);
}
return 0;
}

74
HDOJ/1951_autoAC.cpp Normal file
View File

@ -0,0 +1,74 @@
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <set>
#include <bitset>
#include <vector>
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<MAXSIZE> 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<MAXSIZE> 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<MAXSIZE> 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;
}

71
HDOJ/1954_autoAC.cpp Normal file
View File

@ -0,0 +1,71 @@
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
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;
}

84
HDOJ/1955_autoAC.cpp Normal file
View File

@ -0,0 +1,84 @@
#include<iostream>
#include<string.h>
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<<i<<endl;
}
void bfs(){
int i,j,k;
cnt=0;
memset(v,0,sizeof(v));
memset(a,0,sizeof(a));
memset(b,0,sizeof(b));
for(i=1;i<=2*n;i++)
if(v[i]==0)
{
cnt++;
dfs(i);
}
}
void read(){
int i,j,k,s,t;
int K;
cin>>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;
}

127
HDOJ/1956_autoAC.cpp Normal file
View File

@ -0,0 +1,127 @@
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
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));
queue<int>q;
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 && sum<cur_flow;i=e[i].next)
{
int v=e[i].v;
if(e[i].flow >0 && 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;
}

201
HDOJ/1957_autoAC.cpp Normal file
View File

@ -0,0 +1,201 @@
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <bitset>
#include <ctime>
#include <queue>
#include <complex>
using namespace std;
#define clr(a) memset(a,0,sizeof(a));
const int maxsize=1000007,inf=0x7fffffff;
template<class T>
void show(T a[],int n){
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
}
template<class T>
void show(const vector<T>& t){
for(int i=0;i<t.size();i++){
cout<<t[i]<<" ";
}
cout<<endl;
}
inline int randin(const int& l,const int& r)
{ return rand()%(r-l+1)+l; }
struct node{
int a,b;
node(){
a=b=0;
}
};
char isprime[maxsize];
char tocombine[maxsize];
void init(){
int i;
for(i=0;i<maxsize;i++)
isprime[i]=1;
isprime[0]=0;
for(i=2;i<maxsize;i++){
tocombine[i]=0;
if(isprime[i]){
int k=i;
while(isprime[k]){tocombine[i]++; k--;}
for(int j=i*2;j<maxsize;j+=i){
isprime[j]=0;
}
}
}
}
struct state{
int s[11];
int cnt;
state(){cnt=0;}
void sortme(){sort(s,s+cnt);}
};
bool operator < (const state& a,const state& b){
if(a.cnt!=b.cnt) return a.cnt <b.cnt;
for(int i=0;i<a.cnt;i++){
if(a.s[i]!=b.s[i]){
return a.s[i]<b.s[i];
}
}
return false;
}
bool operator == (state a,state b){
if(a.cnt!=b.cnt) return false;
for(int i=0;i<a.cnt;i++){
if(a.s[i]!=b.s[i]){
return false;
}
}
return true;
}
const int hashsize =maxsize/3;
template<class Tk,class Tv>
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;i<a.cnt;i++){
h=h*1007+a.s[i];
}
return (h%hashsize+hashsize)%hashsize;
}
public:
hashmap(){
clr(entry);mem_end=0;
}
bool get(const Tk& k,Tv& v){
int h=culhash(k);
hashnode *p=entry[h];
for(;p;p=p->next){
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<state,node> 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;i<s.cnt;i++){
if(isprime[s.s[i]]){
l=tocombine[s.s[i]];
k+=l;
s.s[i]-=l;
}
if(s.s[i]==0){
s.cnt--;
swap(s.s[i],s.s[s.cnt]);
i--;
}
}
if(s.cnt){
{
for(i=0;i<s.cnt;i++){
int t=s.s[i];
if(i&&t==s.s[i-1]) continue;
int st=sqrt(s.s[i])+2;
for(j=2;j<st;j++){
if(t%j==0){
state ns =s;
ns.cnt++;
ns.s[i]=j;
ns.s[s.cnt]=t/j;
node tmp =get(ns);
swap(tmp.a,tmp.b);
if(tmp.a>ret.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;i++){
state s;s.s[0]=i;s.cnt=1;
node ans=get(s);
}
cout<<clock()-t0<<endl;
}
int main()
{
init();
state s; s.s[0]=1;s.cnt=1;
node ans; ans.a=1;
hhh.insert(s,ans);
int n;
for(cin>>n;n;--n){
scanf("%d",s.s);
s.cnt=1;
ans =get(s);
printf("%d %d\n",ans.a,ans.b);
}
return 0;
}

69
HDOJ/1959_autoAC.cpp Normal file
View File

@ -0,0 +1,69 @@
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>
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;i<n;i++)
{
tx=x-p[i].x;
ty=y-p[i].y;
if(tx*tx+ty*ty>len)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<m;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
used[p[i].x][p[i].y]=true;
}
int ax=-1,ay=-1;
for(i=0;i<=n&&ax==-1;i++)
{
for(j=0;j<=n&&ax==-1;j++)
{
if(used[i][j])continue;
int len=i;
if(n-i<len)len=n-i;
if(j<len)len=j;
if(n-j<len)len=n-j;
if(ok(i,j,len*len,m))
{
ax=i;
ay=j;
}
}
}
if(ax!=-1)
{
printf("%d %d\n",ax,ay);
}
else puts("poodle");
}
return 0;
}

69
HDOJ/1960_autoAC.cpp Normal file
View File

@ -0,0 +1,69 @@
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define N 510
struct node{
int nt;
int cost;
int x1,x2,y1,y2;
}s[N];
vector<int> g[N];
int linker[N];
bool vis[N];
bool dfs(int u){
for(int i=0;i<g[u].size();i++){
int v=g[u][i];
if(!vis[v]){
vis[v]=1;
if(linker[v]==-1||dfs(linker[v])){
linker[v]=u;
return true;
}
}
}
return false;
}
int hungary(int n){
memset(linker,-1,sizeof(linker));
int cnt=0;
for(int i=0;i<n;i++){
memset(vis,0,sizeof(vis));
if(dfs(i)) cnt++;
}
return cnt;
}
int main(){
int t,n;
scanf("%d",&t);
char str[7];
while(t--){
scanf("%d",&n);
int st,cost;
int x1,y1,x2,y2;
for(int i=0;i<n;i++){
scanf("%s",str);
g[i].clear();
st=((str[0]-'0')*10+(str[1]-'0'))*60+(str[3]-'0')*10+(str[4]-'0');
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
cost=abs(x1-x2)+abs(y1-y2);
s[i].nt=st;
s[i].cost=cost;
s[i].x1=x1;
s[i].x2=x2;
s[i].y1=y1;
s[i].y2=y2;
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(s[i].nt+s[i].cost+1+abs(s[i].x2-s[j].x1)+abs(s[i].y2-s[j].y1)<=s[j].nt){
g[i].push_back(j);
}
}
}
printf("%d\n",n-hungary(n));
}
return 0;
}

74
HDOJ/1962_autoAC.cpp Normal file
View File

@ -0,0 +1,74 @@
#include<iostream>
#include<map>
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<char,int> 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);
}
}

39
HDOJ/1963_autoAC.cpp Normal file
View File

@ -0,0 +1,39 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
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;
}

181
HDOJ/1964_autoAC.cpp Normal file
View File

@ -0,0 +1,181 @@
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
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<hm[cur].size;k++)
{
decode(code,M,hm[cur].state[k]);
left=code[j-1];
up=code[j];
if(left&&up)
{
if(left==up)
{
if(i==ex&&j==ey)
{
code[j-1]=code[j]=0;
if(j==M)shift(code,M);
hm[cur^1].push(encode(code,M),hm[cur].dp[k]);
}
}
else
{
code[j-1]=code[j]=0;
for(int t=0;t<=M;t++)
if(code[t]==left)
code[t]=up;
if(j==M)shift(code,M);
hm[cur^1].push(encode(code,M),hm[cur].dp[k]);
}
}
else if((left&&(!up))||((!left)&&up))
{
int t;
if(left)t=left;
else t=up;
if(maze[i][j+1])
{
code[j-1]=0;
code[j]=t;
hm[cur^1].push(encode(code,M),hm[cur].dp[k]+node[i][j].right);
}
if(maze[i+1][j])
{
code[j-1]=t;
code[j]=0;
if(j==M)shift(code,M);
hm[cur^1].push(encode(code,M),hm[cur].dp[k]+node[i][j].down);
}
}
else
{
if(maze[i][j+1]&&maze[i+1][j])
{
code[j-1]=code[j]=13;
hm[cur^1].push(encode(code,M),hm[cur].dp[k]+node[i][j].down+node[i][j].right);
}
}
}
}
char str[30];
void init()
{
scanf("%d%d%*c",&N,&M);
memset(maze,0,sizeof(maze));
for(int i=1;i<=N;i++)
for(int j=1;j<=M;j++)
maze[i][j]=1;
gets(str);
for(int i=1;i<N;i++)
{
gets(str);
for(int j=1;j<M;j++)
node[i][j].right=str[2*j]-'0';
gets(str);
for(int j=1;j<=M;j++)
node[i][j].down=str[2*j-1]-'0';
}
gets(str);
for(int j=1;j<M;j++)
node[N][j].right=str[2*j]-'0';
gets(str);
ex=N;
ey=M;
}
void solve()
{
int i,j,cur=0;
int ans=0;
hm[cur].init();
hm[cur].push(0,0);
for(i=1;i<=N;i++)
for(j=1;j<=M;j++)
{
hm[cur^1].init();
dpblank(i,j,cur);
cur^=1;
}
for(i=0;i<hm[cur].size;i++)
ans+=hm[cur].dp[i];
printf("%d\n",ans);
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
init();
solve();
}
return 0;
}

89
HDOJ/1965_autoAC.cpp Normal file
View File

@ -0,0 +1,89 @@
#include<iostream>
#include<cstring>
#include<cstdio>
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;
}

57
HDOJ/1966_autoAC.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#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;
}

102
HDOJ/1967_autoAC.cpp Normal file
View File

@ -0,0 +1,102 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
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;
}

39
HDOJ/1969_autoAC.cpp Normal file
View File

@ -0,0 +1,39 @@
#include<stdio.h>
#include<string.h>
#include<math.h>
#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; i<n; i++)
{
scanf("%d",&r);
s[i]=pi*r*r;
if(max<s[i]) max=s[i];
}
while(max-min>eps)
{
mid=(max+min)/2;
pep=0;
for(i=0;i<n;i++)
{
pep+=(int)(s[i]/mid);
}
if(pep>=f)
min=mid;
else
max=mid;
}
printf("%.4lf\n",mid);
}
return 0;
}

59
HDOJ/1970_autoAC.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
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<string,int> cityMap;
for(i=0;i<N;i++)
for(j=0;j<N;j++)
d[i][j]=i==j?0:INF;
for(i=0;i<N;i++) {
cin >> 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<N;k++)
for(i=0;i<N;i++)
for(j=0;j<N;j++)
d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
for(i=0;i<8;i++) {
cin >> s;
e[i]=cityMap[s];
for(j=0;j<N;j++)
dp[1<<i][j]=d[j][e[i]];
}
for(i=1;i<256;i++) {
if (!(i&(i-1)))
continue;
for(k=0;k<N;k++) {
dp[i][k]=INF;
v[k]=0;
for(j=1;j<i;j++)
if ((i|j)==i)
dp[i][k]=min(dp[i][k],dp[j][k]+dp[i-j][k]);
}
for(j=0;b=INF,j<N;j++) {
for(k=0;k<N;k++)
if (dp[i][k]<=b && !v[k])
b=dp[i][c=k];
for(k=0,v[c]=1;k<N;k++)
dp[i][c]=min(dp[i][c],dp[i][k]+d[k][c]);
}
}
for(i=0,b=INF;z=0,i<256;b=min(b,z),i++)
for(j=0;y=0,j<4;z+=!!y*dp[y][x],j++)
for(k=0;k<8;k+=2)
if ((i>>k&3)==j)
y+=3<<k,x=e[k];
cout << b << endl;
}
return 0;
}

78
HDOJ/1971_autoAC.cpp Normal file
View File

@ -0,0 +1,78 @@
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
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<y.w;
}
int main()
{
int T, i, j, n, sum, k;
scanf("%d", &T);
while(T--)
{
Book book[N];
scanf("%d", &n);
sum=0;
for(i=1; i<=n; i++)
{
scanf("%d%d", &book[i].h, &book[i].w);
sum+=book[i].w;
}
sort(book+1, book+n+1, cmp);
for(i=0; i<=sum; i++)
for(j=0; j<=sum; j++)
dp[i][j]=Max;
dp[0][0]=0;
int noww=0;
for(i=2; i<=n; i++)
{
for(j=noww; j>=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);
}
}

48
HDOJ/1972_autoAC.cpp Normal file
View File

@ -0,0 +1,48 @@
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
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];
queue<point>Q;
scanf("%d%d", &n, &m);
for(i=0; i<n; i++)
{
scanf("%d", &a[i]);
p[i].num=a[i], p[i].pla=i;
Q.push(p[i]);
}
sort(a, a+n, cmp);
int maxtop=0;
int num=1;
while(1)
{
point x=Q.front();
Q.pop();
if(x.num==a[maxtop]&&x.pla!=m)
maxtop++, num++;
else if(x.num==a[maxtop]&&x.pla==m)
break;
else
Q.push(x);
}
printf("%d\n", num);
}
return 0;
}

113
HDOJ/1973_autoAC.cpp Normal file
View File

@ -0,0 +1,113 @@
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <queue>
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<item> 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;
}

44
HDOJ/1975_autoAC.cpp Normal file
View File

@ -0,0 +1,44 @@
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
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;
}

24
HDOJ/1976_autoAC.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
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]<a[i+3])
{
printf("Second\n");
break;
}else if(i==2)printf("Same\n");
}
}
return 0;
}

18
HDOJ/1977_autoAC.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <iostream>
#include <string.h>
#include <cstdio>
using namespace std;
typedef long long LL;
const int MS=1001;
int main()
{
LL n;
int T;
cin>>T;
while(T--)
{
cin>>n;
cout<<n*n*n<<" "<<(n+1)*(n+1)*(n+1)<<endl;
}
return 0;
}

25
HDOJ/1978_autoAC.cpp Normal file
View File

@ -0,0 +1,25 @@
#include<stdio.h>
#include<string.h>
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);
}
}

9
HDOJ/1979_autoAC.cpp Normal file
View File

@ -0,0 +1,9 @@
#include<stdio.h>
#include<iostream>
#include <string>
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<<s<<endl;
}

39
HDOJ/1981_autoAC.cpp Normal file
View File

@ -0,0 +1,39 @@
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
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;
}

46
HDOJ/1982_autoAC.cpp Normal file
View File

@ -0,0 +1,46 @@
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>
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<s.size(); i++)
{
if(s[i]=='#')
{
if(t!="")
{
process(t);
t="";
}
cout<<" ";
}
else
{
t+=s[i];
}
}
process(t);
cout<<endl;
}
int main()
{
int T;
cin>>T;
while(T--) run();
return 0;
}

145
HDOJ/1983_autoAC.cpp Normal file
View File

@ -0,0 +1,145 @@
#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
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<STEP> 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;
}

22
HDOJ/1984_autoAC.cpp Normal file
View File

@ -0,0 +1,22 @@
#include<stdio.h>
#include<string.h>
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<len;i++)
if(i!=(t-1)) printf("%c",a[i]);
printf("\n");
}
return 0;
}

23
HDOJ/1985_autoAC.cpp Normal file
View File

@ -0,0 +1,23 @@
#include<stdio.h>
#include<string.h>
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++;
}
}

51
HDOJ/1986_autoAC.cpp Normal file
View File

@ -0,0 +1,51 @@
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
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<c && map[x][y+1]==-1) map[x][++y] = m[++tot];
while(x+1<r && map[x+1][y]==-1) map[++x][y] = m[++tot];
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<r;i++)
for(int j=0;j<c;j++)
{
if(map[i][j]==-1) printf("0");
else printf("%d",map[i][j]);
}
printf("\n");
}
return 0;
}

59
HDOJ/1987_autoAC.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
typedef pair<int , int> 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<char>(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;
}

72
HDOJ/1988_autoAC.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <cstdio>
#include <cmath>
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;
}

29
HDOJ/1990_autoAC.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <cstdio>
#include <cstring>
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<<maxx);
}
return 0;
}

15
HDOJ/1992_autoAC.cpp Normal file
View File

@ -0,0 +1,15 @@
# include <stdio.h>
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 ;
}

145
HDOJ/1993_autoAC.cpp Normal file
View File

@ -0,0 +1,145 @@
#include <iostream>
#include <vector>
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<int> 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;
}

17
HDOJ/1994_autoAC.cpp Normal file
View File

@ -0,0 +1,17 @@
#include<stdio.h>
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;
}

11
HDOJ/1995_autoAC.cpp Normal file
View File

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

19
HDOJ/1996_autoAC.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<stdio.h>
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;
}

46
HDOJ/1997_autoAC.cpp Normal file
View File

@ -0,0 +1,46 @@
#include<iostream>
#include<queue>
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;
}

13
HDOJ/1998_autoAC.cpp Normal file
View File

@ -0,0 +1,13 @@
#include <stdio.h>
int main(){
int n,m,i,j;
scanf("%d",&n);
while(n-->0){
scanf("%d",&m);
for(i=0;i<m;i++){
for(j=0;j<m;j++)
printf("%4d",(i+j-m/2+m)%m*m+(m+i+2*j-m+1)%m+1);
printf("\n");
}
}
}

35
HDOJ/1999_autoAC.cpp Normal file
View File

@ -0,0 +1,35 @@
#include<iostream>
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"<<endl;
else if(n<5) cout<<"no"<<endl;
else
for(i=2;i<=(n-1)/2;i++)
{
if(f(i)&&f(n-1-i)||f(n-1))
{
cout<<"no"<<endl;
x=0;
break;
}
x=1;
}
if(x==1)
cout<<"yes"<<endl;
}
return 0;
}