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

 #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. 移植FastBlur模糊算法至SDL

    FastBlur是Android标配的模糊算法,这也在当时引起了一股毛玻璃热潮.IOS7就采用了此算法(这有抄袭Android之嫌,因为Android1.5就在标库中加入了此函数).算法效率很高,这也 ...

  2. 编程语言中的Namespace

    Namespace 1.C struct 2.C++(Pronounced 'see jia-jia' or 'see plus-plus') namespace 3.Python module(s) ...

  3. Maven使用总结

    1.pom.xml文件中添加新的库 在中央仓库找不到你想要的jar的时候,可以在pom.xml中添加附加的库,语法如下 <repositories> <repository> ...

  4. 数据库连接池c3p0和dbcp

    现在常用的开源数据连接池主要有c3p0.dbcp和proxool三种,其中: hibernate开发组推荐使用c3p0; spring开发组推荐使用dbcp(dbcp连接池有weblogic连接池同样 ...

  5. java集合的互转

    List<-->数组.List<-->Set.数组<-->Set.Map将键转化为Set.Map将值转化为Set.Map将值转化为List等集合常 public c ...

  6. 解决flash挡住层的问题

    让div在flash上面 设置flash为透明: 插件代码换成如下: <object type="application/x-shockwave-flash" data=&q ...

  7. Winform的窗体美化心酸路

    我想做一位狂热的程序猿粪子! 其实一直都很想做点什么,工作原因林林种种导致停止了前进的脚步. 有时会为自己的一个目标狂热,但经常发觉激情过后更多的总是为自己找借口! 最近感觉奔三将近.逐有感而发,不能 ...

  8. 微信公众号-开发者-自定义菜单-CLICK事件处理

    想点击菜单,推送消息.功能很简单,坑了我一天时间.在此笔记. 菜单代码: { "button":[ { "type":"click", &q ...

  9. 在centos 6.4下安装opencv 2.3.1

    系统环境介绍: centos 6.4 1.安装依赖包 yum install cmake gcc gcc-c++ gtk+-devel gimp-devel gimp-devel-tools gimp ...

  10. splObjectStroge的作用,实例化一个数组

    PHP SPL SplObjectStorage是用来存储一组对象的,特别是当你需要唯一标识对象的时候. PHP SPL SplObjectStorage类实现了Countable,Iterator, ...