hdu 4462 Scaring the Birds(暴力,细读)
来源:互联网 发布:h5建站源码 编辑:程序博客网 时间:2024/06/05 14:24
题意:http://acm.hdu.edu.cn/showproblem.php?pid=4462
我想说,这道题不是考验数据结构或是神马复杂的算法,就是考验人的阅读能力和思维的缜密。有两点:第一点都能看出来,当k=0时不能保护已有的庄稼;第二点,当k=n*n时,即所有的点都是没有庄稼的,直接输出0.
#include <iostream>#include<cstdio>#include<cstring>using namespace std;int n,k; //2^16=65536bool tag[55][55];int sec[11][2],r[11];bool chao(int a,int b){ return (a<1||a>n||b<1||b>n);}void cover(int x,int y,int r){ for(int j=y-r;j<=y+r;j++){ if(chao(x,j))continue; tag[x][j]=1; } for(int i=x-r;i<x;i++){ for(int j=y;j<=y+i-x+r;j++){ if(chao(i,j)); else tag[i][j]=1; if(chao(2*x-i,j)); else tag[2*x-i][j]=1; if(chao(i,y-(j-y))); else tag[i][2*y-j]=1; if(chao(2*x-i,2*y-j)); else tag[2*x-i][2*y-j]=1; } }}bool ok(){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(tag[i][j]==0)return 0; } } return 1;}void showtag(){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++)cout<<tag[i][j]<<" "; cout<<endl; }}void intial(){ for(int i=1;i<=k;i++){ tag[sec[i][0]][sec[i][1]]=1; }}int main(){ //freopen("cin.txt","r",stdin); while(cin>>n&&n){ scanf("%d",&k); memset(sec,0,sizeof(sec)); memset(r,0,sizeof(r)); for(int i=1;i<=k;i++)scanf("%d%d",&sec[i][0],&sec[i][1]); for(int i=1;i<=k;i++)scanf("%d",&r[i]); int length=1<<k,ans=0x3f3f3f3f; for(int i=0;i<length;i++){ memset(tag,0,sizeof(tag)); intial(); //showtag(); if(ok()){ ans=0; break; } int sum=0; for(int j=1;j<=k;j++){ if((i>>(j-1))&1){ sum++; cover(sec[j][0],sec[j][1],r[j]); } } //cout<<"sum: "<<sum<<endl; if(ok())ans=ans<sum?ans:sum; } if(ans>k)printf("-1\n"); else printf("%d\n",ans); } return 0;}
0 0
- hdu 4462 Scaring the Birds(暴力,细读)
- hdu 4462 Scaring the Birds (暴力)
- HDU 4462 Scaring the Birds (暴力枚举DFS)
- hdu 4462 Scaring the Birds【Dfs+暴力判断】
- hdu 4462 Scaring the Birds # 暴力枚举(状压)
- HDU 4462(Scaring the Birds)
- HDU 4462 Scaring the Birds
- HDU 4462 Scaring the Birds
- hdu 4462 Scaring the Birds
- HDU 4462 Scaring the Birds
- HDU 4462 Scaring the Birds
- HDU Scaring the Birds
- hdu 4462 Scaring the Birds 状态压缩
- [dfs+水] hdu 4462 Scaring the Birds
- hdu 4462 Scaring the Birds(STL)
- hdu 4462 Scaring the Birds 回溯法
- HDU 4462 Scaring the Birds(dfs)
- HDU 4462 Scaring the Birds (枚举+暴搜)
- 李航《统计学习方法》多项式函数拟合问题V2
- IOS网络编程:HTTP
- 创建或打开android模拟器时遇到的问题,以及打开后遇到的Failed to install FragmentTest.apk on device 'emulator-5554': timeout
- 学习编程的初心
- Ubuntu14.04下搭建reaver pin码破解wifi
- hdu 4462 Scaring the Birds(暴力,细读)
- 数据库角色、数据库用户、权限
- wireshark抓包学习
- 安装ROS工具包和Rviz仿真器
- 3、uc/os:任务控制块OS_TCB
- Android中Thread的使用之Handler机制
- [转] 图像放大并进行BiCubic插值 Matlab/C++代码
- poll函数和select函数
- 【麦可网】Cocos2d-X跨平台游戏开发学习笔记---第二十三课:Cocos2D-X音频系统1-3