Problem A: Apple(高斯消元)
- 可以发现具有非常多的方程, 然后高斯消元就能85分
- 然而我们发现这些方程组成了一些环, 我们仅仅设出一部分变量即可获得N个方程, 就可以A了
- trick 合并方程
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iostream>
#include <cmath>
#define ldb long double
#define ll long long
#define mmp make_pair
#define M 222
using namespace std;
int read() {
int nm = 0, f = 1;
char c = getchar();
for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
for(; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
return nm * f;
}
int n, m, x, y;
int id[M][M], cnt;
double d[M][M];
double f[M][M][M];
void gauss() {
for(int i = 0; i <= cnt; i++) {
int k = i;
for(int j = i + 1; j <= cnt; j++) if(fabs(d[j][i]) > fabs(d[k][i])) k = j;
if(k != i) for(int j = 0; j <= cnt + 1; j++) swap(d[i][j], d[k][j]);
for(int j = 0; j <= cnt; j++) {
if(i == j) continue;
double t = d[j][i] / d[i][i];
for(int k = 0; k <= cnt + 1; k++) d[j][k] -= d[i][k] * t;
}
}
}
int main() {
n = read(), m = read(), x = read(), y = read();
for(int i = 0; i < m; i++) f[n][i][i] = 1;
for(int i = n - 1; i > x; i--) {
double d = 0.5;
for(int j = 0; j < m; j++,d *= 0.5)
for(int k = 0; k <= m; k++)
f[i][0][k] += d * f[i + 1][j][k];
d *= 2;
f[i][0][m] += 2.0 - d * 2.0;
for(int k = 0; k <= m; k++)
f[i][m][k] = (f[i][0][k] *= 1.0 / (1.0 - d));
for(int j = m - 1; j > 0; j-- ) {
for(int k = 0; k <= m; k++)
f[i][j][k] += 0.5 * (f[i][j + 1][k] + f[i + 1][j][k]);
f[i][j][m] += 1.0;
}
}
for(int i = y - 1; i >= 0; i--) {
for(int k = 0; k <= m; k++)
f[x][i][k] += 0.5 * (f[x][i + 1][k] + f[x + 1][i][k]);
f[x][i][m] += 1.0;
}
for(int k = 0; k <= m; k++)
f[x][m][k] = f[x][0][k];
for(int i = m - 1; i>y; i--) {
for(int k = 0; k <= m; k++)
f[x][i][k] += 0.5 * (f[x][i + 1][k] + f[x + 1][i][k]);
f[x][i][m] += 1.0;
}
for(int i = x - 1; i >= 0; i--) {
double d = 0.5;
for(int j = 0; j < m; j++,d *= 0.5)
for(int k = 0; k <= m; k++)
f[i][0][k] += d * f[i + 1][j][k];
d *= 2;
f[i][0][m] += 2.0 - d * 2.0;
for(int k = 0; k <= m; k++)
f[i][m][k] = (f[i][0][k] *= 1.0 / (1.0 - d));
for(int j = m - 1; j > 0; j--) {
for(int k = 0; k <= m; k++)
f[i][j][k] += 0.5 * (f[i][j + 1][k] + f[i + 1][j][k]);
f[i][j][m] += 1.0;
}
}
memcpy(d,f[0],sizeof(d));
cnt = m - 1;
for(int k = 0; k < m; k++) d[k][k] -= 1.0;
gauss();
printf("%.6lf\n",-d[0][m]/d[0][0]);
return 0;
}
Problem A: Apple(高斯消元)的更多相关文章
- HihoCoder 1195 高斯消元·一(高斯消元)
题意 https://hihocoder.com/problemset/problem/1195 思路 高斯消元是解决高元方程的一种算法,复杂度 \(O(n^3)\) . 过程大致是: 构造一个未知数 ...
- 【POJ】1830 开关问题(高斯消元)
http://poj.org/problem?id=1830 高斯消元无解的条件:当存在非法的左式=0而右式不等于0的情况,即为非法.这个可以在消元后,对没有使用过的方程验证是否右式不等于0(此时因为 ...
- POJ 1681---Painter's Problem(高斯消元)
POJ 1681---Painter's Problem(高斯消元) Description There is a square wall which is made of n*n small s ...
- POJ 1681 Painter's Problem(高斯消元+枚举自由变元)
http://poj.org/problem?id=1681 题意:有一块只有黄白颜色的n*n的板子,每次刷一块格子时,上下左右都会改变颜色,求最少刷几次可以使得全部变成黄色. 思路: 这道题目也就是 ...
- POJ 1681 Painter's Problem 【高斯消元 二进制枚举】
任意门:http://poj.org/problem?id=1681 Painter's Problem Time Limit: 1000MS Memory Limit: 10000K Total ...
- poj 1681 Painter's Problem(高斯消元)
id=1681">http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. ...
- POJ - 1681: Painter's Problem (开关问题-高斯消元)
pro:开关问题,同上一题. 不过只要求输出最小的操作步数,无法完成输出“inf” sol:高斯消元的解对应的一组合法的最小操作步数. #include<bits/stdc++.h> #d ...
- HDU 4818 RP problem (高斯消元, 2013年长春区域赛F题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4818 深深地补一个坑~~~ 现场赛坑在这题了,TAT.... 今天把代码改了下,过掉了,TAT 很明显 ...
- UVALive 7138 The Matrix Revolutions(Matrix-Tree + 高斯消元)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
随机推荐
- Multiple plot function
From: http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/ library(ggplot2) multi ...
- CSS学习笔记_day1
目录 一. 什么是HTML 二.编辑器 三.Html的基本骨架 四.html基本标签 h.p.img.a.audio.video.ul>li.ol>li.dl dd dt.span.div ...
- jquery的相关用法
选择器基本选择器1.id选择器$('#id1')找到id为id1 的标签2.class选择器$('.class1')找到class中有class1这个类的标签3.标签选择器$('tag') 找到tag ...
- vue重温之mint-ui------------点击事件绑定
第一次接触mint-ui,在使用它的tabbar时,为了达到点击切换页面的效果,采用了点击事件的方式,然后就碰到了这么个问题: 是的,点击事件是不起作用的. 然后刚好一个朋友也在做这块,而且有一段时间 ...
- 微信小程序wx.navigateTo页面不跳转
排查后发现: 若是在全局app.json中配置了tabBar,引用的链接与wx.navigateTo页面跳转url地址相同就无法实现跳转.
- Python 基础知识(持续更新中)
内置数据类型: 整型 浮点型 字符串 布尔值 空值 None 列表 list 元组 tuple 字典 dict 集合 set ...
- Tenka 1 Computer Contest C-Align
C - Align Time limit : 2sec / Memory limit : 1024MB Score : 400 points Problem Statement You are giv ...
- CPU:chip、core 和 processor 的关系
# 查看物理CPU个数 (chip) 物理cpu数:主板上实际插入的cpu数量,可以数不重复的 physical id 有几个(physical id)cat /proc/cpuinfo| gr ...
- SQL Server Service Broker 示例(转)
1.定义数据类型.协议和服务(发送服务和接收服务) USE master; GO ALTER DATABASE 目标数据库 SET ENABLE_BROKER; GO -- 如果上面的操作执行后,长时 ...
- orientdb docker-compose 运行
orientdb 很早就跑过,但是现在在跑,发现配置有些变动,原有studio 直接就可以访问的,新版本的居然还需要自己添加 server 的配置,所以为了方便使用docker-compose 运行, ...