zoj1155 triangle war

博弈(alpha-beta 剪枝)POJ —— 1085 Triangle War 阅读详情
  1. /**
  2. DP 
  3. 对状态编号, 18条边, 每条边可能实线, 也可能虚线, 有2^18种
  4. MaxScore(x) = max { 
  5.               StepScore(rCode, selectedEdgeNum) > 0 
  6.            ?  StepScore + MaxScore(rCode)         //选择的边成三角行 
  7.            :  RemainScore(x) -  MaxScore(rCode)   //选择的边不成三角形 
  8. }
  9. max 函数作用在所有虚线边上。 
  10. **/
  11. #include <cstdlib>
  12. #include <iostream>
  13. using namespace std;
  14. int maxScore[262144]; //2^18
  15. //给18条边编号, 边的编号见附图 
  16. const int EDGENUM[10][10] = {
  17.      /*1, 2,  3, 4,  5,  6,  7,  8,  9  10 **/
  18.       -1, 0,  1, -1, -1, -1, -1, -1, -1, -1, //1
  19.       0, -1,  2,  3,  4, -1, -1, -1, -1, -1, //2
  20.       1,  2,  -1, -1, 5, 6,  -1, -1, -1, -1, //3
  21.       -1, 3, -1, -1,  7, -1,  9, 10, -1, -1, //4
  22.       -1, 4 , 5,  7, -1,  8, -1, 11, 12, -1, //5
  23.       -1, -1,  6, -1, 8, -1, -1, -1, 13, 14, //6
  24.       -1, -1, -1,  9, -1, -1, -1, 15, -1, -1, //7
  25.       -1, -1, -1, 10, 11, -1, 15, -1, 16, -1, //8
  26.       -1, -1, -1, -1, 12, 13, -1, 16, -1, 17, //9
  27.       -1, -1, -1, -1, -1, 14, -1, -1, 17, -1, //10
  28. };
  29. const int BIT[18] = { 1, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7, 1<<8,
  30.                   1<<9, 1<<10, 1<<11, 1<<12, 1<<13, 1<<14, 1<<15, 1<<16, 1<<17 };
  31.                   
  32. struct Triangle {
  33.        int e1, e2, e3;//三条边的编号 
  34. };
  35. //列举9个三角形 
  36. const Triangle triangle[9] = {
  37.                            {0, 1, 2},
  38.               {3, 4, 7},   {2, 4, 5},    {5, 6, 8},
  39. {9, 10, 15}, {7, 10, 11}, {11, 12, 16}, {8, 12, 13}, {13, 14, 17}
  40. };
  41. int StepScore(int x, int i)
  42. {
  43.     int score = 0;
  44.     for (int j=0; j<9; j++)
  45.     {
  46.         Triangle tri = triangle[j];
  47.         if ( x & BIT[tri.e1] && x & BIT[tri.e2] && x & BIT[tri.e3] )
  48.         {
  49.              if (i == tri.e1 || i == tri.e2 || i == tri.e3)
  50.                 score++;
  51.         }
  52.     }
  53.     return score;
  54. }
  55. int RemainScore(int x)
  56. {
  57.     int score = 9;
  58.     for (int j=0; j<9; j++)
  59.     {
  60.         Triangle tri = triangle[j];
  61.         if ( x & BIT[tri.e1] && x & BIT[tri.e2] && x & BIT[tri.e3] )
  62.         {
  63.                 score--;
  64.         }
  65.     }
  66.     return score;
  67. }
  68. int MaxScore(int x)
  69. {
  70.     if (maxScore[x] > -1) return maxScore[x];
  71.     if (x == 262143) return maxScore[x] = 0;
  72.     int max = -1, m;
  73.     for (int i=0; i<18; i++)
  74.     {
  75.         if (x & BIT[i]) continue;
  76.         int rCode = x | BIT[i];
  77.         int score = StepScore(rCode, i);
  78.         if (score) m = score + MaxScore(rCode);
  79.         else
  80.         {
  81.             int rScore = RemainScore(x);
  82.             m = rScore - MaxScore(rCode);
  83.         }
  84.         max >?= m;
  85.     }
  86.     return maxScore[x] = max;
  87. }
  88. int main(int argc, char *argv[])
  89. {
  90.     int kase;
  91.     cin>>kase;
  92.     memset(maxScore, -1, sizeof(maxScore));
  93.     for (int i=0; i<kase; i++)
  94.     {
  95.         if (i>0) cout<<endl;
  96.         int games, gNum, moves, a, b;
  97.         cin>>games;
  98.         for (gNum=1; gNum<=games; gNum++)
  99.         {            
  100.             cin>>moves;
  101.             int code = 0, turn = 0;//A's turn.
  102.             int scoreOfA = 0;
  103.             for (int j=0; j<moves; j++)
  104.             {
  105.                 cin>>a>>b;
  106.                 int e = EDGENUM[a-1][b-1];
  107.                 code = code | BIT[e];
  108.                 int stepScore = StepScore(code, e);
  109.                 if (stepScore)
  110.                 {
  111.                    if (turn == 0) scoreOfA += stepScore;
  112.                 } else
  113.                 {
  114.                       turn = 1 - turn;
  115.                 }
  116.             }
  117.             if (turn == 0) scoreOfA += MaxScore(code);
  118.             else scoreOfA += RemainScore(code) - MaxScore(code);
  119.             cout<<"Game "<<gNum<<": ";
  120.             if (scoreOfA > 4) cout<<"A wins."<<endl;
  121.             else cout<<"B wins."<<endl;
  122.         }
  123.     }
  124. }
