主要考察表达式的解析和高斯消元!!!

 #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的更多相关文章

  1. POJ 1487:Single-Player Games 浮点数高斯消元

    Single-Player Games Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1287   Accepted: 36 ...

  2. 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. 魔兽争霸3 replay 格式

    ******************************************************************************* * WarCraft III Repla ...

  4. Fast-paced Multiplayer

    http://www.gabrielgambetta.com/fpm1.html —————————————————————————————————————————————————————— Fast ...

  5. poj很好很有层次感(转)

    OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...

  6. POJ题目分类推荐 (很好很有层次感)

    著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299 ...

  7. 绿色 或者 免安装 软件 PortableApps

    Refer to http://portableapps.com/apps for detail. Below is just a list at Jan-01-2017 for quick show ...

  8. Unity Networking API文档翻译(二):The High Level API

    高级API (HLAPI) 是用来提供给Unity 创建多人在线游戏的组件.它是在底层传输层的基础上构建的, 对多人在线游戏提供了很多通用的功能.当传输层支持各种网络拓扑结构的时候,HLAPI是一个功 ...

  9. 【IOS笔记】Creating Custom Content View Controllers

    Creating Custom Content View Controllers 自定义内容视图控制器 Custom content view controllers are the heart of ...

随机推荐

  1. SQL通过日期计算年龄

    首先建立一个表如下: ======================= BirthDay datetime not null Age 通过公式计算得出 ======================= 以 ...

  2. Linux学习三部曲(之一)

    作为.NET程序员,一直以来都是windows环境下工作,很少接触到linux系统.但是随着微软跨出跨平台这一步之后,相信.NET程序员在linux平台进行开发也会变得越来越寻常. 所以,今天这篇文章 ...

  3. (转)Hessian(C#)介绍及使用说明

    什么是Hessian? Hessian是Caucho开发的一种二进制Web Service协议.支持目前所有流行的开发平台. Hessia能干什么? hessian用来实现web服务. Hessia有 ...

  4. Spring Mvc模式下Jquery Ajax 与后台交互操作

    1.基本代码 1)后台控制器基本代码 @Controller @RequestMapping("/user") public class UserController { @Aut ...

  5. c#基础笔记-----------集合

    首先所谓集合是用于管理对象的容器类.一方面集合将独立的对象汇集成群集,作为一个群集来管理,以便进行整体性操作:而另一方面,集合可以方便地获取群集中的个体,进行个体化操作.在.Net中,集合被封装为对象 ...

  6. win7中CIFS挂载和解挂

    1.win7挂载CIFS共享至Z盘指令(用户名:test,密码:123456): net use Z: \\192.168.8.63\ygcd\duanxiuwei 123456 /USER:test ...

  7. Easyui 生成layout

    Easyui 生成layout var $tabs; var $body; var $south; function appendLayout(title, href) { if (!$body) $ ...

  8. VB.NET转C#代码的工具

    比如VB.NET的代码: For Each prop In entity.Details.Properties.All(). OfType(Of Microsoft.LightSwitch.Detai ...

  9. PHP学习之环境搭建

    计算机环境 win7  64位 搭建  apache-httpd-2.2-win64  +  php-5.3.6-Win32-VC9-x64  +MySQL_5.5.13_winx64开发环境 参考: ...

  10. Think PHP 提示验证码输入错误

    最近遇到一个项目中用的是Thinkphp这个框架开发的,其中在登录这块有验证码这个功能,其实这个功能是TP自带的,其中主要方法是buildImageVerify,位于ThinkPHP\Extend\L ...