poj 1487 Single-Player Games
主要考察表达式的解析和高斯消元!!!
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
#define ll __int64
#define pi acos(-1.0)
#define SIZE 1024
using namespace std;
const double eps=1e-;
inline bool zero(double x)
{
return fabs(x)<eps;
}
struct node
{
int type,val;
node(){}
node(int _type,int _val){
type=_type;
val=_val;
}
}an[SIZE];
vector<int> g[SIZE];
double mat[][];
int n,ind;
char *p;
void build(int now)
{
int t,m;
while(*p){
while(*p==' '&&*p) p++;
if(!*p) break;
if((*p>=''&&*p<='')||*p=='-'){
ind++;
sscanf(p,"%d%n",&t,&m);
p+=m;
an[ind]=node(,t);
g[now].push_back(ind);
}
else if(*p=='(')
{
ind++;
an[ind]=node(-,);
p++;
g[now].push_back(ind);
build(ind);
}
else if(*p==')')
{
p++;
return;
}
else{
ind++;
an[ind]=node(,*p-'a');
p++;
g[now].push_back(ind);
}
}
}
void toMat(int now,double tp,int var)
{
double p;
if(g[now].size()) p=tp/g[now].size();
for(int i=;i<(int)g[now].size();i++){
int x=g[now][i];
if(an[x].type==-)
toMat(x,p,var);
else{
if(an[x].type==)
mat[var][n]+=an[x].val*p;
else{
mat[var][an[x].val]-=p;
}
}
}
}
void init()
{
ind=;
memset(an,,sizeof(an));
for(int i=;i<SIZE;i++) g[i].clear();
}
void Gauss_line(int a,int b,int col)
{
double mul_a=mat[a][col];
double mul_b=mat[b][col];
for(int i=;i<=n;i++)
mat[b][i]=mat[b][i]-mat[a][i]*mul_b/mul_a;
}
void Gauss()
{
for(int row=,col=;row<n&&col<n;row++,col++){
int ptr=-;
for(int i=row;i<n;i++)
if(!zero(mat[i][col])){
ptr=i;
break;
}
if(ptr==-) continue;
else{
for(int i=;i<=n;i++)
swap(mat[row][i],mat[ptr][i]);
for(int i=;i<n;i++)
if(i!=row)
Gauss_line(row,i,col);
}
}
}
double getans(int x)
{
return mat[x][n]/mat[x][x];
}
bool check(int x)
{
for(int i=;i<n;i++)
if(i!=x&&!zero(mat[x][i]))
return false;
return !zero(mat[x][x]);
}
int main(){
int m,i,j,t=;
char cmd[SIZE];
while(cin>>n&&n){
memset(mat,,sizeof(mat));
printf("Game %d\n",t++);
for(int i=;i<n;i++){
init();
do{
gets(cmd);
}while(*cmd=='\0');
p=cmd;
while(*p!='(') p++;
build();
toMat(,.,i);
mat[i][i]+=1.0;
}
Gauss();
for(i=;i<n;i++){
if(check(i))
printf("Expected score for %c = %.3lf\n",'a'+i,getans(i));
else
printf("Expected score for %c undefined\n",'a'+i);
}
printf("\n");
}
return ;
}
poj 1487 Single-Player Games的更多相关文章
- POJ 1487:Single-Player Games 浮点数高斯消元
Single-Player Games Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 1287 Accepted: 36 ...
- How to Hack Unity Games using Mono Injection Tutorial
https://guidedhacking.com/threads/how-to-hack-unity-games-using-mono-injection-tutorial.11674/ Unity ...
- 魔兽争霸3 replay 格式
******************************************************************************* * WarCraft III Repla ...
- Fast-paced Multiplayer
http://www.gabrielgambetta.com/fpm1.html —————————————————————————————————————————————————————— Fast ...
- poj很好很有层次感(转)
OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...
- POJ题目分类推荐 (很好很有层次感)
著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299 ...
- 绿色 或者 免安装 软件 PortableApps
Refer to http://portableapps.com/apps for detail. Below is just a list at Jan-01-2017 for quick show ...
- Unity Networking API文档翻译(二):The High Level API
高级API (HLAPI) 是用来提供给Unity 创建多人在线游戏的组件.它是在底层传输层的基础上构建的, 对多人在线游戏提供了很多通用的功能.当传输层支持各种网络拓扑结构的时候,HLAPI是一个功 ...
- 【IOS笔记】Creating Custom Content View Controllers
Creating Custom Content View Controllers 自定义内容视图控制器 Custom content view controllers are the heart of ...
随机推荐
- php 中cookie和session的用法比较
1.cookie数据存放在客户的浏览器上,session数据放在服务器上. 2.cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗,考虑到安全应当使用session. ...
- LeftOuterJoin和OuterApply性能比较(转)
建立测试环境: 建立一个表Department和Employee,并向Department插入50W条记录,向Employee插入200W条记录, 我们就拿[统计DepartmentID 从15000 ...
- Cocos2d-x中SQLite数据库管理工具
数据库创建完成后,我们可能需要看看数据库中数据是否成功插入,很多人喜欢使用图形界面工具来管理SQLite数据库.SQLite图形界面管理工具有很多,我推荐使用SQLiteStudio工具,下载地址ht ...
- 关于百度编辑器UEditor(1.4.3)在C#.NET中的应用实例
首先去百度UEditor官网下载 1.4.3 .net版本 http://ueditor.baidu.com/build/build_down.php?n=ueditor&v=1_4_3-ut ...
- 如何在IOS开发中在自己的framework中添加.bunble文件
今天就跟大家介绍一下有关,如何在IOS开发中在自己的framework中添加.bunble文件,该文章我已经在IOS教程网(http://ios.662p.com)发布过来,个人觉得还是对大家有帮助的 ...
- fedora下python3 安装tkinter和pygame
root 下用 “yum search tkinter”,如下图所示: 然后再根据系统选择安装就好了. tkinter安装完毕. 接下来是安装pygame在fedora的python3上,我的是pyt ...
- dom4j api 详解--XPath 节点详解
dom4j api 详解 http://871421448.iteye.com/blog/1546955 XPath 节点 http://www.w3school.com.cn/xpath/xpath ...
- 【转】JS函数的定义与调用方法
JS函数调用的四种方法:方法调用模式,函数调用模式,构造器调用模式,apply,call调用模式 1.方法调用模式:先定义一个对象,然后在对象的属性中定义方法,通过myobject.property来 ...
- 解决svn “clean up" 失败
解决方法:清空svn的队列 1.下载sqlite3.exe 2.找到你项目的.svn文件,查看是否存在wc.db 3.将sqlite3.exe放到.svn的同级目录 4.启动cmd执行sqlite3 ...
- php计算代码运行时间与内存使用的一段代码
计算运行时间及内存使用,代码如下: <?php //开始计时 $HeaderTime = microtime(true);//参数true表示返回浮点数值 //代码 //... printf(& ...