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

 #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. Quartz 第五课 SimpleTriggers 官方文档翻译

    对于SimpleTrigger你需要知道它的启动总是在一个特殊的时间点或者有你设置的重复时间段中.直白来说,如果你想在2005年1月13日,正好上午11时23分54秒触发,然后执行五次,每十秒钟. 从 ...

  2. (转)软件版本中的Alpha,Beta,RC,Trial是什么意思?

    版本号:V(Version):即版本,通常用数字表示版本号.(如:EVEREST Ultimate v4.20.1188 Beta )Build:用数字或日期标示版本号的一种方式.(如:VeryCD ...

  3. 老老实实学WCF[第一篇] Hell wcf

    老老实实学WCF  第一篇 Hello WCF WCF(Windows Communication Foundation)是微软公司推出的面向服务技术的集大成者,涵盖继承了其之前发布的所有的分布式应用 ...

  4. dorado7 重装了tomcat后配置路径

    在Windows->Preferences->Server->Runtime Environments把先前的工程Servers删除掉

  5. Shared library can't open object

    将cpp的源文件和.so (shared object)链接成可执行程序之后,无法运行,提示如标题,实际就是找不到共享库. 最终找到了解决办法是: export LD_LIBRARY=./:$LD_L ...

  6. DTCMS栏目首页,循环输出子栏目和新闻

    <%set DataTable categoryList=get_category_child_list(channel,0)%> <%foreach(DataRow cdr in ...

  7. CentOS 安装jdk1.7 64位

    [root@localhost ~]# java -versionjava version "1.6.0"OpenJDK Runtime Environment (build 1. ...

  8. CSS控制 table 的 cellpadding,cellspacing

    CSS 常规解决办法: 表格的 cellpadding 和 cellspacing 我们经常会用如下的方式来清除默认样式: <table cellspacing="0" ce ...

  9. Device eth0 does not seem to be present

    解决办法: 首先,打开/etc/udev/rules.d/70-persistent-net.rules内容如下面例子所示: # vi /etc/udev/rules.d/70-persistent- ...

  10. 浅析 public static void main(String[] args)

    最初接触Java程序的时候,老师就教导我们要从下面这句开始学起,据说是约定俗成的,所以直到今天,还是只知道java程序应该这么写,具体为什么这么写,鄙人惭愧. public class ClassNa ...