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

  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<algorithm>
  4. #include<iomanip>
  5. #include<cmath>
  6. #include<cstring>
  7. #include<vector>
  8. #define ll __int64
  9. #define pi acos(-1.0)
  10. #define SIZE 1024
  11. using namespace std;
  12. const double eps=1e-;
  13. inline bool zero(double x)
  14. {
  15. return fabs(x)<eps;
  16. }
  17. struct node
  18. {
  19. int type,val;
  20. node(){}
  21. node(int _type,int _val){
  22. type=_type;
  23. val=_val;
  24. }
  25. }an[SIZE];
  26. vector<int> g[SIZE];
  27. double mat[][];
  28. int n,ind;
  29. char *p;
  30. void build(int now)
  31. {
  32. int t,m;
  33. while(*p){
  34. while(*p==' '&&*p) p++;
  35. if(!*p) break;
  36. if((*p>=''&&*p<='')||*p=='-'){
  37. ind++;
  38. sscanf(p,"%d%n",&t,&m);
  39. p+=m;
  40. an[ind]=node(,t);
  41. g[now].push_back(ind);
  42. }
  43. else if(*p=='(')
  44. {
  45. ind++;
  46. an[ind]=node(-,);
  47. p++;
  48. g[now].push_back(ind);
  49. build(ind);
  50. }
  51. else if(*p==')')
  52. {
  53. p++;
  54. return;
  55. }
  56. else{
  57. ind++;
  58. an[ind]=node(,*p-'a');
  59. p++;
  60. g[now].push_back(ind);
  61. }
  62. }
  63. }
  64. void toMat(int now,double tp,int var)
  65. {
  66. double p;
  67. if(g[now].size()) p=tp/g[now].size();
  68. for(int i=;i<(int)g[now].size();i++){
  69. int x=g[now][i];
  70. if(an[x].type==-)
  71. toMat(x,p,var);
  72. else{
  73. if(an[x].type==)
  74. mat[var][n]+=an[x].val*p;
  75. else{
  76. mat[var][an[x].val]-=p;
  77. }
  78. }
  79. }
  80. }
  81. void init()
  82. {
  83. ind=;
  84. memset(an,,sizeof(an));
  85. for(int i=;i<SIZE;i++) g[i].clear();
  86. }
  87. void Gauss_line(int a,int b,int col)
  88. {
  89. double mul_a=mat[a][col];
  90. double mul_b=mat[b][col];
  91. for(int i=;i<=n;i++)
  92. mat[b][i]=mat[b][i]-mat[a][i]*mul_b/mul_a;
  93. }
  94. void Gauss()
  95. {
  96. for(int row=,col=;row<n&&col<n;row++,col++){
  97. int ptr=-;
  98. for(int i=row;i<n;i++)
  99. if(!zero(mat[i][col])){
  100. ptr=i;
  101. break;
  102. }
  103. if(ptr==-) continue;
  104. else{
  105. for(int i=;i<=n;i++)
  106. swap(mat[row][i],mat[ptr][i]);
  107. for(int i=;i<n;i++)
  108. if(i!=row)
  109. Gauss_line(row,i,col);
  110. }
  111. }
  112. }
  113. double getans(int x)
  114. {
  115. return mat[x][n]/mat[x][x];
  116. }
  117. bool check(int x)
  118. {
  119. for(int i=;i<n;i++)
  120. if(i!=x&&!zero(mat[x][i]))
  121. return false;
  122. return !zero(mat[x][x]);
  123. }
  124. int main(){
  125. int m,i,j,t=;
  126. char cmd[SIZE];
  127. while(cin>>n&&n){
  128. memset(mat,,sizeof(mat));
  129. printf("Game %d\n",t++);
  130. for(int i=;i<n;i++){
  131. init();
  132. do{
  133. gets(cmd);
  134. }while(*cmd=='\0');
  135. p=cmd;
  136. while(*p!='(') p++;
  137. build();
  138. toMat(,.,i);
  139. mat[i][i]+=1.0;
  140. }
  141. Gauss();
  142. for(i=;i<n;i++){
  143. if(check(i))
  144. printf("Expected score for %c = %.3lf\n",'a'+i,getans(i));
  145. else
  146. printf("Expected score for %c undefined\n",'a'+i);
  147. }
  148. printf("\n");
  149. }
  150. return ;
  151. }

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. Cocos2d-x开发实例:使用Lambda 表达式

    在Cocos2d-x 3.0之后提供了对C++11标准[1]的支持,其中的Lambda[2]表达式使用起来非常简洁.我们可以使用Lambda表达式重构上一节的实例. 我们可以将下面的代码: liste ...

  2. 如何让Eclipse的智能提示像VS一样霸气

    说起来用 Eclipse 也有一段时间了,相信每一个用过的人都知道他的智能提示功能真的是糟糕透了,与 VisualStudio2008 简直不是一个档次的!我就纳闷了,他为什么不弄好一点呢!今天我实在 ...

  3. java实现的一个maven多模块项目自动生成工具

    平时在做spring mvc web新项目时,都需要自己去搭建spring mvc的项目框架,包括基本pom 依赖引入,基本配置文件(web.xml,spring-mvc.xml,数据库配置文件等等) ...

  4. stl的实现原理简单讲解,通熟易懂

    总结 需要经常随机访问请用vector 2.list list就是双向链表,元素也是在堆中存放,每个元素都是放在一块内存中,它的内存空间可以是不连续的,通过指针来进行数据的访问,这个特点使得它的随机存 ...

  5. C++对象的JSON序列化与反序列化探索

    一:背景 作为一名C++开发人员,我一直很期待能够像C#与JAVA那样,可以轻松的进行对象的序列化与反序列化,但到目前为止,尚未找到相对完美的解决方案. 本文旨在抛砖引玉,期待有更好的解决方案:同时向 ...

  6. Wildfly8 更改response header中的Server参数

    项目经过局方安全检查需要屏蔽掉服务器中间件信息,查了一下午,网上看到的都是修改jboss7的,我们使用的wildfly8(jboss改名为wildfly),修改地方不一样,折磨了半天. jboss服务 ...

  7. JAVA_SE复习(Class)

    一.面向对象程序设计(OOP) 1.面向对象的程序设计是程序开发的一种方法.它将对象作为程序的基本单元,将程序和 数据封装其中,以提高软件的重用性.灵活性和扩展性 2.三个特征: 封装:隐藏信息 继承 ...

  8. DTCMS自定义标签:面包屑导航,栏目中通过栏目调用名称获得栏目名称

    DTcms.Web.UI\Label\category.cs中增加标签 /// <summary> /// 自定义:通过类别name获得类别title /// </summary&g ...

  9. 解决DB2事物日志满、扩充表字段长度和表空间的命令

    解决DB2事物日志满.扩充表字段长度和表空间的命令 转:http://blog.sina.com.cn/s/blog_4c0137d10100bb5r.html 一.通常我们在使用db2导入数据或进行 ...

  10. js 根据当前星期做跳转(代码段)

    var week = [6,0,1,2,3,4,5]; $('.HotShop_head .HotShop_tab:eq('+week[new Date().getDay()]+')').click( ...