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学习笔记 - 进阶篇(11)
PHP学习笔记 - 进阶篇(11) 数据库操作 PHP支持哪些数据库 PHP通过安装相应的扩展来实现数据库操作,现代应用程序的设计离不开数据库的应用,当前主流的数据库有MsSQL,MySQL,Syba ...
- c#输出json,其中包含子json (可以含 无限级 子json)的方法思路
首页 给出 DataTable 转Json 的方法: public static string TableToJson(DataTable dt) { List<Dictionary<s ...
- javascript笔记——jqGrid 格式化时间列
{ name:'startTime', sortable:false, editable:true, width:300, sorttype:'date', //unformat:startTime, ...
- maven入门程序(3)
欢迎转载交流:http://www.cnblogs.com/shizhongtao/p/3472864.html 这里我将展示如何用maven快速创建一个基于spring的web框架.创建步骤和上一篇 ...
- SQLite学习心得
SQLite是一款很有名气的小型开源跨平台数据库,作为目前最流行的开源嵌入式关系型数据库,在系统结构设计中正在扮演着越来越重要的角色. 本文主要沿着 http://www.cppblog.com/we ...
- ThinkPHP3.2 加载过程(二)
回顾: 上次介绍了 ThinkPHP 的 Index.PHP入口文件.但只是TP的入口前面的入口(刷boss总是要过好几关才能让你看到 ,不然boss都没面子啊),从Index.PHP最后一行把我们引 ...
- 译文:Javascript-Functions
个人理解+google翻译+有道翻译.如有错误,请指正.原文来自MDN:Functions Functions是javascript基本构建模块之一.每一个function是一个javascript程 ...
- discuz论坛X3升级时 文件下载出现问题,请查看您的服务器网络以及data目录是否有写权限
discuz论坛2.5升级X3时候, 在线升级一半提示: 文件 static/image/postbg/3.jpg 下载出现问题,请查看您的服务器网络以及data目录是否有写权限,请确认无误后点击确定 ...
- Java.lang.RuntimeException: Unable to instantiate activity ComponentInfo
如果你更新了ADT的新版本,而工程文件中使用了其他的jar包,也可能会出现"java.lang.RuntimeException: Unable to instantiate activit ...
- 用phpmailer发邮件 中文乱码问题解决
加入如下代码解决. $mail->CharSet = "GB2312"; //utf-8; $mail->Encoding = "base64"; ...