题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5301
解题思路:http://blog.csdn.net/piaocoder/article/details/47657487
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main(){ int n,m,x,y; while(scanf("%d%d%d%d",&n,&m,&x,&y) != EOF){ if(n > m){ swap(n,m); swap(x,y); } //n<=m int ans = (n + 1) / 2,answer; int left = y,right = m - y+1; int up = x-1,down = n-x; if(n % 2 && n == m && x == y && x == (n+1)/2) answer = n / 2; else if(x == ans || x == ans + 1 || y == 1 || y == m) answer = ans; else if(min(left, right) > ans) answer= min(max(up,down),min(left,right)); else answer = ans; printf("%d\n",answer); } return 0; }
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305
解题思路:http://blog.csdn.net/piaocoder/article/details/47657163
#include <iostream> #include <cstdio> #include <cstring> using namespace std; int n,m; int a[30],b[30],cnt; int sum[10],on[10],off[10];//sum记录每个点的度数,on记录每个点的online,off记录每个点的offline bool judge(){ for(int i = 1; i <= n; i++){ if(on[i] != off[i]) return false; } return true; } void dfs(int cur){ if(cur == m+1){ if(judge()){ cnt++; return; } } int x = a[cur], y = b[cur]; if(on[x] < sum[x]/2 && on[y] < sum[y]/2){ on[x]++; on[y]++; dfs(cur+1); on[x]--; on[y]--; } if(off[x] < sum[x]/2 && off[y] < sum[y]/2){ off[x]++; off[y]++; dfs(cur+1); off[x]--; off[y]--; } } int main(){ int T; scanf("%d",&T); while(T--){ memset(on,0,sizeof(on)); memset(off,0,sizeof(off)); memset(sum,0,sizeof(sum)); int flag = 1; cnt = 0; scanf("%d%d",&n,&m); for(int i = 1; i <= m; i++){ scanf("%d%d",&a[i],&b[i]); sum[a[i]]++; sum[b[i]]++; } for(int i = 1; i <= n; i++){ if(sum[i] % 2){ flag = 0; break; } } if(flag){ dfs(1); printf("%d\n",cnt); } else printf("0\n"); } return 0; }
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5308
解题思路:http://blog.csdn.net/piaocoder/article/details/47658883
#include <iostream> #include <cstdio> using namespace std; int main(){ int i,n; while(~scanf("%d",&n)){ if(n <= 3) printf("-1\n"); else if(n == 4){ printf("1 * 2\n");// 5 n*n printf("5 + 3\n");// 6 5*n printf("6 + 4\n");// 7 6*n } else if(n == 5){ printf("1 / 2\n");// 6 1 printf("6 / 3\n");// 7 1/5 printf("4 - 7\n");// 8 24/5 printf("5 * 8\n");// 9 24 } else if(n == 6){ printf("1 + 2\n"); printf("7 + 3\n"); printf("8 + 4\n"); printf("9 + 5\n"); printf("10 - 6\n"); } else if(n == 7){ printf("1 / 2\n");// 8 1 printf("3 * 4\n");// 9 n*n printf("9 - 8\n");// 10 48 printf("5 + 6\n");// 11 2*n printf("10 / 11\n");// 12 48/14 printf("12 * 7\n");// 13 24 } else if(n == 8){ printf("1 - 2\n");// 9 0 printf("9 * 3\n");// 10 0 printf("10 * 4\n");// 11 0 printf("11 * 5\n");// 12 0 printf("12 + 6\n");// 13 n printf("13 + 7\n");// 14 2*n printf("14 + 8\n");// 15 3*n } else if(n == 9){ printf("1 / 2\n");// 10 1 printf("3 / 4\n");// 11 1 printf("5 / 6\n");// 12 1 printf("7 + 8\n");// 13 2*n printf("13 + 9\n");// 14 3*n printf("14 - 10\n");// 15 26 printf("15 - 11\n");// 16 25 printf("16 - 12\n");// 17 24 } else if(n == 10){ printf("1 / 2\n");// 11 1 printf("3 / 4\n");// 12 1 printf("5 / 6\n");// 13 1 printf("7 / 8\n");// 14 1 printf("9 + 10\n");// 15 2*n printf("11 + 12\n");// 16 2 printf("16 + 13\n");// 17 3 printf("17 + 14\n");// 18 4 printf("18 + 15\n");// 19 24 } else if(n == 11){ printf("1 + 2\n");// 12 2*n printf("3 / 4\n");// 13 1 printf("5 / 6\n");// 14 1 printf("12 + 13\n");// 15 23 printf("15 + 14\n");// 16 24 printf("7 - 8\n");// 17 0 for(int i = 9; i < 12; i++) printf("%d * %d\n",i,i+8); printf("16 + 20\n"); } else if(n == 12){ printf("1 + 2\n");// 13 24 printf("3 - 4\n");// 14 0 for(i = 5; i < 13; i++) printf("%d * %d\n",i,i+9); printf("13 + 22\n"); } else if(n == 13){ printf("1 + 2\n");// 14 26 printf("14 / 3\n");// 15 2 printf("4 / 5\n");// 16 1 printf("6 - 16\n");// 17 12 printf("15 * 17\n");// 18 24 printf("7 - 8\n");// 19 0 for(i = 9; i < 14; i++) printf("%d * %d\n",i,i+10); printf("18 + 24\n"); } else if(n == 14){ printf("1 / 2\n");// 15 1 printf("3 / 4\n");// 16 1 printf("5 - 15\n");// 17 13 printf("17 - 16\n");// 18 12 printf("6 + 7\n");// 19 28 printf("19 / 8\n");// 20 2 printf("20 * 18\n");// 21 24 printf("9 - 10\n");// 22 0 for(i = 11; i < 15; i++) printf("%d * %d\n",i,i+11); printf("21 + 26\n"); } else{ printf("1 + 2\n");// n+1 2*n printf("3 + 4\n");// n+2 2*n printf("5 + 6\n");// n+3 2*n printf("7 + 8\n");// n+4 2*n printf("%d + 9\n",n+1);// n+5 3*n printf("%d / 10\n",n+2);// n+6 2 printf("%d / 11\n",n+3);// n+7 2 printf("%d / 12\n",n+4);// n+8 2 printf("%d / 13\n",n+5);// n+9 3 printf("%d * %d\n",n+6,n+7);// n+10 4 printf("%d * %d\n",n+8,n+9);// n+11 8 printf("%d * %d\n",n+10,n+11);// n+12 24 printf("14 - 15\n"); int now = n+13; for(i = 16; i <= n; i++,now++) printf("%d * %d\n",i,now); printf("%d + %d\n",n+12,now); } } return 0; }
有待更新。。。