- /**
- DP
- 对状态编号, 18条边, 每条边可能实线, 也可能虚线, 有2^18种
- MaxScore(x) = max {
- StepScore(rCode, selectedEdgeNum) > 0
- ? StepScore + MaxScore(rCode) //选择的边成三角行
- : RemainScore(x) - MaxScore(rCode) //选择的边不成三角形
- }
- max 函数作用在所有虚线边上。
- **/
- #include <cstdlib>
- #include <iostream>
- using namespace std;
- int maxScore[262144]; //2^18
- //给18条边编号, 边的编号见附图
- const int EDGENUM[10][10] = {
- /*1, 2, 3, 4, 5, 6, 7, 8, 9 10 **/
- -1, 0, 1, -1, -1, -1, -1, -1, -1, -1, //1
- 0, -1, 2, 3, 4, -1, -1, -1, -1, -1, //2
- 1, 2, -1, -1, 5, 6, -1, -1, -1, -1, //3
- -1, 3, -1, -1, 7, -1, 9, 10, -1, -1, //4
- -1, 4 , 5, 7, -1, 8, -1, 11, 12, -1, //5
- -1, -1, 6, -1, 8, -1, -1, -1, 13, 14, //6
- -1, -1, -1, 9, -1, -1, -1, 15, -1, -1, //7
- -1, -1, -1, 10, 11, -1, 15, -1, 16, -1, //8
- -1, -1, -1, -1, 12, 13, -1, 16, -1, 17, //9
- -1, -1, -1, -1, -1, 14, -1, -1, 17, -1, //10
- };
- const int BIT[18] = { 1, 1<<1, 1<<2, 1<<3, 1<<4, 1<<5, 1<<6, 1<<7, 1<<8,
- 1<<9, 1<<10, 1<<11, 1<<12, 1<<13, 1<<14, 1<<15, 1<<16, 1<<17 };
- struct Triangle {
- int e1, e2, e3;//三条边的编号
- };
- //列举9个三角形
- const Triangle triangle[9] = {
- {0, 1, 2},
- {3, 4, 7}, {2, 4, 5}, {5, 6, 8},
- {9, 10, 15}, {7, 10, 11}, {11, 12, 16}, {8, 12, 13}, {13, 14, 17}
- };
- int StepScore(int x, int i)
- {
- int score = 0;
- for (int j=0; j<9; j++)
- {
- Triangle tri = triangle[j];
- if ( x & BIT[tri.e1] && x & BIT[tri.e2] && x & BIT[tri.e3] )
- {
- if (i == tri.e1 || i == tri.e2 || i == tri.e3)
- score++;
- }
- }
- return score;
- }
- int RemainScore(int x)
- {
- int score = 9;
- for (int j=0; j<9; j++)
- {
- Triangle tri = triangle[j];
- if ( x & BIT[tri.e1] && x & BIT[tri.e2] && x & BIT[tri.e3] )
- {
- score--;
- }
- }
- return score;
- }
- int MaxScore(int x)
- {
- if (maxScore[x] > -1) return maxScore[x];
- if (x == 262143) return maxScore[x] = 0;
- int max = -1, m;
- for (int i=0; i<18; i++)
- {
- if (x & BIT[i]) continue;
- int rCode = x | BIT[i];
- int score = StepScore(rCode, i);
- if (score) m = score + MaxScore(rCode);
- else
- {
- int rScore = RemainScore(x);
- m = rScore - MaxScore(rCode);
- }
- max >?= m;
- }
- return maxScore[x] = max;
- }
- int main(int argc, char *argv[])
- {
- int kase;
- cin>>kase;
- memset(maxScore, -1, sizeof(maxScore));
- for (int i=0; i<kase; i++)
- {
- if (i>0) cout<<endl;
- int games, gNum, moves, a, b;
- cin>>games;
- for (gNum=1; gNum<=games; gNum++)
- {
- cin>>moves;
- int code = 0, turn = 0;//A's turn.
- int scoreOfA = 0;
- for (int j=0; j<moves; j++)
- {
- cin>>a>>b;
- int e = EDGENUM[a-1][b-1];
- code = code | BIT[e];
- int stepScore = StepScore(code, e);
- if (stepScore)
- {
- if (turn == 0) scoreOfA += stepScore;
- } else
- {
- turn = 1 - turn;
- }
- }
- if (turn == 0) scoreOfA += MaxScore(code);
- else scoreOfA += RemainScore(code) - MaxScore(code);
- cout<<"Game "<<gNum<<": ";
- if (scoreOfA > 4) cout<<"A wins."<<endl;
- else cout<<"B wins."<<endl;
- }
- }
- }
相关推荐
STM32 SYSTICK定时器及延时函数详解
STM32 SYSTICK及延时函数详解 SysTick定时器 SysTick定时器被捆绑在NVIC中,用于产生SYSTICK异常(异常号:15)。在以前,大多操作系统需要一个硬件定时器来产生操作系统需要的滴答中断,作为整个系统的时基。例如,为多个任务许以不同数目的时间片,确保没有一个任务能霸占系统;或者把每个定时器周期的某个时间范围赐予特定的任务等,还有操作系统提供的各种定时功能,都与这个滴答定时器有关。因此,需要一个定时器来产生周期性的中断,而且最好还让用户程序不能随意访问它的寄存器,以维持操作系统“心
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
让Qt程序适配高分辨率屏幕,解决软件界面错乱异常
前期使用Qt开发一个登录模块一直使用很好。最近在一台新电脑上使用时发现排版混乱。这个问题很普遍,主要原因是旧软件对高清显示器的适配不当造成的。新电脑使用的是4K屏,win10系统自动进行了175%的缩放。
1085:Triangle War
1085:Triangle War 已翻译, 有AC代码
避坑指南:企业微信IP白名单设置失败的5种常见原因及解决方案
本文深入解析企业微信API调用中IP白名单设置失败的5种常见原因,包括动态公网IP变更、代理服务器导致的IP失真等,并提供针对性的解决方案。特别针对可信IP配置问题,详细介绍了诊断方法和Java代码示例,帮助企业开发者快速解决访问限制问题,确保API调用安全稳定。
用 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原则在指定包
pku1085 Triangle War 完全极大极小搜索+状压DP
黑书入门题,我们记录下每一个状态,状态为每条边是否用上,然后记忆化搜索所有状态 WA了一次,因为搜索的时候给状态的值的时候写成了一共的三角形数量而不是双方的最大差值 时间复杂度为2^18*8*17,而且每组数据都不需要额外更新,话说这样写时间复杂度是常数级别的诶2333333333 Problem: 1085 User: BPM136 Memory: 2724K Time: 188MS
【实战】Python 携程酒店价格实时抓取爬虫项目全解析
摘要:本文介绍了一个基于Python的携程酒店价格实时抓取系统开发方案。系统采用Requests、BeautifulSoup和Selenium等技术栈,实现了多城市、多日期的酒店数据采集,包括价格、评分、位置等关键信息。通过请求头伪装、IP代理、随机等待等反爬策略,有效应对携程的反爬机制。系统支持数据清洗、去重和CSV/Excel导出,并提供了多线程优化、代理池集成等进阶方案。本文详细阐述了技术原理、代码实现和优化策略,同时强调了数据采集的合法合规性,为旅游行业数据分析提供了可靠的数据获取方案。
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...
【2027最新版】PCL点云处理算法汇总(C++长期更新版)
PCL学习目录。博客长期更新,最近一次更新时间为:2026年11月29日。
低光照图像增强:从传统方法到深度学习
低光照图像增强:从传统方法到深度学习 人工智能,计算机视觉,大模型,AI,本文聚焦视觉模型的偏差与公平性问题,阐述了偏差在性别、种族、年龄等方面的表现及对医疗、司法、安防等领域的影响。分析了偏差源于数据采集与标注问题及算法局限。介绍了准确率差异等公平性评估指标、相关数据集和工具,还给出数据处理、算法改进、模型训练等避免歧视的策略,并附代码示例与实际案例,为提升视觉模型公平性提供多方面参考。
zoj 1155 Triangle War
位运算
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。完整方案实现了远程桌面环境的快速部署和用户集中管理。
poj 1085 Triangle War
人生第一道真正意义上的极大极小过程+alphabeta剪枝。 其实一开始让我写alphabeta剪枝我是拒绝的,于是我写了个记忆化搜索,TLE了。。。。。。。 哦然后优化了一下,300多MS A了 但是不爽啊 说好的博弈论呢 当然要用正解了 于是学了下alphabeta剪枝,其实挺简单的,就是alpha为已知max游戏者的下界,beta为min游戏者的上界,如果beta 假设在博弈树
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...
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个点 求: 任意改变开关状态后 最多能有几个关着。 为什么这么像高斯消元!!! 每个点的状...
Triangle War
Triangle War 转载于:https://www.cnblogs.com/guxuanqing/p/9672048.html
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
Poj 1085 Triangle War (极大极小搜索)
题目链接:http://poj.org/problem?id=1085 题意:两个人轮流在九个小正三角形组成的大三角形上面选取边,如果当前选择的边刚好为某些三角形最后一个未选取的边,则该玩家得分为这些三解形数目,如果当前玩家取 得三角形,则可以得到另一个机会选择。
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;
zoj 1028 Flip and Shift
/**证明: 首先, 若n为奇数,则必然可以完成任务 将n个球遍号为1,2,...,n 若从1位置开始,进行 n-1次连续的 (flip, shift, shift), 则 除了球1外, 所有球的位置都 减了2, 而球1最后到达原来球n-1的位置。(见图, 可以知道, 相当于交换球1和2的位置)
计算 高次幂相对某个模数的余( (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 =[
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];//从
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,
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
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
2377



被折叠的 条评论
为什么被折叠?



