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. }
【保姆级教程/代码】GNSS反演大气可降水量(Precipitable Water Vapor, PWV) GPS精密单点定位(PPP)是一种采用精密卫星星历和卫星钟差进行非差单点定位的方法,在观测过程中采用双频载波相位观测法以确保高精度定位精度。本文利用PPP技术来求解天顶对流层延迟(zenith tropospheric delay,ZTD)。ZTD由湿延迟(ZWD)和干延迟(ZHD)组成,其中占比90%的ZHD与地面测站高程、大气压和测站纬度等参数有良好的相关性,可以通过Saastamoinen模型精确求出; 阅读详情

相关推荐

STM32 SYSTICK定时器及延时函数详解

STM32 SYSTICK及延时函数详解 SysTick定时器 SysTick定时器被捆绑在NVIC中,用于产生SYSTICK异常(异常号:15)。在以前,大多操作系统需要一个硬件定时器来产生操作系统需要的滴答中断,作为整个系统的时基。例如,为多个任务许以不同数目的时间片,确保没有一个任务能霸占系统;或者把每个定时器周期的某个时间范围赐予特定的任务等,还有操作系统提供的各种定时功能,都与这个滴答定时器有关。因此,需要一个定时器来产生周期性的中断,而且最好还让用户程序不能随意访问它的寄存器,以维持操作系统“心

w1050321758的博客 2377

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的专栏 2101

让Qt程序适配高分辨率屏幕,解决软件界面错乱异常

前期使用Qt开发一个登录模块一直使用很好。最近在一台新电脑上使用时发现排版混乱。这个问题很普遍,主要原因是旧软件对高清显示器的适配不当造成的。新电脑使用的是4K屏,win10系统自动进行了175%的缩放。

cihron的博客 1万+

1085:Triangle War

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

guagua290290的博客 975

避坑指南:企业微信IP白名单设置失败的5种常见原因及解决方案

本文深入解析企业微信API调用中IP白名单设置失败的5种常见原因,包括动态公网IP变更、代理服务器导致的IP失真等,并提供针对性的解决方案。特别针对可信IP配置问题,详细介绍了诊断方法和Java代码示例,帮助企业开发者快速解决访问限制问题,确保API调用安全稳定。

weixin_29280657的博客 632

用 ADT 连接 SAP S/4HANA Public Cloud 开发租户的完整落地指南

摘要:在SAP S/4HANA公有云中进行ABAP开发时,必须使用Development Tenant(客户端080)而非Customizing Tenant(客户端100)连接ADT工具。开发用户需具备SAP_BR_DEVELOPER角色且写权限不受限,开发对象应创建在结构包的子包中。连接前需确认正确的ABAP服务URL(通常为Launchpad URL去掉"/ui"),并通过运行控制台程序验证全链路功能。典型开发场景如通过BAdI实现业务校验时,需遵循Clean Core原则在指定包

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 364

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

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

BPM136 769

【实战】Python 携程酒店价格实时抓取爬虫项目全解析

摘要:本文介绍了一个基于Python的携程酒店价格实时抓取系统开发方案。系统采用Requests、BeautifulSoup和Selenium等技术栈,实现了多城市、多日期的酒店数据采集,包括价格、评分、位置等关键信息。通过请求头伪装、IP代理、随机等待等反爬策略,有效应对携程的反爬机制。系统支持数据清洗、去重和CSV/Excel导出,并提供了多线程优化、代理池集成等进阶方案。本文详细阐述了技术原理、代码实现和优化策略,同时强调了数据采集的合法合规性,为旅游行业数据分析提供了可靠的数据获取方案。

2503_91057718的博客 2618

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

【2027最新版】PCL点云处理算法汇总(C++长期更新版)

PCL学习目录。博客长期更新,最近一次更新时间为:2026年11月29日。

点云侠的博客 63万+

低光照图像增强:从传统方法到深度学习

低光照图像增强:从传统方法到深度学习​ 人工智能,计算机视觉,大模型,AI,本文聚焦视觉模型的偏差与公平性问题,阐述了偏差在性别、种族、年龄等方面的表现及对医疗、司法、安防等领域的影响。分析了偏差源于数据采集与标注问题及算法局限。介绍了准确率差异等公平性评估指标、相关数据集和工具,还给出数据处理、算法改进、模型训练等避免歧视的策略,并附代码示例与实际案例,为提升视觉模型公平性提供多方面参考。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 2万+

zoj 1155 Triangle War

位运算

ZekiDai的博客 673

ubuntu 20.04 搭建多用户远程桌面共享及同时在线使用

摘要:本文介绍了在物理机上配置远程桌面访问的完整流程。通过setup_xrdp.sh脚本自动安装xrdp服务,修改配置文件并开放3389端口。同时提供了用户管理脚本:add_rdp_users.sh用于创建带sudo权限的远程用户,del_rdp_users.sh用于删除用户及主目录。还包含批量操作脚本add_rdp_all.sh和del_rdp_all.sh,支持一次性创建/删除多个用户(如dev1-dev5),所有用户密码统一设置为111111。完整方案实现了远程桌面环境的快速部署和用户集中管理。

631

poj 1085 Triangle War

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

月下沙茶树 800

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

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的博客 2999

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

[水题]ZOJ3038 Triangle War II

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

aicheng4794的博客 143

Triangle War

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

weixin_30515513的博客 198

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! 1636

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

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

dooder_daodao的专栏 3493

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的专栏 1560

zoj 1028 Flip and Shift

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

yllfever的专栏 1446

计算 高次幂相对某个模数的余( (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的专栏 1336

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的专栏 1188

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的专栏 937

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的专栏 907

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的专栏 870
上一篇: 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、付费专栏及课程。

余额充值
⌂ 换网址