医疗影像技术实战:如何用Python快速生成DRR图像(附完整代码) 本文详细介绍了如何使用Python实现数字重建放射影像的快速生成。通过实战代码,从基础光线投射算法到性能优化,逐步讲解DRR图像生成的核心原理与工程实践,帮助开发者掌握医疗影像处理的关键技术,赋能放射治疗规划与图像引导手术等临床工具开发。 阅读详情

相关推荐

音视频从入门到精通——指数哥伦布码原理

在计算机中,一般数字的编码都为二进制,但是由于以相等长度来记录不同数字,因此会出现很多的。

mirana的专栏 1381

POJ 1085 Triangle War

Triangle WarTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 1465 Accepted: 582DescriptionTriangle War is a two-player game played on the following trian

bobten2008的专栏 2097

GPU八卡A100使用INT4-W4A16量化大模型实验

本实验旨在探索在环境下,对大语言模型进行权重量化的可行性、效率与性能影响。通过采用工具集成 GPTQ 算法,实现对所有线性层的权重量化(W4A16 方案最终通过lm-eval工具在GSM8K任务上对压缩模型进行评估。

goodgood_UP的博客 1908

1085:Triangle War

1085:Triangle War 已翻译, 有AC代码

guagua290290的博客 973

Python爬虫实战(基础篇)—23—爬取微信小程序<随机目的地旅行>生成随机地址(附GUI版)

爬取微信小程序<随机目的地旅行>生成随机地址

weixin_42636075的博客 1228

Cadence Sigrity PowerSI实战:从.brd到S参数提取的完整避坑指南

本文详细介绍了使用Cadence Sigrity PowerSI进行信号完整性分析的完整流程,从.brd文件预处理到S参数提取的关键技巧。通过实战案例和避坑指南,帮助工程师高效解决高速PCB设计中的信号质量问题,提升仿真精度和设计效率。

carrot的博客 694

pku1085 Triangle War 完全极大极小搜索+状压DP

黑书入门题,我们记录下每一个状态,状态为每条边是否用上,然后记忆化搜索所有状态 WA了一次,因为搜索的时候给状态的值的时候写成了一共的三角形数量而不是双方的最大差值 时间复杂度为2^18*8*17,而且每组数据都不需要额外更新,话说这样写时间复杂度是常数级别的诶2333333333 Problem: 1085 User: BPM136 Memory: 2724K Time: 188MS

BPM136 766

RK3588 C-PHY摄像头驱动升级踩坑记:从‘Only CSI2 supported’报错到成功取流

本文详细记录了在RK3588平台上调试C-PHY摄像头驱动的全过程,从‘Only CSI2 supported’报错分析到成功取流。内容涵盖C-PHY与CSI-2协议差异、SDK版本对比、V4L2框架下的bus-type解析机制,以及硬件排查与寄存器调优实战经验,为嵌入式Camera驱动工程师提供宝贵参考。

weixin_42522374的博客 123

Triangle War 1085

Triangle War Time Limit:1000MS Memory Limit:65536K Total Submissions:2508 Accepted:983 Description Triangle War is a two-player game played on the following triangular gr...

wqisen's workspace 221

电子元件及其规格书的查找与理解

本内容收录:在电子开发或维修过程中,查找电子元件及其规格书心得体会,以及元件规格书的理解,系个人多年实战经验的系统梳理。内容着重介绍贴片元件代码反查型号的实用技巧,并以三款典型疑难元件为例,详述其完整查找过程与最终型号确认。

让你爱上电路设计 3987

linux v3h平台开发系列详解(GMSL摄像头篇):1.12 解串器MAX96712输出4 lane 变 2 lane的配置

本文详细介绍了在Linux v3h平台上,针对Max96712解串器进行MIPI 4lane到2lane配置。内容包括串行器解串器介绍、链路框架、硬件连接、以及软件寄存器如何配值和一些问题的解决方法。

xian18809311584的博客 1092

zoj 1155 Triangle War

位运算

ZekiDai的博客 669

我的世界进阶模组开发教程——制作机械动力附属模组

摘要: Create是Minecraft的机械动力模组,其代码结构分为多个关键模块: 数据生成系统:通过CreateRecipeProvider基类实现配方自动化生成,支持多步骤序列化装配配方(SequencedAssemblyRecipeGen),采用建造者模式链式调用; 注册管理:CreateRegistrate扩展了Registrate库,统一管理方块、流体、实体等注册,集成标签页分类和工具提示定制; 伤害系统:DamageTypeTagGen为机械伤害(如钻头、风扇火焰)定义原版兼容的标签; 客户端

qq_24992377的博客 2083

poj 1085 Triangle War

人生第一道真正意义上的极大极小过程+alphabeta剪枝。 其实一开始让我写alphabeta剪枝我是拒绝的,于是我写了个记忆化搜索,TLE了。。。。。。。 哦然后优化了一下,300多MS A了 但是不爽啊 说好的博弈论呢 当然要用正解了 于是学了下alphabeta剪枝,其实挺简单的,就是alpha为已知max游戏者的下界,beta为min游戏者的上界,如果beta 假设在博弈树

月下沙茶树 793

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

[水题]ZOJ3038 Triangle War II

题意: 给了这样一张图 有两种状态:pushed(*)和unpushed(.) 为方便起见分别成为 开 和 关 改变一个点的开关状态 会同时改变与它相邻的点的开关状态 比如改变5,则2、3、4、6、8、9都会改变 N(行数)最多为6 即 最多21个点 求: 任意改变开关状态后 最多能有几个关着。 为什么这么像高斯消元!!! 每个点的状...

aicheng4794的博客 143

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Poj 1085 Triangle War (极大极小搜索)

题目链接:http://poj.org/problem?id=1085   题意:两个人轮流在九个小正三角形组成的大三角形上面选取边,如果当前选择的边刚好为某些三角形最后一个未选取的边,则该玩家得分为这些三解形数目,如果当前玩家取 得三角形,则可以得到另一个机会选择。

dooder_daodao的专栏 3491

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

ZOJ刷题题目分类

初学者题: 1001 1037 1048 1049 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 1334 1337 1338 1350 1365 1382 1383 1394 1402 1405 1414 1494 1514 1622 1715 1730 1755 1760 1763 1796 1813 1879 1889...

Veni的博客 2998

Triangle War

Triangle War 转载于:https://www.cnblogs.com/guxuanqing/p/9672048.html

weixin_30515513的博客 197

poj 1085 Triangle War (状压+记忆化搜索)

Triangle War Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2685   Accepted: 1061 Description Triangle War is a two-player game played on the following tria

To be what you what to be! 1635

zoj 1011NTA

//#include #include #define MAXN 15 #define MAXK 10#define MAXL 10using namespace std;int m, n, k;struct mypair{ int a, b; mypair *next;

yllfever的专栏 1557

zoj 1028 Flip and Shift

/**证明: 首先, 若n为奇数,则必然可以完成任务 将n个球遍号为1,2,...,n 若从1位置开始,进行 n-1次连续的 (flip, shift, shift), 则 除了球1外, 所有球的位置都 减了2, 而球1最后到达原来球n-1的位置。(见图, 可以知道, 相当于交换球1和2的位置)

yllfever的专栏 1445

计算 高次幂相对某个模数的余( (a ^ n)mod p, n 很大 )

在做google codejam 2008 round 1A problem C 的 时候, 从别人代码里学到的 假如 要计算 (a ^ n) , n很大, 直接计算的话, 是个 O(n)的方法有 O(log (n))的方法,如下:       把n表示成2进制, n = n0 * 1 + n1 * 2 + n2 * 4 + ... + nk * (2^k)则    a^n =[

yllfever的专栏 1334

POJ1097 Roads Scholar

#include #include #include #include using namespace std;const int MAXN = 30;const int MAXDIST = 100000000;int distanc[MAXN][MAXN];//从交点a到b的最短距离 int dist[MAXN][MAXN];//从

yllfever的专栏 1187

zoj 1038 T9 mobile input method

#include #include #include using namespace std;struct Key{ int num; char ch[4];};const Key keys[10] = { {}, {}, {3, {a, b,

yllfever的专栏 934

zoj 1166 Anagram Checker

/**A seach problem.**/#include  #include  #include  #include  #include  using namespace std;/**dictionary words**/string word[2000];/**Word in phrase**/string swo

yllfever的专栏 906

ZOJ 1102 Phylogenetic Trees Inherited (My algorithm , Time limit exeeded)

#include #include using namespace std;int n, l;string s[1025];int cnt[1025][26];string result;inline bool input(){    cin>>n>>l;    if ( !n && !l ) return false;    for

yllfever的专栏 869
上一篇: zoj1136 Code
下一篇: zoj1163 The Staircases 解法1 O(n^3)
yllfever
博客等级 码龄19年 4粉丝 44原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值