hdu 4414 && hdu 4415
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4414
简单题目,直接枚举
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using namespace std; 2 typedef long long ll; 3 const int N = 60; 4 char map[N][N]; 5 int ans,ans1,ans2,ans3,ans4; 6 int n; 7 bool juge(int x,int y,int flag) 8 { 9 //cout<<"x = "<<x<<" "<<y<<" "<<flag<<endl; 10 if(flag) 11 { 12 if(x < n && x >= 0 && y - 1 >= 0 && y + 1 < n && map[x][y - 1] == 'o' && map[x][y + 1] == 'o' && map[x][y] == '#') 13 return true; 14 else return false; 15 } 16 if(!flag) 17 { 18 if(x + 1 < n && x - 1 >= 0 && y >= 0 && y < n && map[x - 1][y] == 'o' && map[x + 1][y] == 'o' && map[x][y] == '#') 19 return true; 20 else return false; 21 } 22 } 23 bool dfs(int x,int y) 24 { 25 int temx = x; 26 int temy = y; 27 while(juge(temx - 1,y,1)) 28 { 29 ans1 ++; 30 temx --; 31 } 32 temx = x; 33 while(juge(temx + 1,y,1)) 34 { 35 ans2 ++; 36 temx ++; 37 } 38 while(juge(x,temy - 1,0)) 39 { 40 ans3 ++; 41 temy --; 42 } 43 temy = y; 44 int tt = juge(x,temy + 1,0); 45 while(juge(x,temy + 1,0)) 46 { 47 ans4 ++; 48 temy ++; 49 } 50 //cout<<"ans1 = "<<ans1<<" "<<ans2<<" "<<ans3<<" "<<ans4<<endl; 51 if(ans1 == ans2 && ans1 == ans3 && ans1 == ans4 && ans1 != 0) 52 return true; 53 else return false; 54 } 55 int main() 56 { 57 int i,j; 58 //freopen("data.txt","r",stdin); 59 while(cin>>n) 60 { 61 if(!n) break; 62 for(i = 0; i < n; i++) 63 cin>>map[i]; 64 ans = 0; 65 for(i = 1; i < n - 1; i++) 66 { 67 for(j = 1; j < n - 1; j++) 68 { 69 if(map[i - 1][j] == '#' && map[i + 1][j] == '#' && map[i][j - 1] == '#' && map[i][j + 1] == '#' && map[i][j] == '#') 70 { 71 ans1 = ans2 = ans3 = ans4 = 0; 72 if(dfs(i,j)) ans ++; 73 } 74 } 75 } 76 printf("%d\n",ans); 77 } 78 return 0; 79 }
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4415
想的太简单了,直接贪心做的,找到ai最小的那个敌人并且他的bi不为的零的时候作为入口,然后找下去,但是没考虑如果给的敌人的bi值的和不能把那些bi是零的敌人杀完的话就要分情况考虑了。看了别人的解释还是写了好长时间 http://blog.csdn.net/acm_ted/article/details/8010170 读她的解释,读的都晕了
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 using namespace std; 2 typedef long long ll; 3 const int N = 100001; 4 int tt[N]; 5 struct node 6 { 7 int val; 8 int wei; 9 }; 10 node tworm[N]; 11 node zworm[N]; 12 bool cmp(node a,node b) 13 { 14 return a.val < b.val; 15 } 16 int main() 17 { 18 int t,n,m; 19 int i,j; 20 int tn,zn; 21 node tw; 22 int ans,tsum; 23 int cs = 0; 24 //freopen("data.txt","r",stdin); 25 scanf("%d",&t); 26 while(t--) 27 { 28 _clr(tworm,0); 29 _clr(zworm,0); 30 scanf("%d%d",&n,&m); 31 tn = zn = 0; 32 for(i = 0; i < n; i++) 33 { 34 scanf("%d%d",&tw.val,&tw.wei); 35 if(!tw.wei) zworm[zn ++] = tw; 36 else tworm[tn ++] = tw; 37 } 38 printf("Case %d: ",++cs); 39 sort(zworm,zworm + zn,cmp); 40 sort(tworm,tworm + tn,cmp); 41 int tzn = zn - 1; 42 int maxsum = 0; 43 int maxans = 0; 44 int sum = 0; 45 if(tn > 0 && tworm[0].val <= m) 46 { 47 maxsum += tworm[0].val; 48 maxans = tn; 49 for(i = 0; i < tn; i++) 50 { 51 if(!i) sum += tworm[i].wei; 52 else {sum --; sum += tworm[i].wei;} 53 } 54 } 55 for(;sum != 0 && tzn >= 0;) 56 { 57 sum --, maxans ++, tzn --; 58 } 59 if(tzn < 0) printf("%d %d\n",maxans,maxsum); 60 else 61 { 62 m -= maxsum; 63 for(i = 1,j = 0; i < tn && j <= tzn;) 64 { 65 if(tworm[i].val <= zworm[j].val) 66 { 67 if(m >= tworm[i].val) 68 { 69 maxans ++, tzn --; 70 maxsum += tworm[i].val; 71 m -= tworm[i].val; 72 i++; 73 } 74 else break; 75 } 76 else 77 { 78 if(m >= zworm[j].val) 79 { 80 maxans ++; 81 maxsum += zworm[j].val; 82 m -= zworm[j].val; 83 j++; 84 } 85 else break; 86 } 87 } 88 printf("%d %d\n",maxans,maxsum); 89 } 90 } 91 return 0; 92 }