hdu 4925 贪心 自己从小到大做数据找方法规律
2015-12-29 12:51
253 查看
http://acm.hdu.edu.cn/showproblem.php?pid=4925
自己逐个做数据找规律。提供下我的找的:
1 2
1 3
2 2
2 3
3 3
然后发现这种矩阵是最优的:
然后初始化的时候搞一个100*100的矩阵。然后每次对这个矩阵统计下2^1 2^2 2^3 2^4各有几个就可以
WA了一次。由于我的统计方法里,n==1 m==1这样的会出现错误
自己逐个做数据找规律。提供下我的找的:
1 2
1 3
2 2
2 3
3 3
然后发现这种矩阵是最优的:
然后初始化的时候搞一个100*100的矩阵。然后每次对这个矩阵统计下2^1 2^2 2^3 2^4各有几个就可以
WA了一次。由于我的统计方法里,n==1 m==1这样的会出现错误
#include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include <iomanip> #include <cmath> #include <map> #include <set> #include <queue> using namespace std; #define ls(rt) rt*2 #define rs(rt) rt*2+1 #define ll long long #define ull unsigned long long #define rep(i,s,e) for(int i=s;i<e;i++) #define repe(i,s,e) for(int i=s;i<=e;i++) #define CL(a,b) memset(a,b,sizeof(a)) #define IN(s) freopen(s,"r",stdin) #define OUT(s) freopen(s,"w",stdout) const ll ll_INF = ((ull)(-1))>>1; const double EPS = 1e-8; const int INF = 100000000; ll n,m; const int MAXN = 110; bool mat[MAXN][MAXN]; ll p[5]={1,2,4,8,16}; ll cnt[5]; void init() { for(int i=1;i<=100;i++) for(int j=1;j<=100;j++) { if(i%2)mat[i][j]=j%2; else mat[i][j]=!(j%2); } } ll solve() { CL(cnt,0); //ll a1=0,a2,a3,a4=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(mat[i][j]) { ll ret=0; if(i-1>=1)ret++; if(i+1<=n)ret++; if(j-1>=1)ret++; if(j+1<=m)ret++; cnt[ret]++; } } return p[1]*cnt[1]+p[2]*cnt[2]+p[3]*cnt[3]+p[4]*cnt[4]; } int main() { //IN("hdu4925.txt"); int ncase; init(); scanf("%d",&ncase); while(ncase--) { scanf("%I64d%I64d",&n,&m); if(n==1 && m==1)printf("1\n"); else printf("%I64d\n",solve()); } return 0; }
相关文章推荐
- iOS开源项目(旧)
- #! /usr/bin/env在脚本中的作用
- java正则表达式和转义字符
- Java eclipse下 Ant build.xml实例详解 附完整项目源码
- 为项目添加滑动删除效果
- 存储过程相关知识 汇总
- Dagger2的使用
- MyBatis学习总结(10)——批量操作
- MyBatis学习总结(10)——批量操作
- MyBatis学习总结(10)——批量操作
- 如何删除Ambari已有的服务
- 第五章 消息摘要算法--MAC
- 父Shell与子Shell
- 复制:我就差一个程序员了!
- unzip、cp命令参数
- springmvc文件上传(原生)
- ElasticSearch 新建mapping
- eclipse 中运行代码 出现:editor does not contain a main type
- ERP和商业智能
- linux+jenkins+tomcat+git 安装过程的的一些小问题