From 378c82e5131902df7deb1e6644f7f9df57f2cc9f Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Sat, 13 Aug 2016 23:51:27 +0800 Subject: [PATCH] Powered By HC TECH : AutoACer Engine --- HDOJ/1300_autoAC.cpp | 51 +++++++++++++++ HDOJ/1301_autoAC.cpp | 63 ++++++++++++++++++ HDOJ/1302_autoAC.cpp | 28 ++++++++ HDOJ/1303_autoAC.cpp | 24 +++++++ HDOJ/1304_autoAC.cpp | 32 +++++++++ HDOJ/1305_autoAC.cpp | 77 ++++++++++++++++++++++ HDOJ/1306_autoAC.cpp | 57 ++++++++++++++++ HDOJ/1307_autoAC.cpp | 109 ++++++++++++++++++++++++++++++ HDOJ/1308_autoAC.cpp | 101 ++++++++++++++++++++++++++++ HDOJ/1309_autoAC.cpp | 31 +++++++++ HDOJ/1310_autoAC.cpp | 72 ++++++++++++++++++++ HDOJ/1311_autoAC.cpp | 60 +++++++++++++++++ HDOJ/1312_autoAC.cpp | 71 ++++++++++++++++++++ HDOJ/1313_autoAC.cpp | 49 ++++++++++++++ HDOJ/1314_autoAC.cpp | 103 +++++++++++++++++++++++++++++ HDOJ/1315_autoAC.cpp | 40 +++++++++++ HDOJ/1316_autoAC.cpp | 83 +++++++++++++++++++++++ HDOJ/1317_autoAC.cpp | 99 ++++++++++++++++++++++++++++ HDOJ/1318_autoAC.cpp | 13 ++++ HDOJ/1319_autoAC.cpp | 31 +++++++++ HDOJ/1320_autoAC.cpp | 52 +++++++++++++++ HDOJ/1321_autoAC.cpp | 23 +++++++ HDOJ/1322_autoAC.cpp | 18 +++++ HDOJ/1323_autoAC.cpp | 36 ++++++++++ HDOJ/1324_autoAC.cpp | 35 ++++++++++ HDOJ/1325_autoAC.cpp | 61 +++++++++++++++++ HDOJ/1326_autoAC.cpp | 24 +++++++ HDOJ/1327_autoAC.cpp | 41 ++++++++++++ HDOJ/1328_autoAC.cpp | 23 +++++++ HDOJ/1329_autoAC.cpp | 46 +++++++++++++ HDOJ/1330_autoAC.cpp | 24 +++++++ HDOJ/1331_autoAC.cpp | 37 +++++++++++ HDOJ/1332_autoAC.cpp | 127 +++++++++++++++++++++++++++++++++++ HDOJ/1333_autoAC.cpp | 65 ++++++++++++++++++ HDOJ/1334_autoAC.cpp | 21 ++++++ HDOJ/1335_autoAC.cpp | 58 ++++++++++++++++ HDOJ/1336_autoAC.cpp | 60 +++++++++++++++++ HDOJ/1337_autoAC.cpp | 33 ++++++++++ HDOJ/1338_autoAC.cpp | 31 +++++++++ HDOJ/1339_autoAC.cpp | 19 ++++++ HDOJ/1341_autoAC.cpp | 64 ++++++++++++++++++ HDOJ/1342_autoAC.cpp | 39 +++++++++++ HDOJ/1343_autoAC.cpp | 59 +++++++++++++++++ HDOJ/1344_autoAC.cpp | 74 +++++++++++++++++++++ HDOJ/1345_autoAC.cpp | 107 ++++++++++++++++++++++++++++++ HDOJ/1346_autoAC.cpp | 42 ++++++++++++ HDOJ/1347_autoAC.cpp | 55 ++++++++++++++++ HDOJ/1348_autoAC.cpp | 88 +++++++++++++++++++++++++ HDOJ/1350_autoAC.cpp | 90 +++++++++++++++++++++++++ HDOJ/1351_autoAC.cpp | 27 ++++++++ HDOJ/1352_autoAC.cpp | 112 +++++++++++++++++++++++++++++++ HDOJ/1353_autoAC.cpp | 63 ++++++++++++++++++ HDOJ/1354_autoAC.cpp | 103 +++++++++++++++++++++++++++++ HDOJ/1355_autoAC.cpp | 53 +++++++++++++++ HDOJ/1356_autoAC.cpp | 5 ++ HDOJ/1358_autoAC.cpp | 43 ++++++++++++ HDOJ/1361_autoAC.cpp | 3 + HDOJ/1362_autoAC.cpp | 130 ++++++++++++++++++++++++++++++++++++ HDOJ/1364_autoAC.cpp | 66 +++++++++++++++++++ HDOJ/1365_autoAC.cpp | 153 +++++++++++++++++++++++++++++++++++++++++++ HDOJ/1366_autoAC.cpp | 96 +++++++++++++++++++++++++++ HDOJ/1369_autoAC.cpp | 103 +++++++++++++++++++++++++++++ HDOJ/1370_autoAC.cpp | 24 +++++++ HDOJ/1371_autoAC.cpp | 61 +++++++++++++++++ HDOJ/1372_autoAC.cpp | 25 +++++++ HDOJ/1373_autoAC.cpp | 123 ++++++++++++++++++++++++++++++++++ HDOJ/1374_autoAC.cpp | 21 ++++++ HDOJ/1375_autoAC.cpp | 139 +++++++++++++++++++++++++++++++++++++++ HDOJ/1376_autoAC.cpp | 29 ++++++++ HDOJ/1377_autoAC.cpp | 145 ++++++++++++++++++++++++++++++++++++++++ HDOJ/1378_autoAC.cpp | 130 ++++++++++++++++++++++++++++++++++++ HDOJ/1379_autoAC.cpp | 46 +++++++++++++ HDOJ/1380_autoAC.cpp | 61 +++++++++++++++++ HDOJ/1381_autoAC.cpp | 20 ++++++ HDOJ/1382_autoAC.cpp | 62 ++++++++++++++++++ HDOJ/1384_autoAC.cpp | 62 ++++++++++++++++++ HDOJ/1385_autoAC.cpp | 61 +++++++++++++++++ HDOJ/1387_autoAC.cpp | 80 ++++++++++++++++++++++ HDOJ/1388_autoAC.cpp | 62 ++++++++++++++++++ HDOJ/1390_autoAC.cpp | 26 ++++++++ HDOJ/1391_autoAC.cpp | 31 +++++++++ HDOJ/1392_autoAC.cpp | 84 ++++++++++++++++++++++++ HDOJ/1393_autoAC.cpp | 25 +++++++ HDOJ/1394_autoAC.cpp | 47 +++++++++++++ HDOJ/1395_autoAC.cpp | 25 +++++++ HDOJ/1396_autoAC.cpp | 20 ++++++ HDOJ/1397_autoAC.cpp | 42 ++++++++++++ HDOJ/1398_autoAC.cpp | 27 ++++++++ HDOJ/1399_autoAC.cpp | 29 ++++++++ 89 files changed, 5110 insertions(+) create mode 100644 HDOJ/1300_autoAC.cpp create mode 100644 HDOJ/1301_autoAC.cpp create mode 100644 HDOJ/1302_autoAC.cpp create mode 100644 HDOJ/1303_autoAC.cpp create mode 100644 HDOJ/1304_autoAC.cpp create mode 100644 HDOJ/1305_autoAC.cpp create mode 100644 HDOJ/1306_autoAC.cpp create mode 100644 HDOJ/1307_autoAC.cpp create mode 100644 HDOJ/1308_autoAC.cpp create mode 100644 HDOJ/1309_autoAC.cpp create mode 100644 HDOJ/1310_autoAC.cpp create mode 100644 HDOJ/1311_autoAC.cpp create mode 100644 HDOJ/1312_autoAC.cpp create mode 100644 HDOJ/1313_autoAC.cpp create mode 100644 HDOJ/1314_autoAC.cpp create mode 100644 HDOJ/1315_autoAC.cpp create mode 100644 HDOJ/1316_autoAC.cpp create mode 100644 HDOJ/1317_autoAC.cpp create mode 100644 HDOJ/1318_autoAC.cpp create mode 100644 HDOJ/1319_autoAC.cpp create mode 100644 HDOJ/1320_autoAC.cpp create mode 100644 HDOJ/1321_autoAC.cpp create mode 100644 HDOJ/1322_autoAC.cpp create mode 100644 HDOJ/1323_autoAC.cpp create mode 100644 HDOJ/1324_autoAC.cpp create mode 100644 HDOJ/1325_autoAC.cpp create mode 100644 HDOJ/1326_autoAC.cpp create mode 100644 HDOJ/1327_autoAC.cpp create mode 100644 HDOJ/1328_autoAC.cpp create mode 100644 HDOJ/1329_autoAC.cpp create mode 100644 HDOJ/1330_autoAC.cpp create mode 100644 HDOJ/1331_autoAC.cpp create mode 100644 HDOJ/1332_autoAC.cpp create mode 100644 HDOJ/1333_autoAC.cpp create mode 100644 HDOJ/1334_autoAC.cpp create mode 100644 HDOJ/1335_autoAC.cpp create mode 100644 HDOJ/1336_autoAC.cpp create mode 100644 HDOJ/1337_autoAC.cpp create mode 100644 HDOJ/1338_autoAC.cpp create mode 100644 HDOJ/1339_autoAC.cpp create mode 100644 HDOJ/1341_autoAC.cpp create mode 100644 HDOJ/1342_autoAC.cpp create mode 100644 HDOJ/1343_autoAC.cpp create mode 100644 HDOJ/1344_autoAC.cpp create mode 100644 HDOJ/1345_autoAC.cpp create mode 100644 HDOJ/1346_autoAC.cpp create mode 100644 HDOJ/1347_autoAC.cpp create mode 100644 HDOJ/1348_autoAC.cpp create mode 100644 HDOJ/1350_autoAC.cpp create mode 100644 HDOJ/1351_autoAC.cpp create mode 100644 HDOJ/1352_autoAC.cpp create mode 100644 HDOJ/1353_autoAC.cpp create mode 100644 HDOJ/1354_autoAC.cpp create mode 100644 HDOJ/1355_autoAC.cpp create mode 100644 HDOJ/1356_autoAC.cpp create mode 100644 HDOJ/1358_autoAC.cpp create mode 100644 HDOJ/1361_autoAC.cpp create mode 100644 HDOJ/1362_autoAC.cpp create mode 100644 HDOJ/1364_autoAC.cpp create mode 100644 HDOJ/1365_autoAC.cpp create mode 100644 HDOJ/1366_autoAC.cpp create mode 100644 HDOJ/1369_autoAC.cpp create mode 100644 HDOJ/1370_autoAC.cpp create mode 100644 HDOJ/1371_autoAC.cpp create mode 100644 HDOJ/1372_autoAC.cpp create mode 100644 HDOJ/1373_autoAC.cpp create mode 100644 HDOJ/1374_autoAC.cpp create mode 100644 HDOJ/1375_autoAC.cpp create mode 100644 HDOJ/1376_autoAC.cpp create mode 100644 HDOJ/1377_autoAC.cpp create mode 100644 HDOJ/1378_autoAC.cpp create mode 100644 HDOJ/1379_autoAC.cpp create mode 100644 HDOJ/1380_autoAC.cpp create mode 100644 HDOJ/1381_autoAC.cpp create mode 100644 HDOJ/1382_autoAC.cpp create mode 100644 HDOJ/1384_autoAC.cpp create mode 100644 HDOJ/1385_autoAC.cpp create mode 100644 HDOJ/1387_autoAC.cpp create mode 100644 HDOJ/1388_autoAC.cpp create mode 100644 HDOJ/1390_autoAC.cpp create mode 100644 HDOJ/1391_autoAC.cpp create mode 100644 HDOJ/1392_autoAC.cpp create mode 100644 HDOJ/1393_autoAC.cpp create mode 100644 HDOJ/1394_autoAC.cpp create mode 100644 HDOJ/1395_autoAC.cpp create mode 100644 HDOJ/1396_autoAC.cpp create mode 100644 HDOJ/1397_autoAC.cpp create mode 100644 HDOJ/1398_autoAC.cpp create mode 100644 HDOJ/1399_autoAC.cpp diff --git a/HDOJ/1300_autoAC.cpp b/HDOJ/1300_autoAC.cpp new file mode 100644 index 0000000..a2f1710 --- /dev/null +++ b/HDOJ/1300_autoAC.cpp @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define MAXN 1100 +typedef struct kind +{ + int num,price; +}Kind; +Kind kind[MAXN]; +int sum[MAXN]; +int ans[MAXN]; +int main() +{ + int t; + int i,j; + int n; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + sum[0]=0; + memset(ans,0,sizeof(ans)); + for(i=1;i<=n;i++) + { + scanf("%d%d",&kind[i].num,&kind[i].price); + sum[i]=sum[i-1]+kind[i].num; + ans[i]=(sum[i]+10)*kind[i].price; + } + for(i=1;i<=n;i++) + for(j=1;j<=i;j++) + ans[i]=min(ans[i],(sum[i]-sum[j]+10)*kind[i].price+ans[j]); + printf("%d\n",ans[n]); + } + return 0; +} diff --git a/HDOJ/1301_autoAC.cpp b/HDOJ/1301_autoAC.cpp new file mode 100644 index 0000000..9d20fe7 --- /dev/null +++ b/HDOJ/1301_autoAC.cpp @@ -0,0 +1,63 @@ +#include +#include +#define inf 0x6fffff +int dis[105]; +int map[105][105]; +int vis[105]; +int sum,n; +void prim() +{ + int i,j,k,min; + for(i=1;i<=n;i++) + dis[i]=map[1][i]; + vis[1]=1; + for(i=1;i<=n;i++) + { + min=inf; + for(j=1;j<=n;j++) + { + if(vis[j]==0 &&dis[j]map[k][j]) + dis[j]=map[k][j]; + } + } +} +int main() +{ + int i,j,a,l; + char b[22],b1[22]; + while(scanf("%d",&n)!=EOF&&n!=0) + { + for(i=1;i<=n;i++) + for(j=1;j<=n;j++) + map[i][j]=inf; + for(i=1;i<=n-1;i++) + { + scanf("%s",b); + scanf("%d",&a); + for(j=1;j<=a;j++) + { + scanf("%s",b1); + scanf("%d",&l); + map[b[0]-'A'+1][b1[0]-'A'+1]=map[b1[0]-'A'+1][b[0]-'A'+1]=l; + } + getchar(); + } + memset(vis,0,sizeof(vis)); + sum=0; + prim(); + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/1302_autoAC.cpp b/HDOJ/1302_autoAC.cpp new file mode 100644 index 0000000..373295e --- /dev/null +++ b/HDOJ/1302_autoAC.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; +int main() +{ + int h,u,d,f; + while(cin>>h>>u>>d>>f&&h!=0) + { + int i=1; + double sum=0; + while(i) + { + sum+=u-u*(i-1)*double(f)/100; + if(sum>h) + { + cout<<"success on day "< +#include +#include +using namespace std; +int main() +{ + int temp; + while(cin>>temp&&temp!=-1) + { + vector v; + v.push_back(temp); + while(cin>>temp&&temp!=0) + v.push_back(temp); + int sum=0; + for(int i=0;i!=v.size();++i) + { + auto b=find(v.cbegin(),v.cend(),2*v[i]); + if(b!=v.cend()) + sum++; + } + cout< +#include +using namespace std; +int main() +{ + string name1,name0; + int n,i,submit,time; + int solve1,solve0=0,penalty1,penalty0=0; + cin>>n; + while(n--) + { + cin>>name1; + solve1=penalty1=0; + for(i=0;i<4;i++) + { + cin>>submit>>time; + if(time) + { + solve1++; + penalty1=penalty1+time+(submit-1)*20; + } + } + if(solve1>solve0||(solve1==solve0&&penalty1 +#include +#include +typedef struct Trie +{ + int v; + Trie* next[2]; +}; +Trie* root; +void creatTrie(char str[]) +{ + Trie* p=root,*q; + int i; + for(i=0;inext[id]==NULL) + { + q=(Trie*)malloc(sizeof(Trie)); + q->next[0]=q->next[1]=NULL; + q->v=1; + p->next[id]=q; + } + p=p->next[id]; + } + p->v=-1; +} +int findTrie(char str[]) +{ + Trie* p=root; + for(int i=0;inext[id]->v==-1) + { + return 1; + } + } + p=p->next[id]; + } + return 0; +} +int main() +{ + char s[10][20]; + int c=1; + while(scanf("%s",s[0])!=EOF) + { + root=(Trie*)malloc(sizeof(Trie)); + root->next[0]=NULL; + root->next[1]=NULL; + root->v=1; + creatTrie(s[0]); + int k=1; + while(scanf("%s",s[k])!=EOF&&s[k][0]!='9') + { + creatTrie(s[k++]); + } + int i; + for( i=0;i=k) + { + printf("Set %d is immediately decodable\n",c++); + } + } + return 0; +} diff --git a/HDOJ/1306_autoAC.cpp b/HDOJ/1306_autoAC.cpp new file mode 100644 index 0000000..48db2f8 --- /dev/null +++ b/HDOJ/1306_autoAC.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +using namespace std; +int main() +{ + string s1,s2,t1,t2,x1,x2; + int i,j,k,n; + while(cin>>x1&&x1!="-1") + { + cin>>x2; + if(x1.length()>x2.length()) + { + s1=x2; + s2=x1; + } + else + { + s1=x1; + s2=x2; + } + int sum=0; + for(i=0;isum) + sum=total; + } + int temp=x1.length()+x2.length(); + int t=sum*2; + if(sum==0) + cout<<"appx("< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int n; +int from[1000][11]; +int to[1000][11]; +int l; +int s[11],e[11]; +bool vist[100000]; +bool ans; +int get(int f[]) +{ + int sum=0; + for (int i=0;i>n,n) + { + num++; + l=0; + for (i=0;i>s[i]; + for (i=0;i>e[i]; + while (cin>>k) + { + if (k<0) + break; + from[l][0]=k; + for (i=1;i>from[l][i]; + for (i=0;i>to[l][i]; + l++; + } + memset(vist,false,sizeof(vist)); + ans=false; + dfs(s); + if (ans) + printf("Maze #%d can be travelled\n",num); + else + printf("Maze #%d cannot be travelled\n",num); + } +} diff --git a/HDOJ/1308_autoAC.cpp b/HDOJ/1308_autoAC.cpp new file mode 100644 index 0000000..4e6f35f --- /dev/null +++ b/HDOJ/1308_autoAC.cpp @@ -0,0 +1,101 @@ +#include +int calculate(int year, int month, int day); +int main() +{ + const char *weekdays[] = + { + "Sunday", "Monday", "Tuesday", "Wednesday", + "Thursday", "Friday", "Saturday" + }; + const char *monthname[] = + { + "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December" + }; + int year, month, day, week; + while (scanf("%d%d%d", &month, &day, &year) != EOF) + { + if (year == 0 && month == 0 && day == 0) + break; + week = calculate(year, month, day); + if (week == -1) + printf("%d/%d/%d is an invalid date.\n", month, day, year); + else + printf("%s %d, %d is a %s\n", monthname[month - 1], day, year, weekdays[week]); + } + return 0; +} +int calculate(int year, int month, int day) +{ + int count, leap, century; + static const int daycount[] = + { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; + if (year <= 0 || month > 12 || month < 1 || day < 1 || day > 31) + return -1; + if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30) + return -1; + if (year <= 1752) + { + if (year == 1752 && month == 9 && day > 2 && day < 14) + return -1; + if (year % 4 == 0) + { + leap = 1; + if (month == 2) + { + if (day > 29) + return -1; + } + } + else + { + leap = 0; + if (month == 2) + { + if (day > 28) + return -1; + } + } + count = (year - 1) * 365 + (year - 1) / 4; + count += daycount[month - 1] + day; + if (leap && month > 2) + count += 1; + if (year == 1752) + { + if (month > 9 || (month == 9 && day >= 14)) + count -= 11; + } + return ((count + 5) % 7); + } + else + { + if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) + { + leap = 1; + if (month == 2) + { + if (day > 29) + return -1; + } + } + else + { + leap = 0; + if (month == 2) + { + if (day > 28) + return -1; + } + } + century = (year - 1) / 100 - 17; + count = (year - 1) * 365 + (year - 1) / 4; + count += (daycount[month - 1] + day); + count -= (11 + century); + count += (century + 1) / 4; + if (leap && month > 2) + count += 1; + return ((count + 5) % 7); + } + return -1; +} diff --git a/HDOJ/1309_autoAC.cpp b/HDOJ/1309_autoAC.cpp new file mode 100644 index 0000000..d77d974 --- /dev/null +++ b/HDOJ/1309_autoAC.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +using namespace std; +double mon,downpay,loan,dep; +double rate[110]; +int main(){ + // freopen("in","r",stdin); + while(cin >> mon >> downpay>>loan>>dep&&mon>0){ + memset(rate,0.0,sizeof rate); + while(dep--){ + int s; + double ra; + cin >> s >> ra; + for(int i = s; i <= 100; i++) rate[i] = ra; + } + int ans = 0; + double aver = loan/mon; + double nowloan = loan; + double nowsum = (loan+downpay)*(1-rate[0]); + while(nowsum < nowloan){ + ans++; + nowloan -= aver; + nowsum = nowsum*(1-rate[ans]); + } + cout< +#include +#include +#include +#include +#include +using namespace std; +#define ONLINE_JUDGE +#define MAXN 125 +#define INF 0xfffffff +int nn; +int dis[MAXN][MAXN]; +string buf[MAXN]; +bool visit[5]; +map tb; +int a[MAXN]; +int myabs(int x) { + return x<0 ? -x:x; +} +void init() { + string s = "ABCDE"; + nn = 0; + int i, j, k, p; + int sum, tmp; + do { + buf[nn] = s; + tb[s] = nn++; + } while (next_permutation(s.begin(), s.end())); + for (i=0; i>n && n) { + for (i=0; i>s; + a[i] = tb[s]; + } + mmin = INF; + for (i=0; i +#include +#include +#include +#include +#include +#include +#include +using namespace std; +int father[110]; +struct data +{ + string father, child; + int dis; + int age; +}; +int n; +data family[200]; +bool sign[200]; +void dfs(string str, int year) +{ + for(int i=0; i b.age ? 1:0; + else + return a.child < b.child ? 1:0; +} +int main() +{ + int T; + int co = 1; + scanf("%d\n", &T); + while(T--) + { + printf("DATASET %d\n", co++); + scanf("%d", &n); + int flag; + memset(sign, 0, sizeof(sign) ); + for(int i=0; i> family[i].father >> family[i].child >> family[i].dis; + } + dfs("Ted", 100); + sort(family, family+n, cmp); + for(int i=0; i +#include +char map[100][100]; +int sign[100][100]; +int n,m; +int ans; +void dfs(int x,int y) +{ + if(x>=0&&x=0&&y=0&&map[x-1][y]=='.'&&sign[x-1][y]==0) + { + sign[x-1][y]=1; + ans++; + dfs(x-1,y); + } + if(x+1=0&&map[x][y-1]=='.'&&sign[x][y-1]==0) + { + sign[x][y-1]=1; + ans++; + dfs(x,y-1); + } + if(y+1 +#include +int main(void) +{ + char number[61]; + int value[60]; + int result[60]; + int i,j,k,l; + int flag; + while(gets(number)) + { + int n = strlen(number); + for(i = 0; i < n; i++) + value[i] = number[i] - '0'; + for(i = 1; i <= n; i++) + { + flag = 0; + int r = 0; + for(j = n - 1; j >= 0; j--) + { + r += value[j] * i; + result[j] = r % 10; + r /= 10; + } + for(j = 0; j < n; j++) + { + if(result[j] == value[0]) + { + k = j; + for(l = 0; l < n; l++) + { + if(result[k] != value[l]) + break; + k == n - 1 ? k = 0:k++; + } + if(l == n) + { + flag = 1; + break; + } + } + } + if(flag == 0) + break; + } + printf("%s is %scyclic\n",number,flag == 0? "not ":""); + } + return 0; +} diff --git a/HDOJ/1314_autoAC.cpp b/HDOJ/1314_autoAC.cpp new file mode 100644 index 0000000..5f6ef77 --- /dev/null +++ b/HDOJ/1314_autoAC.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +int a[40], b[40], ca[40]; +void add(int s[], int n) { + int t = 0, i; + s[39] += n; + for (i = 39; i >= 0; --i) { + s[i] += t; + t = s[i] / 10; + s[i] %= 10; + } +} +void mul(int s[], int n) { + int t = 0, i; + for (i = 39; i >= 0; --i) { + s[i] = s[i] * n + t; + t = s[i] / 10; + s[i] %= 10; + } +} +void sub(int s[], int n) { + int t = 0, i; + s[39] -= n; + for (i = 39; i >= 0; --i) { + if (s[i] >= 0) { + break; + } else { + s[i + 1]--; + s[i] += 10; + } + } +} +int div_mod(int s[], int n) { + int t = 0, i; + for (i = 0; i < 40; ++i) { + s[i] += 10 * t; + t = s[i] % n; + s[i] /= n; + } + return t; +} +int is_zero(int s[]) { + int i; + for (i = 0; i < 40; ++i) + if (s[i]) + return 0; + return 1; +} +char ss[40]; +int main() { + int le, i, ans; + while (scanf("%s", ss) != EOF) { + if (ss[0] == '*') + break; + le = strlen(ss); + memset(a, 0, sizeof (a)); + memset(b, 0, sizeof (b)); + memset(ca, 0, sizeof (ca)); + if (ss[0] <= '9' && ss[0] >= '0') { + for (i = 39; le > 0; --i) + ca[i] = a[i] = ss[--le] - '0'; + for (i = 39; i >= 0; --i) { + ans = div_mod(a, 26); + if (!ans) { + b[i] = 26; + sub(a, 1); + } else + b[i] = ans; + if (is_zero(a)) + break; + } + for (i = 0; i < 40; ++i) + a[i] = ca[i]; + } else if (ss[0] <= 'z' && ss[0] >= 'a') { + for (i = 39; le > 0; --i) + b[i] = ss[--le] - 'a' + 1; + for (i = 0; i < 40; ++i) { + mul(a, 26); + add(a, b[i]); + } + } + for (i = 0; i < 40; ++i) + if (b[i]) + break; + ans = i; + for (; i < 40; ++i) + printf("%c", b[i] + 'a' - 1); + ans -= 18; + while (ans--) + printf(" "); + for (i = 0; i < 40; ++i) + if (a[i]) + break; + for (; i < 40; ++i) { + printf("%c", a[i] + '0'); + if (i < 39 && i % 3 == 0) + printf(","); + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1315_autoAC.cpp b/HDOJ/1315_autoAC.cpp new file mode 100644 index 0000000..0f1bf11 --- /dev/null +++ b/HDOJ/1315_autoAC.cpp @@ -0,0 +1,40 @@ +#include +char s[100]; +int pd(double p,int i) +{ + int j; + double g=0; + if(p<2||p>16) return 0; + if(s[i]=='#') return 0; + for(j=i;s[j]!='\0';j++) + { + if(s[j]=='#') break; + if(p>10&&(s[j]<'0'||(s[j]>'9'&&s[j]<'a')||s[j]>'a'+p-11)) return 0; + if(p<=10&&!(s[j]>='0'&&s[j]<='0'+p-1)) return 0; + if(s[j]>='a'&&s[j]<='f') g=g*p+10+s[j]-'a'; + else g=g*p+s[j]-'0'; + } + if(s[j]=='#'&&s[j+1]=='\0'||s[j]=='#'&&s[j+1]=='#'&&pd(g,j+2)) + return 1; + else return 0; +} +int main() +{ + int t,j; + double p; + scanf("%d",&t); + while(t--) + { + scanf("%s",s); + p=0; + for(j=0;;j++) + { + if(s[j]>='0'&&s[j]<='9') + p=p*10+s[j]-'0'; + else break; + } + if(s[j]=='#'&&pd(p,j+1)||p==0&&s[j]=='\0') printf("yes\n"); + else printf("no\n"); + } + return 0; +} diff --git a/HDOJ/1316_autoAC.cpp b/HDOJ/1316_autoAC.cpp new file mode 100644 index 0000000..21009d3 --- /dev/null +++ b/HDOJ/1316_autoAC.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +using namespace std; +#define NUM 500 +#define MAX_LEN 110 +class BigInteger{ + int d[MAX_LEN]; + int len; +public: + BigInteger(){ + memset( d, 0, sizeof(d)); + len = 0; + } + void set(char *str){ + len = strlen(str); + for(int i = 0, j = len - 1; i < len; i++, j-- ){ + d[i] = str[j] - '0'; + } + } + BigInteger operator+(const BigInteger &other)const{ + BigInteger ret; + ret.len = max( len, other.len ); + for(int i = 0; i < ret.len; i++ ){ + ret.d[i] = d[i] + other.d[i]; + } + for(int i = 0; i < ret.len; i++ ){ + if(ret.d[i] > 9){ + ret.d[i] -= 10; + ret.d[i + 1]++; + } + } + if(ret.d[ret.len] > 0) + ret.len ++; + return ret; + } + bool operator<=(const BigInteger &other)const{ + if(len < other.len) + return true; + if(len == other.len){ + int i = len - 1; + while(i >= 0 && d[i] == other.d[i]) + i--; + if(i == -1 || d[i] <= other.d[i]) + return true; + } + return false; + } +}; +BigInteger fibo[NUM], a, b; +char stra[MAX_LEN], strb[MAX_LEN]; +void init(){ + fibo[0].set("1"); fibo[1].set("2"); + for(int i = 2; i < NUM; i++ ) + fibo[i] = fibo[i - 1] + fibo[i - 2]; +} +bool input(){ + scanf("%s%s", stra, strb ); + if(stra[0] == '0' && strb[0] == '0') + return false; + a.set(stra); b.set(strb); + return true; +} +void output(){ + int l, r; + for( l = 0; l < NUM; l++ ){ + if(a <= fibo[l]) + break; + } + for( r = NUM - 1; r > 0; r-- ){ + if(fibo[r] <= b) + break; + } + printf("%d\n", r - l + 1 ); +} +int main(){ + init(); + while(input()){ + output(); + } + return 0; +} diff --git a/HDOJ/1317_autoAC.cpp b/HDOJ/1317_autoAC.cpp new file mode 100644 index 0000000..8159f9b --- /dev/null +++ b/HDOJ/1317_autoAC.cpp @@ -0,0 +1,99 @@ +#include +#include +using namespace std; +const int maxn=102; +struct node +{ + int to; + int next; +}; +node edge[maxn*maxn]; +node edge1[maxn*maxn]; +int head[maxn]; +int head1[maxn]; +bool ac[maxn]; +int isin[maxn]; +int point[maxn]; +int total[maxn]; +int stack[maxn+10]; +void dfs(int x) +{ + isin[x]=1; + ac[x]=true; + for(int k=head1[x];k!=-1;k=edge1[k].next) + { + if(!isin[edge1[k].to]) + dfs(edge1[k].to); + } +} +int main() +{ + int n,i,j,k,t,x,c,ptr,top; + while(scanf("%d",&n)==1) + { + if(n==-1) break; + if(n==1) + { + printf("winnable\n"); + continue; + } + for(i=1;i<=n;i++) + { + head[i]=-1; + head1[i]=-1; + total[i]=-1; + isin[i]=0; + ac[i]=false; + } + c=0; + for(i=1;i<=n;i++) + { + scanf("%d%d",&point[i],&t); + for(j=1;j<=t;j++) + { + scanf("%d",&x); + edge[c].to=x; + edge[c].next=head[i]; + head[i]=c; + edge1[c].to=i; + edge1[c].next=head1[x]; + head1[x]=c++; + } + } + dfs(n); + if(!ac[1]) printf("hopeless\n"); + else + { + for(i=1;i<=n;i++) isin[i]=0; + bool ju=false; + total[1]=100; + ptr=0; + stack[++ptr]=1; + while(ptr&&!ju) + { + top=stack[ptr--]; + isin[top]=2; + for(k=head[top];k!=-1&&!ju;k=edge[k].next) + { + if(ac[edge[k].to]) + { + int temp=total[top]+point[edge[k].to]; + if(temp>0&&temp>total[edge[k].to]) + { + total[edge[k].to]=temp; + if(edge[k].to==n||isin[edge[k].to]==2) ju=true; + else if(!isin[edge[k].to]) + { + stack[++ptr]=edge[k].to; + isin[edge[k].to]=1; + } + } + } + } + } + if(ju) printf("winnable\n"); + else printf("hopeless\n"); + } + } + return 0; +} diff --git a/HDOJ/1318_autoAC.cpp b/HDOJ/1318_autoAC.cpp new file mode 100644 index 0000000..3292d7f --- /dev/null +++ b/HDOJ/1318_autoAC.cpp @@ -0,0 +1,13 @@ +Character Reverse Character Reverse Character Reverse + A A M M Y Y + B N Z 5 + C O O 1 1 + D P 2 S + E 3 Q 3 E + F R 4 + G S 2 5 Z + H H T T 6 + I I U U 7 + J L V V 8 8 + K W W 9 + L J X X diff --git a/HDOJ/1319_autoAC.cpp b/HDOJ/1319_autoAC.cpp new file mode 100644 index 0000000..309180a --- /dev/null +++ b/HDOJ/1319_autoAC.cpp @@ -0,0 +1,31 @@ +#include +#include +#include +using namespace std; +int main() +{ + int p[1001],vis[1001],k=0; + memset(vis,0,sizeof(vis)); + memset(p,0,sizeof(p)); + for(int i=2; i*i<=1000; i++) + for(int j=i*i; j<=1000; j+=i) + vis[j]=1; + for(int i=1; i<=1000; i++) + if(!vis[i]) + p[k++]=i; + int n,m; + while(cin>>n>>m) + { + int sum=0; + for(int i=1; i<=n; i++) + if(!vis[i]) + sum++; + int c=(sum>>1)-m+(sum&1); + c=(c<0)?0:c; + printf("%d %d:", n, m); + for(int i=c; i +#include +using namespace std; +int a[100],b[100]; +int main() +{ + int N,i,j; + while(cin>>N&&N) + { + memset(a,0,sizeof(a)); + memset(b,0,sizeof(b)); + char c; + cin>>c; + if(c=='P') + { + for(i=1;i<=N;i++) + cin>>b[i]; + for(i=1;i<=N;i++) + { + for(j=1;jb[i]) + a[b[i]]++; + } + for(i=1;i>a[i]; + for(i=1;i<=N;i++) + { + j=1; + int k=1; + while(1) + { + if(b[k]==0&&j>a[i]) + break; + if(b[k]==0) + j++; + k++; + } + b[k]=i; + } + for(i=1;i +int main() +{ + int n; + scanf("%d",&n); + getchar(); + while(n--) + { + char a[100]; + int i=0; + while(1) + { + a[i]=getchar(); + if(a[i]=='\n') + break; + i++; + } + i--; + for(;i>=0;i--) + putchar(a[i]); + printf("\n"); + } +} diff --git a/HDOJ/1322_autoAC.cpp b/HDOJ/1322_autoAC.cpp new file mode 100644 index 0000000..b1ee408 --- /dev/null +++ b/HDOJ/1322_autoAC.cpp @@ -0,0 +1,18 @@ +#include +int main() +{ + double in; + int out,count = 1; + while(scanf("%lf",&in)!=EOF,in!=0) + { + in *= 0.75; + in /= (1.86*1000000); + out = (int)in; + if(in - out != 0) + { + out++; + } + printf("File #%d\nJohn needs %d floppies.\n\n",count++,out); + } + return 0; +} diff --git a/HDOJ/1323_autoAC.cpp b/HDOJ/1323_autoAC.cpp new file mode 100644 index 0000000..57f5d86 --- /dev/null +++ b/HDOJ/1323_autoAC.cpp @@ -0,0 +1,36 @@ +#include +#include +using namespace std; +int t[103]; +int judge(int n) +{ + int sum=0; + for(int i=1;in) + return 1; +} +int main() +{ + int i,num=0; + while(cin>>t[++num]&&t[num]); + --num; + cout<<"PERFECTION OUTPUT"< +using namespace std; +int record[100000]; +int main() +{ + int z,i,m,l,j; + int key=1; + while(cin>>z>>i>>m>>l) + { + if(z==0&&i==0&&m==0&&l==0) + break; + int k=1; + record[0]=l; + int flag=0; + while(1) + { + l=(z*l+i)%m; + for( j=0;j +#include +using namespace std; +int father[100010]; +int findfather(int x) +{ + while (father[x]!=x) + x=father[x]; + return x; +} +bool is_father(int m,int n) +{ + while (father[m]!=n) + { + if (father[m]==m) return true; + m=father[m]; + } + return false; +} +int main() +{ + bool e,flag; + int times=0; + int maxx,root,m,n,t; + while (cin >> m >> n && (m>=0 && n>=0)) + { + memset(father,0,sizeof(father)); + e=false;flag=true; + root=-1; + maxx=0; + while ((m+n)!=0) + { + if (e) cin >> m >> n; + if (m+n==0) break; + if (maxx +int main() +{ + int n,t=0,i,sum,a[100]; + int flag; + while(scanf("%d",&n)!=EOF) + { + if(n==0)break; + t++; + for(i=0,sum=0;isum) + flag=flag+a[i]-sum; + } + printf("Set #%d\nThe minimum number of moves is %d.\n\n",t,flag); + } + return 0; +} diff --git a/HDOJ/1327_autoAC.cpp b/HDOJ/1327_autoAC.cpp new file mode 100644 index 0000000..b1d6283 --- /dev/null +++ b/HDOJ/1327_autoAC.cpp @@ -0,0 +1,41 @@ +#include +using namespace std; +bool al[26]={false}; +int main() +{ + int n; + int T=1; + while(cin>>n&&n!=0) + { + memset(al,0,sizeof(al)); + al[0]=1; + char c1,c2,c3; + while(n--) + { + cin>>c1>>c2>>c3; + if(al[c3-'a']==0) + al[c1-'a']=0; + else + { + al[c1-'a']=1; + } + } + int ok=0; + cout<<"Program #"< +#include +int main() +{ + int n,m,i,p,t; + char a[1000]; + scanf("%d",&n); + getchar(); + for(i=1;i<=n;i++) + { + gets(a); + p=strlen(a); + printf("String #%d\n",i); + for(t=0;t +#include +#include +using namespace std; +#define MAXN 50 +int main(int ac, char *av[]) +{ + vector < vector < int > > number; + vector < int > result; + int pegs = 1; + number.resize(MAXN + 2); + for (int i = 1; i <= MAXN; i++) + number[i].push_back(0); + for (int current = 1; pegs <= MAXN;) + { + bool successed = false; + for (int c = 1; c <= pegs; c++) + { + int top = current + number[c][number[c].size() - 1]; + int value = sqrt(top); + if (value * value == top) + { + number[c].push_back(current); + successed = true; + break; + } + } + if (successed == false) + { + result.push_back(current - 1); + pegs++; + number[pegs].push_back(current); + current++; + } + else + current++; + } + int cases, n; + cin >> cases; + while (cases--) + { + cin >> n; + cout << result[n - 1] << endl; + } + return 0; +} diff --git a/HDOJ/1330_autoAC.cpp b/HDOJ/1330_autoAC.cpp new file mode 100644 index 0000000..13b55aa --- /dev/null +++ b/HDOJ/1330_autoAC.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +using namespace std; +int main() +{ + int n,i; + double sum; + int f=1; + while(scanf("%d",&n)!=EOF) + { + if(f) + { + printf("# Cards Overhang\n");f=0; + } + sum=0; + for(i=1;i<=n;i++) + { + sum=sum+1.0/(2*i); + } + printf("%5d %.3lf\n",n,sum); + } + return 0; +} diff --git a/HDOJ/1331_autoAC.cpp b/HDOJ/1331_autoAC.cpp new file mode 100644 index 0000000..a74b939 --- /dev/null +++ b/HDOJ/1331_autoAC.cpp @@ -0,0 +1,37 @@ +#include +using namespace std; +int x[21][21][21]={0}; +int w(int a,int b,int c) +{ + if(a<=0||b<=0||c<=0) + return 1; + if(x[a][b][c]!=0) + return x[a][b][c]; + if(a>a>>b>>c&&!(a==-1&&b==-1&&c==-1)) + { + if(a<=0||b<=0||c<=0) + { + printf("w(%d, %d, %d) = %d\n",a,b,c,1); + continue; + } + if(a>20||b>20||c>20) + printf("w(%d, %d, %d) = %d\n",a,b,c,w(20,20,20)); + else + printf("w(%d, %d, %d) = %d\n",a,b,c,w(a,b,c)); + } + return 0; +} diff --git a/HDOJ/1332_autoAC.cpp b/HDOJ/1332_autoAC.cpp new file mode 100644 index 0000000..10baa06 --- /dev/null +++ b/HDOJ/1332_autoAC.cpp @@ -0,0 +1,127 @@ +#include +int col,s; +void out(int step,int shu) +{ + int i,j; + if(step==1) + { + if(shu==1||shu==4) + { + for(i=1;i<=col;i++) + printf(" "); + } + else + { + printf(" "); + for(i=1;i<=col-2;i++) + printf("-"); + printf(" "); + } + } + else + if(step==2*s+3) + { + if(shu==1||shu==4||shu==7) + { + for(i=1;i<=col;i++) + printf(" "); + } + else + { + printf(" "); + for(i=1;i<=col-2;i++) + printf("-"); + printf(" "); + } + } + else + if(step==(2*s+4)/2) + { + if(shu==1||shu==7||shu==0) + for(i=1;i<=col;i++) + printf(" "); + else + { + printf(" "); + for(i=1;i<=col-2;i++) + printf("-"); + printf(" "); + } + } + else + if(step<(2*s+4)/2) + { + if(shu==1||shu==2||shu==7||shu==3) + { + for(i=1;i0) + { + t[x++]=n%10; + n/=10; + } + col=2+s; + for(i=1;i<=2*s+3;i++) + { + for(j=x-1;j>=0;j--) + { + out(i,t[j]); + if(j>0) + printf(" "); + } + printf("\n"); + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1333_autoAC.cpp b/HDOJ/1333_autoAC.cpp new file mode 100644 index 0000000..ba74d6e --- /dev/null +++ b/HDOJ/1333_autoAC.cpp @@ -0,0 +1,65 @@ +#include +#include +#include +#include +using namespace std; +int n; +bool isprime[10100]; +vector prime,a; +int sum(int n) +{ + int ans=0; + while(n) + { + ans+=n%10; + n/=10; + } + return ans; +} +void init() +{ + memset(isprime,0,sizeof(isprime)); + isprime[0]=isprime[1]=true; + for(int i=2;i<=10010;i++) + { + if(isprime[i]==false) + { + prime.push_back(i); + a.push_back(sum(i)); + for(int j=i+i;j<=10010;j+=i) + isprime[j]=true; + } + } +} +bool issame(int n) +{ + int ans1=sum(n),ans2=0; + if(n<=10010&&isprime[n]==false) + return false; + for(int i=0;i +#include +using namespace std; +int main() +{ + for(int a=3;a!=201;++a) + { + for(int i=2;i<=200;++i) + { + for(int j=i;j<=200;++j) + { + for(int k=j;k<=200;++k) + { + if(i*i*i+j*j*j+k*k*k==a*a*a) + cout<<"Cube = "< +#include +#include +#include +using namespace std; +int powe(int,int); +int main() +{ + string s; + short b,e; + while(cin>>s>>b>>e) + { + vector v; + string str=""; + int sum=0; + for(int i=s.size()-1,c=0;i>=0;--i,++c) + { + if(s[i]>='0'&&s[i]<='9') + sum+=(s[i]-48)*powe(b,c); + if(s[i]>='A'&&s[i]<='F') + sum+=(s[i]-55)*powe(b,c); + } + int r; + while(sum!=0) + { + r=sum%e; + if(r>=0&&r<=9) + v.push_back(r+48); + else if(r==10) + v.push_back('A'); + else if(r==11) + v.push_back('B'); + else if(r==12) + v.push_back('C'); + else if(r==13) + v.push_back('D'); + else if(r==14) + v.push_back('E'); + else + v.push_back('F'); + sum/=e; + } + for(int i=v.size()-1;i>=0;--i) + str+=v[i]; + if(str.size()>7) + cout< +#include +#include +#include +using namespace std; +map table; +int main() +{ + int cnt = 1; + for(char i = 'a'; i <= 'z'; ++i) + { + string tmp; + tmp += i; + table[tmp] = cnt ++; + } + for(char i = 'a'; i <= 'z'; ++i) + for(char j = i + 1; j <= 'z'; ++j) + { + string tmp; + tmp += i;tmp += j; + table[tmp] = cnt ++; + } + for(char i = 'a'; i <= 'z'; ++i) + for(char j = i + 1; j <= 'z'; ++j) + for(char k = j + 1; k <= 'z'; ++k) + { + string tmp; + tmp += i;tmp += j;tmp += k; + table[tmp] = cnt ++; + } + for(char i = 'a'; i <= 'z'; ++i) + for(char j = i + 1; j <= 'z'; ++j) + for(char k = j + 1; k <= 'z'; ++k) + for(char l = k + 1; l <= 'z'; ++l) + { + string tmp; + tmp += i;tmp += j;tmp += k;tmp += l; + table[tmp] = cnt ++; + } + for(char i = 'a'; i <= 'z'; ++i) + for(char j = i + 1; j <= 'z'; ++j) + for(char k = j + 1; k <= 'z'; ++k) + for(char l = k + 1; l <= 'z'; ++l) + for(char m = l + 1; m <= 'z'; ++m) + { + string tmp; + tmp += i;tmp += j;tmp += k;tmp += l;tmp += m; + table[tmp] = cnt ++; + } + string word; + while(cin >> word) + { + map::iterator it = table.find(word); + if(it == table.end()) + {cout << 0 << endl;} + else + {cout << it->second << endl;} + } + return 0; +} diff --git a/HDOJ/1337_autoAC.cpp b/HDOJ/1337_autoAC.cpp new file mode 100644 index 0000000..e465391 --- /dev/null +++ b/HDOJ/1337_autoAC.cpp @@ -0,0 +1,33 @@ +#include +#include +#include +int main() +{ + int n,a[20000],i,j,k,m,t,f; + while(scanf("%d",&n)!=EOF&&n) + { + while(n--) + { t=0; + memset(a,0,sizeof(a)); + scanf("%d",&m); + f=2; + while(f<=m) + { + for(i=f;i<=m;i+=f) + { + if(a[i]==1) + a[i]=0; + else + a[i]=1; + } + f++; + } + for(i=1;i<=m;i++) + { if(a[i]==0) + t++; + } + printf("%d\n",t); + } + } + return 0; +} diff --git a/HDOJ/1338_autoAC.cpp b/HDOJ/1338_autoAC.cpp new file mode 100644 index 0000000..fbf37c7 --- /dev/null +++ b/HDOJ/1338_autoAC.cpp @@ -0,0 +1,31 @@ +#include +#include +using namespace std; +int cmp(int x,int y) +{ + return x>y; + } +int main() +{ + int n,i,j,k; + int a[60]; + i=0; + while(cin>>n>>k&&(n||k)) + { + i++; + for(j=0;j>a[j]; + sort(a,a+k,cmp); + int max=n*k; + int count=0; + for(j=0;j +#include +using namespace std; +int main() +{ + int t,n,q; + cin>>t; + while(t--) + { + cin>>n; + for(int p=0;p<=log(n)+1;p++) + { + q=1< +#include +using namespace std; +unsigned char ins[32], accu, pc; +char str[10]; +unsigned char getValue(char *ins) +{ + unsigned char res(0); + for(int i(0); i<8; ++i) res = res * 2 + ins[i] - '0'; + return res; +} +int main() +{ + bool halt; + int type, value; + while(scanf("%s", str) != EOF) + { + ins[0] = getValue(str); + for(int i(1); i<32; ++i) scanf("%s", str), ins[i] = getValue(str); + halt = false; + pc = accu = 0; + while(!halt) + { + type = ins[pc] >> 5; + value = ins[pc] % 32; + switch(type) + { + case 0: + ins[value] = accu; + pc = (pc + 1) % 32; + break; + case 1: + accu = ins[value]; + pc = (pc + 1) % 32; + break; + case 2: + if(!accu) pc = value; + else pc = (pc + 1) % 32; + break; + case 3: + pc = (pc + 1) % 32; + break; + case 4: + --accu; + pc = (pc + 1) % 32; + break; + case 5: + ++accu; + pc = (pc + 1) % 32; + break; + case 6: + pc = ins[pc] % 32; + break; + case 7: + halt = true; + break; + } + } + for(int i(7); i>=0; --i) + printf("%d", (accu >> i) & 1); + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1342_autoAC.cpp b/HDOJ/1342_autoAC.cpp new file mode 100644 index 0000000..7253b40 --- /dev/null +++ b/HDOJ/1342_autoAC.cpp @@ -0,0 +1,39 @@ +#include +#include +using namespace std; +int a[20]; +int main() +{ + int k,i,j,l,m,n,q,t=0; + while (scanf("%d",&k)!=EOF&&k) + { + if (t!=0) + printf ("\n"); + t++; + for (i=0;i +#include +#include +#include +using namespace std; +#define maxn 2005 +int fn, gn, hn, en; +int f[maxn], g[maxn], h[maxn], e[maxn]; +void input() +{ + scanf("%d", &fn); + for (int i = fn -1; i >=0; i--) + scanf("%d", &f[i]); + scanf("%d", &gn); + for (int i = gn -1; i >=0; i--) + scanf("%d", &g[i]); + scanf("%d", &hn); + for (int i = hn -1; i >=0; i--) + scanf("%d", &h[i]); +} +void mul() +{ + memset(e, 0, sizeof(e)); + for (int i =0; i < fn; i++) + for (int j =0; j < gn; j++) + e[i + j] ^= f[i] * g[j]; + en = fn + gn; + while (en >=0&& e[en] ==0) + en--; + en++; +} +void mo() +{ + while (en >= hn) + { + int d = en - hn; + for (int i = hn -1; i >=0; i--) + e[i + d] ^= h[i]; + while (en >=0&& e[en] ==0) + en--; + en++; + } +} +int main() +{ + int t; + scanf("%d", &t); + while (t--) + { + input(); + mul(); + mo(); + printf("%d", en); + for (int i = en -1; i >=0; i--) + printf(" %d", e[i]); + putchar('\n'); + } + return 0; +} diff --git a/HDOJ/1344_autoAC.cpp b/HDOJ/1344_autoAC.cpp new file mode 100644 index 0000000..631c112 --- /dev/null +++ b/HDOJ/1344_autoAC.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +using namespace std; +const int N = 8; +struct Traffic +{ + double pos; + int g, y, r; +}; +Traffic traffic[N]; +int n; +bool input(); +void solve(); +int main() +{ + int t = 1; + while (input()) { + printf("Case %d:", t++); + solve(); + } + return 0; +} +bool input() +{ + scanf("%d", &n); + if (n < 0) return false; + for (int i = 0; i < n; i++) { + scanf("%lf%d%d%d", &traffic[i].pos, &traffic[i].g, &traffic[i].y, &traffic[i].r); + } + return true; +} +void solve() +{ + vector ans; + for (int i = 30; i <= 60; i++) { + bool ok = true; + for (int j = 0; j < n; j++) { + int t = (int)(traffic[j].pos * 3600 / i); + if (t % (traffic[j].g + traffic[j].y + traffic[j].r) >= traffic[j].g + traffic[j].y) { + ok = false; + break; + } + } + if (ok) ans.push_back(i); + } + if (ans.empty()) { + printf(" No acceptable speeds.\n"); + } else { + bool first = true; + for (size_ i = 0; i < ans.size(); i++) { + size_ j = i; + while (j + 1 < ans.size() && ans[j + 1] - ans[j] == 1) { + j++; + } + if (first) { + first = false; + if (j - i >= 1) { + printf(" %d-%d", ans[i], ans[j]); + } else { + printf(" %d", ans[i]); + } + } else { + if (j - i >= 1) { + printf(", %d-%d", ans[i], ans[j]); + } else { + printf(", %d", ans[i]); + } + } + i = j; + } + printf("\n"); + } +} diff --git a/HDOJ/1345_autoAC.cpp b/HDOJ/1345_autoAC.cpp new file mode 100644 index 0000000..9c3368b --- /dev/null +++ b/HDOJ/1345_autoAC.cpp @@ -0,0 +1,107 @@ +#include +#include +#include +using namespace std; +double r[4]; +int is_integer(double t) +{ + int i=t+0.0000005; + if(fabs(t-i)<0.000001) + return i; + return 0; +} +int try_height(int i,int sw) +{ + double dh=sw/r[i]; + int h=dh+.0000005; + if(fabs(h-dh)<0.000001) + return h; + return -1; +} +int try_weight(int i,int sh) +{ + double dw=sh*r[i]; + int w=dw+.0000005; + if(fabs(w-dw)<0.000001) + return w; + return -1; +} +bool fill(int sw, int sh) +{ + int w,h,tw,th,j,k,a[4]={0,1,2,3}; + for(j=0;j<24;j++) + { + tw=sw,th=sh; + for(k=0;k<4&&th&&tw;k++) + { + h=try_height(a[k],tw); + if(h!=-1&&h<=th) + th-=h; + else + { + w=try_weight(a[k],th); + if(w==-1||w>tw) + break; + tw-=w; + } + } + if (k==4&&(!tw||!th)) + return true; + next_permutation(a,a+4); + } + return false; +} +int fit(int w ,int i,int j) +{ + double h=w/(r[i]+r[j]); + int ret=is_integer(h); + if(is_integer(h*r[i]) && is_integer(h*r[j])) + return ret; + return 0; +} +bool mixture(int sw,int sh) +{ + int a[4]={0,1,2,3}; + int i,j,k,h1,h2,tw,th; + for(i=0;i<24;i++) + { + tw=sw,th=sh; + h1=fit(tw,a[0],a[1]); + h2=fit(tw,a[2],a[3]); + if(h1&&h2&&h1+h2==sh) + return true; + next_permutation(a,a+4); + } + return false; +} +int main() +{ + int i,t,w,h,sw,sh; + for(t=1;scanf("%d%d",&sw,&sh),sw+sh;t++) + { + bool found=false; + for(i=0;i<4;i++) + { + scanf("%d%d",&w,&h); + r[i]=w*1.0/h; + } + if(fill(sw,sh)) + found=true; + else + { + if(mixture(sw,sh)) + found=true; + else + { + for(i=0;i<4;i++) + r[i]=1/r[i]; + found=mixture(sh,sw); + } + } + if(found) + printf("Set %d: Yes\n",t); + else + printf("Set %d: No\n",t); + } + return 0; +} diff --git a/HDOJ/1346_autoAC.cpp b/HDOJ/1346_autoAC.cpp new file mode 100644 index 0000000..dc351f1 --- /dev/null +++ b/HDOJ/1346_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +using namespace std; +int main() +{ + int sum; + while(scanf("%d",&sum)!=EOF) + { + if(sum==-1) + break; + int totle, num=-1; + for(int i=10;i>1;i--) + { + totle=sum; + bool bo=true; + for(int j=1;j<=i;j++) + { + if((totle-1)%i==0) + { + totle=(totle-1)/i*(i-1); + } + else + { + bo=false; + break; + } + } + if(totle%i!=0) + bo=false; + if(bo) + { + num=i; + break; + } + } + if(num!=-1) + printf("%d coconuts, %d people and 1 monkey\n",sum,num); + else + printf("%d coconuts, no solution\n",sum); + } +} diff --git a/HDOJ/1347_autoAC.cpp b/HDOJ/1347_autoAC.cpp new file mode 100644 index 0000000..d7b5d6d --- /dev/null +++ b/HDOJ/1347_autoAC.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +using namespace std; +int b[10005]; +int main() +{ + int n,m,i,j,max1,max2,l; + int a; + while(scanf("%d %d",&n,&m)!=EOF&&n!=0||m!=0) + { + memset(b,0,sizeof(b)); + for(i=0;imax1) + { + max2=max1; + max1=b[i]; + } + else + { + if(b[i]>max2) + { + max2=b[i]; + } + } + } + l=0; + for(i=1;i<=10000;i++) + { + if(b[i]==max2) + { + if(l==0) + { + printf("%d",i); + l++; + } + else + printf(" %d",i); + } + } + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1348_autoAC.cpp b/HDOJ/1348_autoAC.cpp new file mode 100644 index 0000000..0df51ec --- /dev/null +++ b/HDOJ/1348_autoAC.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +#include +#include +#include +#include +#include +const int MAX=1001; +const double PI=3.1415926; +int n; +int top; +using namespace std; +typedef struct Node +{ + double x; + double y; +}; +Node s[MAX],stack[MAX]; +double Distance(Node a,Node b) +{ + return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)); +} +double Mul(Node p2, Node p1, Node p0) +{ + return (p2.x - p0.x) * (p1.y - p0.y) - (p1.x - p0.x) * (p2.y - p0.y); +} +bool cmp(Node p2,Node p1) +{ + double m; + m=Mul(p2,p1,s[0]); + if(m>0||(!m&&Distance(s[0],p2)=1&&Mul(s[i],stack[top],stack[top-1])>=0) + top--; + top++; + stack[top]=s[i]; + } +} +int main() +{ + int i,p=0,t,l; + double sum; + while(cin>>t) + { + while(t--) + { + cin>>n>>l; + cout.setf(ios::fixed); + cout.precision(0); + for(i=0;i>s[i].x>>s[i].y; + convex_hull(); + sum=0; + for(i=0;i +#include +#include +#include +#include +using namespace std; +#define maxn 505 +struct Elem +{ + int x1, y1, x2, y2; + int s, e; +} ride[maxn]; +int n; +int uN, vN; +bool g[maxn][maxn]; +int xM[maxn], yM[maxn]; +bool chk[maxn]; +int cal(int h, int m) +{ + return h * 60 + m; +} +int dist(int x1, int y1, int x2, int y2) +{ + return abs(x1 - x2) + abs(y1 - y2); +} +void input() +{ + scanf("%d", &n); + for (int i = 0; i < n; i++) + { + int h, m; + scanf("%d:%d", &h, &m); + ride[i].s = cal(h, m); + scanf("%d%d%d%d", &ride[i].x1, &ride[i].y1, &ride[i].x2, &ride[i].y2); + ride[i].e = ride[i].s + dist(ride[i].x1, ride[i].y1, ride[i].x2, ride[i].y2); + } +} +bool ok(Elem &a, Elem &b) +{ + return dist(a.x2, a.y2, b.x1, b.y1) + a.e < b.s; +} +void make() +{ + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + g[i][j] = ok(ride[i], ride[j]); +} +bool SearchPath(int u) +{ + int v; + for (v = 0; v < vN; v++) + if (g[u][v] && !chk[v]) + { + chk[v] = true; + if (yM[v] == -1 || SearchPath(yM[v])) + { + yM[v] = u; + xM[u] = v; + return true; + } + } + return false; +} +int MaxMatch() +{ + int u, ret = 0; + memset(xM, -1, sizeof(xM)); + memset(yM, -1, sizeof(yM)); + for (u = 0; u < uN; u++) + if (xM[u] == -1) + { + memset(chk, false, sizeof(chk)); + if (SearchPath(u)) + ret++; + } + return ret; +} +int main() +{ + int t; + scanf("%d", &t); + while (t--) + { + input(); + make(); + uN = vN = n; + printf("%d\n", n - MaxMatch()); + } + return 0; +} diff --git a/HDOJ/1351_autoAC.cpp b/HDOJ/1351_autoAC.cpp new file mode 100644 index 0000000..ada6de1 --- /dev/null +++ b/HDOJ/1351_autoAC.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; +int num[10],ans,C; +void cal(int p, int s) +{ + if(p==32) return; + int sum=s,i; + for(i=0;i<8;i++) sum+=(num[i]>>p)&1; + if((sum&1)!=((num[8]>>p)&1)) + { + ans|=1<>p)&1)^1; + } + cal(p+1,sum/2); +} +int main() +{ + for(scanf("%d",&C);C--;) + { + for(int i=0;i<9;i++) scanf("%x",&num[i]); + ans=0; + cal(0,0); + printf("%x\n",ans); + } + return 0; +} diff --git a/HDOJ/1352_autoAC.cpp b/HDOJ/1352_autoAC.cpp new file mode 100644 index 0000000..86ebf00 --- /dev/null +++ b/HDOJ/1352_autoAC.cpp @@ -0,0 +1,112 @@ +#include +#include +#include +#include +#include +#include +#include +#define eps 1e-8 +using namespace std; +struct Point +{ + double x,y; + Point(){} + Point(double x0,double y0):x(x0),y(y0){} + void Input() + { + scanf("%lf%lf",&x,&y); + } +}; +struct Line +{ + Point a,b; + double inter,k; + Line(){} + Line(Point a0,Point b0):a(a0),b(b0){} +}; +double Xmult(Point o,Point a,Point b) +{ + return (a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y); +} +int Sig(double a) +{ + return a<-eps?-1:a>eps; +} +int cmp(Line l1,Line l2) +{ + if(!Sig(l1.k-l2.k) && !Sig(l1.inter-l2.inter) && !Sig(l1.a.x-l2.a.x)) + return l1.b.x v) +{ + int n=v.size(); + for(int i=0;i v; + vector v1; + while(scanf("%d",&n) && n) + { + v.clear(); + v1.clear(); + for(int i=0;ib.x) + swap(a,b); + if(a.x==b.x) + v1.push_back(Line(a,b)); + else + v.push_back(Line(a,b)); + } + int ans=0; + ans=Count(v); + for(int i=0;iv1[i].b.y) + swap(v1[i].a,v1[i].b); + } + sort(v1.begin(),v1.end(),cmp1); + for(int i=1;i +#include +#include +using namespace std; +int dp[700]; +int pr[700]; +int main() +{ + int a,b[5],c[5]={25,10,5,1},op[50]; + char s[100]; + op[25]=0;op[10]=1;op[5]=2;op[1]=3; + while(scanf(" %s %d %d %d %d",s,&b[0],&b[1],&b[2],&b[3])!=EOF) + { + memset(dp,-1,sizeof(dp)); + dp[0]=0; + bool flag=false; + int pos; + for(int i=0;s[i]!='\0';i++) + if(s[i]=='.') + { + pos=i; + flag=true; + break; + } + if(flag) + { + int x,y; + sscanf(s,"%d.%d",&x,&y); + if(y<10&&s[pos+1]!='0') + y*=10; + a=x*100+y; + } + else + sscanf(s,"%d",&a); + for(int i=0;i<4;i++) + { + int v=c[i],n=b[i]; + if(n*v>=a) + for(int i=0;i+v<=a;i++) + { + if(dp[i]!=-1&&(dp[i+v]==-1||dp[i+v]>dp[i]+1)) + dp[i+v]=dp[i]+1,pr[i+v]=i; + } + else + { + while(n--) + for(int i=a;i-v>=0;i--) + if(dp[i-v]!=-1&&(dp[i]==-1||dp[i]>dp[i-v]+1)) + dp[i]=dp[i-v]+1,pr[i]=i-v; + } + } + if(dp[a]==-1) + puts("NO EXACT CHANGE"); + else + { + int tot[4]; + memset(tot,0,sizeof(tot)); + for(int i=a;i!=0;tot[op[i-pr[i]]]++,i=pr[i]); + printf("%d %d %d %d\n",tot[0],tot[1],tot[2],tot[3]); + } + } + return 0; +} diff --git a/HDOJ/1354_autoAC.cpp b/HDOJ/1354_autoAC.cpp new file mode 100644 index 0000000..81af3ae --- /dev/null +++ b/HDOJ/1354_autoAC.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +using namespace std; +typedef struct +{ + int next1,next2; + char type; + string text; + string end; +}Page; +Page page[101]; +int mark[101]; +int path[101]; +void init() +{ + for(int i = 0;i < 101; i++) + { + page[i].end = ""; + page[i].text = ""; + page[i].next1 = 0; + page[i].next2 = 0; + mark[i] = 0; + path[i] = 0; + } +} +bool dfs(int p,int k) +{ + if(mark[p]==1) + return false; + path[k] = p; + mark[p] = 1; + if(page[p].type=='E'&&page[p].end.compare("HAPPY")==0) + return true; + if(page[p].type == 'C') + { + if(dfs(page[p].next1,k+1)) + return true; + if(dfs(page[p].next2,k+1)) + return true; + } + path[k] = 0; + mark[p] = 0; + return false; +} +void print() +{ + int i = 1; + while(path[i]!=0) + { + cout<>n; + for(int m = 1; m <= n; m++) + { + cin>>x; + getchar(); + init(); + for(int i = 1; i <= x; i++) + { + getline(cin,line); + if(line[0] == 'C') + { + page1 = atoi(line.substr(line.find_last_of("\"")+2,1).c_str()); + page2 = atoi(line.substr(line.find_last_of("\"")+4,1).c_str()); + text = line.substr(line.find_first_of("\"")+1,line.find_last_of("\"")-line.find_first_of("\"")-1); + page[i].next1 = page1; + page[i].next2 = page2; + page[i].text = text; + page[i].type = 'C'; + }else if(line[0] == 'E') + { + text = line.substr(line.find_first_of("\"")+1,line.find_last_of("\"")-line.find_first_of("\"")-1); + end = line.substr(line.find_last_of("\"")+2,line.length()-line.find_last_of("\"")); + page[i].end = end; + page[i].text = text; + page[i].type = 'E'; + } + line = ""; + cin.clear(); + } + mark[1] = 1; + path[1] = 1; + cout<<"STORY "< +#include +#include +using namespace std; +int abss(int x) +{ + if(x>0) + return x; + return -x; +} +struct aa +{ + int x,y,c; +}a[5000]; +bool camp(aa x,aa y) +{ + return x.c>y.c; +} +int main () +{ + int xx,yy,i,j,sum,maxt,t,q,w,ss; + scanf("%d",&t); + while(t--) + { + scanf("%d%d%d",&xx,&yy,&maxt); + for(w=i=1;i<=xx;i++) + for(j=1;j<=yy;j++) + { + scanf("%d",&q); + a[w].x=i; + a[w].y=j; + a[w].c=q; + w++; + } + sort(a+1,a+w,camp); + for(ss=sum=0,i=1;i +#include +int next[1000005],n; +char s[1000005]; +void getnext(char *s) +{ + int i,j; + memset(next,0,sizeof(next)); + next[0]=-1; + i=0; + j=-1; + while(i1) + { + printf("%d %d\n",i,i/len); + } + } + printf("\n"); + } +} diff --git a/HDOJ/1361_autoAC.cpp b/HDOJ/1361_autoAC.cpp new file mode 100644 index 0000000..b360e4e --- /dev/null +++ b/HDOJ/1361_autoAC.cpp @@ -0,0 +1,3 @@ +S(((()()()))) +P-sequence 4 5 6666 +W-sequence 1 1 1456 diff --git a/HDOJ/1362_autoAC.cpp b/HDOJ/1362_autoAC.cpp new file mode 100644 index 0000000..ff03c4c --- /dev/null +++ b/HDOJ/1362_autoAC.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +#include +using namespace std; +int hexagon[110][110]; +int ori_size,n,cut_size[11]; +bool can_cut(int x,int y,int size) +{ + int i,j; + if (y+2*size-2>ori_size*4 || x+size-1>ori_size*2) + return false; + if (y%2==1) + { + for (i=0;iori_size*2) + return true; + if (y>4*ori_size) + return dfs(x+1,1); + if (hexagon[x][y]==false) + { + for (j=y+1;j<=4*ori_size;j++) + if (hexagon[x][j]) + break; + return dfs(x,j); + } + for (i=0;iori_size) + { + n=i-1; + break; + } + for (i=0;i +#include +#include +using namespace std; +const int mx=111; +int mp[mx][mx],T,n,m,num,ans; +bool used[mx][mx]; +int dx[]={0,0,1,-1},dy[]={-1,1,0,0}; +struct MOVE +{ + int least,most,dir; +}mov[1000]; +bool dfs(int x,int y,int co,int step) +{ + if(step==num) + { + return true; + } + if(co>=mov[step].least&&co<=mov[step].most) + { + if(dfs(x,y,0,step+1)) + return true; + } + if(co=0&&nx=0&&ny>c; + if(c=='R')mov[num++].dir=1; + else if(c=='L') mov[num++].dir=0; + else if(c=='U') mov[num++].dir=3; + else mov[num++].dir=2; + } + ans=0; + for(int i=0;i +#include +#include +#include +using namespace std; +struct node{ + int right,child; + char ch; + bool end; +}tree[350010]; +int index = 1,cnt = 0,mat[100],tl[100]; +char answer[128],key[125],list[100][30]; +bool used[128],findans,matched[100]; +void insert(int p,char *word){ + if (tree[p].ch){ + if (tree[p].ch == *word){ + if (!*(word + 1)) tree[p].end = 1; + else{ + if(!tree[p].child) tree[p].child = ++index; + insert(tree[p].child,word + 1); + } + } + else{ + if (tree[p].right) insert(tree[p].right,word); + else { + tree[p].right = ++ index; + insert(tree[p].right,word); + } + } + } + else{ + tree[p].ch = *word; + if (!*(word + 1)) tree[p].end = 1; + else{ + tree[p].child = ++ index; + insert(tree[p].child,word + 1); + } + } +} +int findwordmat(){ + for (int i = 0;i < cnt;i ++){ + mat[i] = 0; + for (int j = 0;j < tl[i];j ++) + if (key[list[i][j]]) + ++ mat[i]; + } +} +int subsearch(int cur,int wi,int num,int tnum); +int search(int cur){ + if (cur == cnt){ + if (findans) return 2; + findans = 1; + for (int i = 'A';i <= 'Z';i ++) answer[key[i]] = i; + return 1; + } + findwordmat(); + int m = -1,wi; + for (int i = 0;i < cnt;i ++) + if (!matched[i] && mat[i] > m){ + m = mat[i]; + wi = i; + } + return subsearch(cur,wi,0,1); +} +int subsearch(int cur,int wi,int num,int tnum){ + if (num == tl[wi]){ + matched[wi] = true; + int tmp = search(cur + 1); + matched[wi] = false; + return tmp; + } + if (!tnum) return 0; + char cc = list[wi][num]; + if (key[cc]){ + for (;tnum;tnum = tree[tnum].right) + if (tree[tnum].ch == key[cc]){ + if (num + 1 == tl[wi] && !tree[tnum].end) return 0; + return subsearch(cur,wi,num + 1,tree[tnum].child); + } + return 0; + }else{ + int find = 0; + for (;tnum;tnum = tree[tnum].right) + if (!used[tree[tnum].ch]){ + if (num + 1 == tl[wi] && !tree[tnum].end) continue; + used[tree[tnum].ch] = true; + key[cc] = tree[tnum].ch; + int tmp = subsearch(cur,wi,num + 1,tree[tnum].child); + key[cc] = 0; + used[tree[tnum].ch] = false; + if (tmp == 2) return tmp; + if (tmp == 1) find = tmp; + } + return find; + } +} +int main(){ + char word[130]; + int w,t,tmp,pd,T; + scanf("%d",&w); + for (int i = 1;i <= w;i ++){ + scanf("%s",word); + insert(1,word); + } + scanf("%d",&T); + while (T --){ + memset(list,0,sizeof list); + cnt = 0,tmp = 0,pd = 0; + findans = 0; + memset(key,0,sizeof key); + memset(answer,0,sizeof answer); + char c; + while (c = getchar(),c < 'A' || c > 'z'); + for (;;){ + if (c >= 'A' && c <= 'Z'){ + pd = false; list[cnt][tmp ++] = c; + } + else if (c == ' '){ + pd = false; + if (tmp){ + tl[cnt] = tmp;list[cnt ++][tmp] = 0; + tmp = 0; + } + } + else if (c == '\n'){ + if (tmp){ + tl[cnt] = tmp;list[cnt ++][tmp] = 0; + tmp = 0; + } + if (pd) break; + pd = 1; + } + if (scanf("%c",&c) == EOF){ + if (tmp){ + tl[cnt] = tmp;list[cnt ++][tmp] = 0; + tmp = 0;break; + } + } + } + int tmp = search(0); + if (tmp == 0) puts("#No solution#"); + else if (tmp == 1){ + for (int i = 'A';i <= 'Z';i ++){ + if (answer[i]) printf("%c",answer[i]); + else printf("*"); + } + printf("\n"); + }else{ + puts("#More than one solution#"); + } + } + return 0; +} diff --git a/HDOJ/1366_autoAC.cpp b/HDOJ/1366_autoAC.cpp new file mode 100644 index 0000000..0cbdfbc --- /dev/null +++ b/HDOJ/1366_autoAC.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#define N 1000000 +using namespace std; +struct ty +{ + int x,y,len,bj; + int linkx[75]; + int linky[75]; +}pipe[50]; +struct ty2 +{ + int v,bj,link; +}f[120]; +int ans; +int ok() +{ + int i,j,ii,flag[50],k; + ans=0; + memset(flag,0,sizeof(flag)); + flag[1]=1; + for(i=0;i<=110;i++)f[i].link=-1; + for(i=0;i<=110;i++) + { + if((pipe[1].y<=i)&&(i=0;i--) + { + if(f[i].v>=10000000)return f[i+2].bj; + if(f[i+1].bj==1)return 1; + ans+=f[i].v; + f[i].v=0; + if((f[i].link>=0)&&(flag[f[i].link]==0)) + { + k=f[i].link; + f[i].link=-1; + flag[k]=1; + for(j=0;j<=110;j++) + { + if((pipe[k].y<=j)&&(jpipe[x].y+pipe[x].len){printf("No Solution\n");continue;} + if(ok())printf("%d\n",ans); + else printf("No Solution\n"); + } + return 0; +} diff --git a/HDOJ/1369_autoAC.cpp b/HDOJ/1369_autoAC.cpp new file mode 100644 index 0000000..89f65f7 --- /dev/null +++ b/HDOJ/1369_autoAC.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include +#include +using namespace std; +struct Editor{ + int ID; + int Num; +}; +vectordata[10000]; +map name; +map::iterator pos; +int author[10000]; +string Erdos = "Erdos,P."; +void bfs() +{ + queueQ; + Editor tmp,now; + int i,id,nNum; + memset(author,-1,sizeof(author)); + tmp.ID = name[Erdos]; + tmp.Num = 0; + Q.push(tmp); + while(!Q.empty()) + { + now = Q.front(); Q.pop(); + id = now.ID; + nNum = data[id].size(); + for(i=0;i +int main() +{ int p,e,i,d,n,T; + int j,k; + scanf("%d",&T); + while(T--) + { j=1; + getchar(); + while(scanf("%d%d%d%d",&p,&e,&i,&d)!=EOF) + { + if(p==-1&&e==-1&&i==-1&&d==-1) + break; + else + { n=( 5544*p+14421*e+1288*i-d+21252)%21252; + if(n==0) + n=21252; + printf("Case %d: the next triple peak occurs in %d days.\n",j++,n); + } + } + if(T!=0) + printf("\n"); + } + return 0; +} diff --git a/HDOJ/1371_autoAC.cpp b/HDOJ/1371_autoAC.cpp new file mode 100644 index 0000000..ba91146 --- /dev/null +++ b/HDOJ/1371_autoAC.cpp @@ -0,0 +1,61 @@ +#include +#include +using namespace std; +namespace +{ + vector, pair > > V; + void init() + { + V.push_back(make_pair(make_pair(1, 5), make_pair(1, 6))); + V.push_back(make_pair(make_pair(2, 10), make_pair(2, 11))); + V.push_back(make_pair(make_pair(3, 16), make_pair(3, 17))); + V.push_back(make_pair(make_pair(4, 21), make_pair(4, 22))); + V.push_back(make_pair(make_pair(5, 27), make_pair(5, 28))); + V.push_back(make_pair(make_pair(6, 32), make_pair(6, 33))); + V.push_back(make_pair(make_pair(7, 38), make_pair(7, 39))); + V.push_back(make_pair(make_pair(8, 43), make_pair(8, 44))); + V.push_back(make_pair(make_pair(9, 48), make_pair(9, 49))); + V.push_back(make_pair(make_pair(10, 54), make_pair(10, 55))); + } + bool before(int h1, int m1, int h2, int m2) + { + if (h1 != h2) + return h1 < h2; + else + return m1 <= m2; + } + int pass(int bh, int bm, int eh, int em) + { + int total = 0; + for (size_ i = 0; i < V.size(); i++) + { + pair &begin = V[i].first; + pair &end = V[i].second; + if (before(bh, bm, begin.first, begin.second) + && before(end.first, end.second, eh, em)) + total++; + } + return total; + } +} +int main() +{ + init(); + int bh, bm, eh, em; + puts("Program 3 by team X"); + puts("Initial time Final time Passes"); + while (scanf("%d%d%d%d", &bh, &bm, &eh, &em) != EOF) + { + bh %= 12; + eh %= 12; + int res; + if (bh > eh || (bh == eh && bm > em)) + res = pass(bh, bm, 12, 0) + pass(0, 0, eh, em) + 1; + else + res = pass(bh, bm, eh, em); + printf(" %02d:%02d %02d:%02d%8d\n", bh ? bh : 12, bm, + eh ? eh : 12, em, res); + } + puts("End of program 3 by team X"); + return 0; +} diff --git a/HDOJ/1372_autoAC.cpp b/HDOJ/1372_autoAC.cpp new file mode 100644 index 0000000..eeea6ab --- /dev/null +++ b/HDOJ/1372_autoAC.cpp @@ -0,0 +1,25 @@ +#include +#include +int knight[8][8]; +int x[]={1,1,2,2,-1,-1,-2,-2}; +int y[]={2,-2,1,-1,2,-2,1,-1}; +void dfs(int si,int sj,int moves) +{ + if(si < 0 || sj < 0 || si >= 8 || sj >= 8 || moves >= knight[si][sj]) + return; + knight[si][sj] = moves; + int i; + for(i = 0; i < 8; i++) + dfs(si + x[i],sj + y[i],moves + 1); +} +int main() +{ + char a[10],b[10]; + while(scanf("%s%s",a,b) != EOF) + { + memset(knight,10,sizeof(knight)); + dfs(a[0] - 'a',a[1] - '1',0); + printf("To get from %s to %s takes %d knight moves.\n",a,b,knight[b[0] - 'a'][b[1] - '1']); + } + return 0; +} diff --git a/HDOJ/1373_autoAC.cpp b/HDOJ/1373_autoAC.cpp new file mode 100644 index 0000000..39b66e2 --- /dev/null +++ b/HDOJ/1373_autoAC.cpp @@ -0,0 +1,123 @@ +#include +#include +#include +#include +#include +#include +#define debug 0 +#define sca scanf +#define pri printf +#define LL long long +#define fou(i,a,b) for(i = a; i < b; i ++) +#define fod(i,a,b) for(i = a; i >= b; i --) +#define clean(a) memset(a,0,sizeof(a)) +using namespace std; +int Compare(int a,int b,bool flag) +{if(flag)return a>b?a:b; else return a(b)?(a-b):(b-a);} +int Map[30][30]; +int channel[30]; +int mark[30][30]; +int n,ans,key,res; +void dfs(int x) +{ + if(debug)pri("%d\n",x); + int i,j,u,v; + if(key) + { + return ; + } + for(i=1;i<=n;i++) + { + for(j=1;j<=n;j++) + { + if(Map[x][j]&&mark[j][i]) + { + break; + } + } + if(j==n+1) + { + mark[x][i]=1; + channel[i]=1; + if(debug) + { + pri("X:%d I:%d J:%d\n",x,i,j); + pri("mark-----------\n"); + fou(i,1,n + 1) + { + pri("%d ",mark[x][i]); + } + pri("\nchannel:\n"); + fou(i,1,n + 1) + { + pri("%d ",channel[i]); + } + pri("\n"); + } + if(x == n) + { + for(u=1;u<=n;u++) + { + if(channel[u]) + { + res++; + } + } + key=1; + return ; + }else + { + dfs(x+1); + } + mark[x][i]=0; + channel[i]=0; + } + } +} +int main() +{ + int i,j,k,len; + char tmp[100]; + while(~sca("%d",&n) && n) + { + clean(mark); + clean(channel); + clean(Map); + fou(i,1,n + 1) + { + sca("%s",tmp); + len = strlen(tmp); + fou(j,2,len) + { + Map[i][tmp[j] - 'A' + 1] = 1; + Map[tmp[j] - 'A' + 1][i] = 1; + } + } + res = 0; key = 0; + dfs(1); + if(res ==1 ) + pri("%d channel needed.\n",res); + else + pri("%d channels needed.\n",res); + if(debug) + { + fou(i,1,n + 1) + pri("%d ",channel[i]); + pri("\n"); + fou(i,1,n + 1) + pri("%d ",mark[i]); + pri("\n"); + fou(i,1,n + 1) + { + fou(j,1,n + 1) + { + pri("%d ",Map[i][j]); + } + pri("\n"); + } + } + } + return 0; +} diff --git a/HDOJ/1374_autoAC.cpp b/HDOJ/1374_autoAC.cpp new file mode 100644 index 0000000..2f4673b --- /dev/null +++ b/HDOJ/1374_autoAC.cpp @@ -0,0 +1,21 @@ +#include +#include +#define PI 3.141592653589793 +double square(double x) +{ + return x * x; +} +int main(void) +{ + double x1,y1,x2,y2,x3,y3; + double a2,b2,c2; + double r; + while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3) != EOF) + { + a2 = square(x1 - x2) + square(y1 - y2); + b2 = square(x1 - x3) + square(y1 - y3); + c2 = square(x3 - x2) + square(y3 - y2); + r = sqrt(c2/(1 - square(a2 + b2 - c2)/a2/b2/4))/2; + printf("%.2f\n",2 * PI * r); + } +} diff --git a/HDOJ/1375_autoAC.cpp b/HDOJ/1375_autoAC.cpp new file mode 100644 index 0000000..2f87385 --- /dev/null +++ b/HDOJ/1375_autoAC.cpp @@ -0,0 +1,139 @@ +#include +#include +#include +#include +using namespace std; +struct P +{ + char s[5]; + int n; +}node[11000], get[11000]; +int cmp(const void *a , const void *b) +{ + return strcmp( (*(P *)a).s, (*(P *)b).s ); +} +char str[11000], str1[11000]; +int n, num; +void element(char *str, int s, int t, int k, P *p); +void insert(char *s, int k, P *p) +{ + int i; + for ( i = 0 ; i < num ; i++ ) + { + if ( !strcmp(s, p[i].s) ) + break; + } + if ( i < num ) + p[i].n+=k; + else p[num].n+=k, strcpy(p[num++].s, s); +} +void sequence(char *str, int s, int t, int k, P *p) +{ + int i = s; + while ( i < t ) + { + if ( '(' ==str[i] ) + { + int ti, tk; + for ( ti = i+1, tk= 1 ; tk ; ti++ ) + { + if ( '(' == str[ti] ) + tk++; + else if ( ')' == str[ti] ) + tk--; + } + if ( '0' <= str[ti] && str[ti] <= '9' ) + { + int ttk, te= ti; + for ( ttk = 0; '0' <= str[ti] && str[ti] <= '9' ; ti++ ) + ttk= ttk*10+str[ti]-'0'; + element(str, i, te, k*ttk, p); + } + else element(str, i, ti, k, p); + i= ti; + } + else if ( 'A' <= str[i] && str[i] <= 'Z' ) + { + int tk= i; + i++; + if ( 'a' <= str[i] && str[i] <= 'z' ) + i++; + if ( '0' <= str[i] && str[i] <= '9' ) + { + int ttk; + for ( ttk = 0; '0' <= str[i] && str[i] <= '9' ; i++ ) + ttk= ttk*10+str[i]-'0'; + element(str, tk, i, k*ttk, p); + } + else element(str, tk, i, k, p); + } + } +} +void element(char *str, int s, int t, int k, P *p) +{ + if ( '(' == str[s] && ')' == str[t-1] ) + sequence(str, s+1, t-1, k, p); + else + { + char tmp[5]; + tmp[0] = str[s]; + if ( 'a' <= str[s+1] && str[s+1] <= 'z' ) + tmp[1]= str[s+1], tmp[2]= 0; + else tmp[1]= 0; + insert(tmp, k, p); + } +} +void slove(char *str, P *p) +{ + int len = strlen(str), i= 0, j, k; + num= 0; + while ( i < len ) + { + char ch; + ch= str[i]; + if ( '0' <= ch && ch <= '9' ) + { + for ( k = 0; '0' <= str[i] && str[i] <= '9' ; i++ ) + k= k*10+str[i]-'0'; + for ( j = i ; str[j] && '+' != str[j] ; j++ ); + sequence(str, i, j, k, p); + i= j+1; + } + else + { + for ( j = i+1 ; str[j] && '+' != str[j] ; j++ ); + sequence(str, i, j, 1, p); + i= j+1; + } + } +} +int main() +{ + while ( EOF!= scanf("%s", str) ) + { + memset(node, 0, sizeof(node)); + slove(str, node); + int m= num; + qsort(node, m, sizeof(P), cmp); + scanf("%d", &n); + while ( n-- ) + { + scanf("%s", str1); + memset(get, 0, sizeof(get)); + slove(str1, get); + if ( m == num ) + { + qsort(get, m, sizeof(P), cmp); + int i; + for ( i = 0 ; i <= num && node[i].n == get[i].n && !strcmp(node[i].s, get[i].s) ; i++ ); + if ( i > num ) + { + printf("%s==%s\n", str, str1); + continue; + } + } + printf("%s!=%s\n", str, str1); + } + } + return 0; +} diff --git a/HDOJ/1376_autoAC.cpp b/HDOJ/1376_autoAC.cpp new file mode 100644 index 0000000..cc5945c --- /dev/null +++ b/HDOJ/1376_autoAC.cpp @@ -0,0 +1,29 @@ +#include +#include +const int MAXN = 100; +int main(void) +{ + char str[MAXN]; + int i,j; + while(scanf("%s",str) != EOF) + { + char str1[MAXN]; + memset(str1,0x30,sizeof(str1)); + int index = 0; + for(i = strlen(str) - 1; i > 1; i--) + { + int num = str[i] - '0'; + int temp; + for(j = 0; j < index || num; j++) + { + temp = num * 10 + (j < index ? str1[j] - '0': 0); + str1[j] = temp/8 + '0'; + num = temp%8; + } + index = j; + } + str1[j] = '\0'; + printf("%s [8] = 0.%s [10]\n",str,str1); + } + return 0; +} diff --git a/HDOJ/1377_autoAC.cpp b/HDOJ/1377_autoAC.cpp new file mode 100644 index 0000000..1c56479 --- /dev/null +++ b/HDOJ/1377_autoAC.cpp @@ -0,0 +1,145 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define ERROR non=true;return +set used; +stack s; +bool non, root; +bool gettag(char* &ch, string &tag, bool &end, bool &empty) +{ + int p1, p2, p3, p4; + string attribute; + end=false, empty=false; + tag=attribute=""; + ch++; + if (*ch=='/'){end=true;ch++;} + while (isalnum(*ch) || *ch=='-') + { + tag+=*ch; + ch++; + } + while (isspace(*ch)) ch++; + if (*ch=='>') + return 1; + if (*ch=='/') + { + int cal=0; + ch++; + while (*ch!='>'){cal++;ch++;} + if (cal>0) return -2; + if (end) return -1; + else empty=true; + } + while (isalnum(*ch) || *ch=='-' || *ch=='.' || *ch=='\"' || *ch=='=') + { + attribute+=*ch; + ch++; + } + if (attribute.length()>0) + { + p1=attribute.find("=", 0); if (p1==-1) return -3; + p2=attribute.find("\"", 0); if (p2') return 1; + if (*ch=='/') + { + int cal=0; + ch++; + while (*ch!='>'){cal++;ch++;} + if (cal>0) return -10; + if (end) return -9; + else empty=true; + } + while (*ch!='>'){ + ch++; + if (!isspace(*ch) && *ch!='>') return -11; + } + return 1; +} +void solve(char *ch) +{ + bool end, empty; + string tag; + int tmp; + while (!non && *ch!='\0') + { + if (*ch=='<') + { + tmp=gettag(ch, tag, end, empty); + if (tmp==1) + { + if (end && empty){ + ERROR; + } + if (empty && used.count(tag)>0){ + ERROR; + } + else if (!empty && !end) + { + if (used.count(tag)>0){ + ERROR; + } + if (s.empty()) + { + if (root){ERROR;} + else root=true; + } + used.insert(tag); + s.push(tag); + } + else if (!empty && end) + { + if (s.empty() || s.top()!=tag){ + ERROR; + } + used.erase(tag); + s.pop(); + } + } + else{ERROR;} + } + else ch++; + } +} +int main() +{ + string tag, attribute; + bool firstdata=true; + bool end, empty; + char buf[65536]; + do{ + while (gets(buf)!=NULL && strcmp(buf, ")!=0 + && strcmp(buf, ")!=0) + { + solve(buf); + } + if (strcmp(buf, ")==0) + { + if (!firstdata) + { + if (non || !s.empty()) printf("non well-formed\n"); + else printf("well-formed\n"); + } + else firstdata=false; + non=false; + root=false; + used.clear(); + while (!s.empty()) s.pop(); + } + }while (strcmp(buf, ")!=0); + if (non || !s.empty()) printf("non well-formed\n"); + else printf("well-formed\n"); + return 0; +} diff --git a/HDOJ/1378_autoAC.cpp b/HDOJ/1378_autoAC.cpp new file mode 100644 index 0000000..f259c31 --- /dev/null +++ b/HDOJ/1378_autoAC.cpp @@ -0,0 +1,130 @@ +#include +#include +#include +using namespace std; +const int MAXL = 80 + 10; +const int MAXN = 10000 + 10; +char szLine[MAXN]; +char szWord[MAXN][MAXL]; +int n; +int nWordCnt; +int dp[MAXN]; +int nLastTo[MAXN]; +int nSum[MAXN]; +void Read() +{ + getchar(); + nWordCnt = 0; + while (gets(szLine)) + { + if (szLine[0] == '\0') break; + sscanf(szLine, "%s", szWord[++nWordCnt]); + for (int i = 0; szLine[i] != '\0'; ++i) + { + if (szLine[i] == ' ') + { + while (szLine[i] == ' ') + { + i++; + } + sscanf(szLine + i, "%s", szWord[++nWordCnt]); + } + } + } +} +void Init() +{ + nSum[0] = 0; + for (int i = 1; i <= nWordCnt; ++i) + { + nSum[i] = nSum[i - 1] + strlen(szWord[i]); + } +} +int Sum(int i, int j) +{ + return nSum[j] - nSum[i - 1]; +} +int LeastLen(int i, int j) +{ + return Sum(i, j) + j - i; +} +int Badness(int i, int j) +{ + if (i == j) + { + return 500; + } + int nBlankCnt = n - Sum(i, j); + int nGapCnt = j - i; + int nGapLen = nBlankCnt / nGapCnt; + int nRemain = nBlankCnt % nGapCnt; + return (nGapLen - 1) * (nGapLen - 1) * (nGapCnt - nRemain) + nGapLen * nGapLen * nRemain; +} +void Dp() +{ + memset(dp, 0x3f, sizeof(dp)); + dp[nWordCnt + 1] = 0; + for (int i = nWordCnt; i >= 1; --i) + { + for (int j = i; j <= nWordCnt && LeastLen(i, j) <= n; ++j) + { + if (dp[j + 1] + Badness(i, j) <= dp[i]) + { + dp[i] = dp[j + 1] + Badness(i, j); + nLastTo[i] = j; + } + } + } +} +void PrintBlank(int nNum) +{ + for (int i = 0; i < nNum; ++i) + { + putchar(' '); + } +} +void Output() +{ + int nL = 1; + while (true) + { + int nR = nLastTo[nL]; + if (nL == nR) + { + puts(szWord[nL]); + } + else + { + int nBlankCnt = n - Sum(nL, nR); + int nGapCnt = nR - nL; + int nGapLen = nBlankCnt / nGapCnt; + int nRemain = nBlankCnt % nGapCnt; + printf("%s", szWord[nL]); + for (int i = 0; i < nGapCnt - nRemain; ++i) + { + PrintBlank(nGapLen); + printf("%s", szWord[nL + 1 + i]); + } + for (int i = 0; i < nRemain; ++i) + { + PrintBlank(nGapLen + 1); + printf("%s", szWord[nR - nRemain + 1 + i]); + } + puts(""); + } + if (nR == nWordCnt) break; + nL = nR + 1; + } + puts(""); +} +int main() +{ + while (scanf("%d", &n) == 1 && n) + { + Read(); + Init(); + Dp(); + Output(); + } + return 0; +} diff --git a/HDOJ/1379_autoAC.cpp b/HDOJ/1379_autoAC.cpp new file mode 100644 index 0000000..6835ac4 --- /dev/null +++ b/HDOJ/1379_autoAC.cpp @@ -0,0 +1,46 @@ +# include +# include +# include +# include +using namespace std; +bool cmp(string a,string b) +{ + int x=0,y=0,i,j; + for(i=0;ia[j]) + x++; + } + } + for(i=0;ib[j]) + y++; + } + } + return x!=y?xw; + for(i=0;i>s; + w.push_back(s); + } + sort(w.begin(),w.end(),cmp); + for(i=0;i +#include +#include +using namespace std; +const int N = 10; +struct state { + double dis; + int r, y, g; +}d[N]; +struct can { + int l, r; + void put() { + if (l == r) + printf("%d", l); + else + printf("%d-%d", l, r); + } +}s[6*N]; +int n, m; +bool judge (double v) { + v /= 3600; + for (int i = 0; i < n; i++) { + int sum = d[i].r + d[i].y + d[i].g; + double t = d[i].dis / v; + int ti = (int)t; + int k = ti / sum; + t = t - k * sum; + if (t > d[i].g + d[i].y) + return false; + } + return true; +} +int main () { + int cas = 1; + while (scanf("%d", &n) == 1 && n != -1) { + for (int i = 0; i < n; i++) + scanf("%lf%d%d%d", &d[i].dis, &d[i].g, &d[i].y, &d[i].r); + m = 0; + for (int i = 30; i <= 60; i++) { + if (judge(i)) { + if (m == 0 || s[m-1].r + 1 < i) { + s[m].l = s[m].r = i; + m++; + } else { + s[m-1].r++; + } + } + } + printf("Case %d: ", cas++); + if (m) { + for (int i = 0; i < m - 1; i++) { + s[i].put(); + printf(", "); + } + s[m-1].put(); + printf("\n"); + } else + printf("No acceptable speeds.\n"); + } + return 0; +} diff --git a/HDOJ/1381_autoAC.cpp b/HDOJ/1381_autoAC.cpp new file mode 100644 index 0000000..a1a877f --- /dev/null +++ b/HDOJ/1381_autoAC.cpp @@ -0,0 +1,20 @@ +#include +#include +#include +using namespace std; +int main(){ + set Set; + int t,n,nc; + string str; + cin>>t; + while(t--){ + cin>>n>>nc>>str; + int size=str.size(); + for(int i=0;i +#include +#include +#include +using namespace std; +#define maxn 35 +int n, m; +int d[maxn]; +int dir[2] = {-1, 1}; +bool vis[maxn]; +void input() +{ + char st[5]; + scanf("%d", &m); + m--; + for (int i = 0; i < n; i++) + { + scanf("%s", st); + if (st[0] == 'R') + d[i] = 1; + else + d[i] = 0; + } +} +int unify(int a) +{ + return (a + n) % n; +} +void work() +{ + int s = m; + int t = unify(0 + dir[d[m]]); + if (t == m) + t = unify(t + dir[d[m]]); + int cnt = 1; + int ret = 1; + vis[m] = true; + memset(vis, 0, sizeof(vis)); + while (cnt < n) + { + vis[s] = true; + d[s] = 1 - d[s]; + ret++; + if (!vis[t]) + cnt++; + int temp = unify(s + dir[d[t]]); + if (temp == t) + temp = unify(temp + dir[d[t]]); + s = t; + t = temp; + } + printf("Classmate %d got the ball last after %d tosses.\n", s + 1, ret); +} +int main() +{ + while (scanf("%d", &n), n) + { + input(); + work(); + } + return 0; +} diff --git a/HDOJ/1384_autoAC.cpp b/HDOJ/1384_autoAC.cpp new file mode 100644 index 0000000..e93f5c0 --- /dev/null +++ b/HDOJ/1384_autoAC.cpp @@ -0,0 +1,62 @@ +#include"iostream" +#include "queue" +#define inf 0x7FFFFFFF +#define M 500010 +using namespace std; +int head[M],minm,maxm,dis[M],edge_sum; +bool inq[M]; +struct a{ + int end,jie,next; +}edge[M]; +void Init(){ + edge_sum=0; + memset(head,-1,sizeof(head)); + minm=inf; + maxm=-inf; + memset(inq,0,sizeof(inq)); + memset(dis,-inf,sizeof(dis)); +} +void add_edge(int u,int v, int jie){ + edge[edge_sum].end=v; + edge[edge_sum].jie=jie; + edge[edge_sum].next=head[u]; + head[u]=edge_sum++; +} +int max(int a,int b){ if(a>b)return a;return b;} +int min(int a,int b){ if(a q; + while(!q.empty())q.pop(); + q.push(minm), inq[minm]=1, dis[minm]=0; + while( !q.empty()){ + int u=q.front(); q.pop(), inq[u]=0; + for(int i=head[u] ; i!=-1; i=edge[i].next ) + { + int v=edge[i].end, jie=edge[i].jie; + if(dis[v] +#include +#include +using namespace std; +#define maxn 50 +#define INF 0xffffff +#define Min(a, b) (a > b ? b : a) +int map[maxn][maxn], n; +int patl[maxn][maxn]; +int f[maxn]; +void floyd(); +int main() +{ + while(cin >> n, n) + { + int i, j, a, b, next; + for(i=1; i<=n; i++) + for(j=1; j<=n; j++) + { + cin >> map[i][j]; + if(map[i][j] == -1) + map[i][j] = INF; + } + for(i=1; i<=n; i++) + cin >> f[i]; + floyd(); + while(cin >> a >> b, a != -1) + { + next = a; + printf("From %d to %d :\nPath: ", a, b); + while(next != b) + { + printf("%d-->", next); + next = patl[next][b]; + } + printf("%d\n", next); + printf("Total cost : %d\n\n", map[a][b]); + } + } + return 0; +} +void floyd() +{ + int k, i, j; + for(i=1; i<=n; i++) + for(j=1; j<=n; j++) + patl[i][j] = j; + for(k=1; k<=n; k++) + for(i=1; i<=n; i++) + for(j=1; j<=n; j++) + { + int new_patl = map[i][k] + map[k][j] + f[k]; + if(map[i][j] > new_patl) + { + map[i][j] = new_patl; + patl[i][j] = patl[i][k]; + } + else if(map[i][j] == new_patl) + patl[i][j] = Min(patl[i][j], patl[i][k]); + } +} diff --git a/HDOJ/1387_autoAC.cpp b/HDOJ/1387_autoAC.cpp new file mode 100644 index 0000000..fbe3c89 --- /dev/null +++ b/HDOJ/1387_autoAC.cpp @@ -0,0 +1,80 @@ +#include +#include +using namespace std; +int belong[1000000]; +int pos[1005]; +struct node +{ + int x; + int next; +}r[200010]; +int main() +{ + int x,t,i,j,n,No=0; + int front,back,used; + string com; + while(cin>>t&&t) + { + front=-1; + back=-1; + used=-1; + for(i=0;i>n; + for(j=0;j>x; + belong[x]=i; + } + pos[i]=-1; + } + cout<<"Scenario #"<<++No<>com&&com!="STOP") + { + if(com=="ENQUEUE") + { + used++; + cin>>x; + if(pos[belong[x]]==-1) + { + if(front==-1&&back==-1) + { + front=used; + back=used; + r[used].x=x; + r[used].next=-1; + pos[belong[x]]=used; + } + else + { + r[used].x=x; + r[used].next=-1; + r[back].next=used; + back=used; + pos[belong[x]]=used; + } + } + else + { + if(pos[belong[x]]==back) + back=used; + r[used].x=x; + r[used].next=r[pos[belong[x]]].next; + r[pos[belong[x]]].next=used; + pos[belong[x]]=used; + } + } + else if(com=="DEQUEUE") + { + cout< +#include +#include +using namespace std; +struct Tile +{ +int x1,y1; +int x2,y2; +int s; +}p[101]; +int main() +{ +int n,i,j,k; +int t1,t2,t3; +int a,b,sum,m,c1,c2,t; +while(scanf("%d",&n)!=EOF) +{ + while(n--) + { +t1=t2=t3=0; +sum=0; +scanf("%d%d",&a,&b); +scanf("%d",&m); + t=(a>b? a:b); + for(i=0;it||p[i].x2>t||p[i].y1>t||p[i].y2>t) + t2=1; + } + if(sum=p[i].x2)||(p[j].x2<=p[i].x1)||(p[j].y1>=p[i].y2)||(p[j].y2<=p[i].y1)) + continue; + else + {t1=1; + break; + } + } + } +if(t1) + printf("NONDISJOINT\n"); +else if(t2) + printf("NONCONTAINED\n"); +else if(t3) + printf("NONCOVERING\n"); +else +printf("OK\n"); + } +} +return 0; +} diff --git a/HDOJ/1390_autoAC.cpp b/HDOJ/1390_autoAC.cpp new file mode 100644 index 0000000..e7329f2 --- /dev/null +++ b/HDOJ/1390_autoAC.cpp @@ -0,0 +1,26 @@ +#include +int main() +{ + int N,n,i,flag1; + __int64 flag; + scanf("%d",&N); + while(N--) + { + scanf("%d",&n); + for(i=0,flag=0,flag1=0;flag +using namespace std; +int main() +{ + int n; + cin>>n; + while(n--) + { + int x,y; + cin>>x>>y; + if(x==0&&y==0) + cout<<"0\n"; + else if(x==y) + { + if(x%2==1) + cout<<(2*x-1)< +#include +#include +using namespace std; +struct node +{ + int x,y; +}a[110],stack1[110]; +double distan(node a,node b) +{ + return (double)sqrt((a.x-b.x)*(a.x-b.x)*1.0+(a.y-b.y)*(a.y-b.y)*1.0); +} +double across(node a,node n1,node n2) +{ + return (n1.x-a.x)*(n2.y-a.y) - (n1.y-a.y)*(n2.x-a.x); +} +bool cmp(node a1,node b1) +{ + double k=across(a[0],a1,b1); + if(k>0) return true; + else if (k==0&&distan(a[0],a1)=2 && (across(stack1[head-1],stack1[head],a[i])<=0)) head--; + stack1[++head]=a[i]; + } + for(i=0;i +int main() +{ + int n,m,i,j; + while(scanf("%d%d",&n,&m)) + { + if(n==0&&m==0) + break; + for(j=1;;j++) + { + if((n+m*n)%60==0) + { + printf("%d\n",j); + break; + } + n=(n+m*n)%60; + if(j>=1000) + { + printf("Impossible\n"); + break; + } + } + } + return 0; +} diff --git a/HDOJ/1394_autoAC.cpp b/HDOJ/1394_autoAC.cpp new file mode 100644 index 0000000..16ffb1b --- /dev/null +++ b/HDOJ/1394_autoAC.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +using namespace std; +#define N 5005 +#define inf 999999999 +int c[N]; +int a[N]; +int lowbit(int x){ + return x&(-x); +} +void update(int x){ + while(x0){ + ans+=c[x]; + x-=lowbit(x); + } + return ans; +} +main() +{ + int n, i, j, k; + while(scanf("%d",&n)==1){ + memset(c,0,sizeof(c)); + int num=0; + for(i=1;i<=n;i++){ + scanf("%d",&a[i]); + a[i]++; + num+=get_sum(N-1)-get_sum(a[i]); + update(a[i]); + } + int minh=inf; + for(i=1;i<=n;i++) + { + num=num-(a[i]-1)+(n-a[i]); + minh=min(minh,num); + } + printf("%d\n",minh); + } +} diff --git a/HDOJ/1395_autoAC.cpp b/HDOJ/1395_autoAC.cpp new file mode 100644 index 0000000..84904dd --- /dev/null +++ b/HDOJ/1395_autoAC.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; +int main() +{ + int k,m,x,n; + while(cin>>n) + { + k=1; + x=2; + if(n%2==0||n==1) + cout<<"2^? mod "< +#include +int a[505]; +int main() +{ + int n,sum,i; + while(scanf("%d",&n)!=EOF) + { + for(i=n,sum=0;i>=1;i--) + { + sum=sum+(1+i)*i/2; + } + for(i=n-1;i>=0;i=i-2) + { + sum=sum+(1+i)*i/2; + } + printf("%d\n",sum); + } + return 0; +} diff --git a/HDOJ/1397_autoAC.cpp b/HDOJ/1397_autoAC.cpp new file mode 100644 index 0000000..c346df6 --- /dev/null +++ b/HDOJ/1397_autoAC.cpp @@ -0,0 +1,42 @@ +#include +#define N 4000 +#define MAX 32770 +using namespace std; +int su[N],tot; +void prime() +{ + tot=1; + su[0]=2; + for(int i=3;ii) break; + if(i%su[j]==0) {ok=0;break;} + } + if(ok) su[tot++]=i; + } +} +int main() +{ + int n; + prime(); + while(cin>>n&&n) + { + int num=0; + for(int i=0;2*su[i]<=n;i++) + { + int a=0,b=tot; + while(an) b=mid; + } + } + cout< +using namespace std; +int main() +{ + int a[350],b[350],i,j,k,n; + while(cin>>n&&n) + { + for(i=0;i<=n;i++) + { + a[i]=1; + b[i]=0; + } + for(i=2;i<=17;i++) + { + for(j=0;j<=n;j++) + for(k=0;k+j<=n;k+=i*i) + b[k+j]+=a[j]; + for(j=0;j<=n;j++) + { + a[j]=b[j]; + b[j]=0; + } + } + cout< +int cubic[54]; +void init() +{ + int i,j; + for(i=0,j=0;i<54;++i) + cubic[j++]=i*i*i; +} +int main() +{ + int i,j,ans,sum; + init(); + while(scanf("%d",&sum),sum) + { + ans=0; + for(i=0;i*(i+1)*(i+2)/6<=sum;++i) + { + for(j=53;j>=0;--j) + { + if(cubic[j]<=sum-i*(i+1)*(i+2)/6) + break; + } + if(ans