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 ...
随机推荐
- Cocos2d-x开发实例:使用Lambda 表达式
在Cocos2d-x 3.0之后提供了对C++11标准[1]的支持,其中的Lambda[2]表达式使用起来非常简洁.我们可以使用Lambda表达式重构上一节的实例. 我们可以将下面的代码: liste ...
- 如何让Eclipse的智能提示像VS一样霸气
说起来用 Eclipse 也有一段时间了,相信每一个用过的人都知道他的智能提示功能真的是糟糕透了,与 VisualStudio2008 简直不是一个档次的!我就纳闷了,他为什么不弄好一点呢!今天我实在 ...
- java实现的一个maven多模块项目自动生成工具
平时在做spring mvc web新项目时,都需要自己去搭建spring mvc的项目框架,包括基本pom 依赖引入,基本配置文件(web.xml,spring-mvc.xml,数据库配置文件等等) ...
- stl的实现原理简单讲解,通熟易懂
总结 需要经常随机访问请用vector 2.list list就是双向链表,元素也是在堆中存放,每个元素都是放在一块内存中,它的内存空间可以是不连续的,通过指针来进行数据的访问,这个特点使得它的随机存 ...
- C++对象的JSON序列化与反序列化探索
一:背景 作为一名C++开发人员,我一直很期待能够像C#与JAVA那样,可以轻松的进行对象的序列化与反序列化,但到目前为止,尚未找到相对完美的解决方案. 本文旨在抛砖引玉,期待有更好的解决方案:同时向 ...
- Wildfly8 更改response header中的Server参数
项目经过局方安全检查需要屏蔽掉服务器中间件信息,查了一下午,网上看到的都是修改jboss7的,我们使用的wildfly8(jboss改名为wildfly),修改地方不一样,折磨了半天. jboss服务 ...
- JAVA_SE复习(Class)
一.面向对象程序设计(OOP) 1.面向对象的程序设计是程序开发的一种方法.它将对象作为程序的基本单元,将程序和 数据封装其中,以提高软件的重用性.灵活性和扩展性 2.三个特征: 封装:隐藏信息 继承 ...
- DTCMS自定义标签:面包屑导航,栏目中通过栏目调用名称获得栏目名称
DTcms.Web.UI\Label\category.cs中增加标签 /// <summary> /// 自定义:通过类别name获得类别title /// </summary&g ...
- 解决DB2事物日志满、扩充表字段长度和表空间的命令
解决DB2事物日志满.扩充表字段长度和表空间的命令 转:http://blog.sina.com.cn/s/blog_4c0137d10100bb5r.html 一.通常我们在使用db2导入数据或进行 ...
- js 根据当前星期做跳转(代码段)
var week = [6,0,1,2,3,4,5]; $('.HotShop_head .HotShop_tab:eq('+week[new Date().getDay()]+')').click( ...