poj 1191
来源:互联网 发布:地理空间数据库 编辑:程序博客网 时间:2024/06/12 22:44
#include <iostream>#include <algorithm>#include <queue>#include <cstring>#include <cstdio>#include <vector>#include <string>#include <iterator>#include <cmath>#include <deque>#include <stack>#include <cctype>#include <iomanip>using namespace std;typedef long long ll;typedef long double ld;const int N = 1100;const int INF = 0xfffffff;const double EPS = 1e-8;const ll MOD = 1e9 + 7;const ld PI = acos (-1.0);#define INFL 0x7fffffffffffffffLL#define met(a, b) memset(a, b, sizeof(a))#define put(a) cout << setiosflags(ios::fixed) << setprecision(a)int dp[16][9][9][9][9], sum[9][9]; //左上角为1 1的矩阵和int cut (int k, int x1, int y1, int x2, int y2);int getsum (int x1, int y1, int x2, int y2);int main (){ int n; while (cin >> n) { int x, cot = 0; met (dp, -1); met (sum, 0); for (int i=1; i<9; i++) for (int j=1; j<9; j++) { cin >> x; cot += x; sum[i][j] = x + sum[i][j-1] + sum[i-1][j] - sum[i-1][j-1]; } double avr = cot * 1.0 / n; int res = cut (n, 1, 1, 8, 8); double ans = sqrt (res * 1.0 / n - avr * avr); printf ("%.3f\n", ans); } return 0;}int getsum (int x1, int y1, int x2, int y2){ return sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1];}int cut (int k, int x1, int y1, int x2, int y2){ int s1, s2; if (dp[k][x1][y1][x2][y2] != -1) return dp[k][x1][y1][x2][y2]; if (k == 1) { s1 = getsum (x1, y1, x2, y2); return dp[k][x1][y1][x2][y2] = s1 * s1; } int minx = INF, tmp1, tmp2; for (int x=x1; x<x2; x++) { s1 = getsum (x1, y1, x, y2); s2 = getsum (x+1, y1, x2, y2); tmp1 = min (cut (k-1, x+1, y1, x2, y2) + s1*s1, cut(k-1, x1, y1, x, y2) + s2*s2); minx = min (minx, tmp1); } for (int y=y1; y<y2; y++) { s1 = getsum (x1, y1, x2, y); s2 = getsum (x1, y+1, x2, y2); tmp2 = min (cut(k-1, x1, y+1, x2, y2) + s1*s1, cut(k-1, x1, y1, x2, y) + s2*s2); minx = min (minx, tmp2); } return dp[k][x1][y1][x2][y2] = minx;}
《算法艺术与信息学竞赛》的116页有讲解,先将方差公式化简,最终确定只需求切割n-1次后n块矩形中每块矩形的总分的平方的和最小。
设这个平方和为res,最终的答案就为res/n-avrg^2开根号
wa的几个地方提示:
用double %.3lf 输出 G++ wa c++ ac
用double %.3f 输出 G++ ac c++ ac
要是正规比赛 怎么能想到坑在这 虽然不知道为什么 但是先记住了
0 0
- poj 1191
- POJ 1191
- poj 1191
- POJ 1191
- POJ 1191
- poj-1191
- poj 1191
- POJ 1191棋盘分割
- poj 1191 普通dp
- poj 1191 棋盘分割
- Poj 1191 棋盘分割
- poj 1191 棋盘分割
- POJ 1191 棋盘分割
- poj 1191棋盘分割
- poj 1191 dp经典
- poj 1191 搜索+剪枝
- poj 1191 棋盘分割
- POJ-1191-棋盘分割
- static关键字
- HDOJ 5223 GCD
- Webx中的uris
- 未能从程序集“System.ServiceModel, Version=3.0.0.0”中加载类型“System.ServiceModel.Activation.HttpModule” 的解决办法
- 直接插入排序法
- poj 1191
- Save Failed Compilation unit name must end with .java, or one of the registered java-like extensions
- 送上最新鲜的互联网行业新闻-【2015-05-07】
- 编程遇到的问题:20150507,Java中byte[]与int的互转
- 反射的性能
- ios网络请求 get——post 区别
- Markdown 语法(1)- 写标题
- CGContext
- 黑马程序员——java基础学习--IO流