- /**
- 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;
- }
- }
- }
相关推荐
音视频从入门到精通——指数哥伦布码原理
在计算机中,一般数字的编码都为二进制,但是由于以相等长度来记录不同数字,因此会出现很多的。
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
GPU八卡A100使用INT4-W4A16量化大模型实验
本实验旨在探索在环境下,对大语言模型进行权重量化的可行性、效率与性能影响。通过采用工具集成 GPTQ 算法,实现对所有线性层的权重量化(W4A16 方案最终通过lm-eval工具在GSM8K任务上对压缩模型进行评估。
1085:Triangle War
1085:Triangle War 已翻译, 有AC代码
Python爬虫实战(基础篇)—23—爬取微信小程序<随机目的地旅行>生成随机地址(附GUI版)
爬取微信小程序<随机目的地旅行>生成随机地址
Cadence Sigrity PowerSI实战:从.brd到S参数提取的完整避坑指南
本文详细介绍了使用Cadence Sigrity PowerSI进行信号完整性分析的完整流程,从.brd文件预处理到S参数提取的关键技巧。通过实战案例和避坑指南,帮助工程师高效解决高速PCB设计中的信号质量问题,提升仿真精度和设计效率。
pku1085 Triangle War 完全极大极小搜索+状压DP
黑书入门题,我们记录下每一个状态,状态为每条边是否用上,然后记忆化搜索所有状态 WA了一次,因为搜索的时候给状态的值的时候写成了一共的三角形数量而不是双方的最大差值 时间复杂度为2^18*8*17,而且每组数据都不需要额外更新,话说这样写时间复杂度是常数级别的诶2333333333 Problem: 1085 User: BPM136 Memory: 2724K Time: 188MS
RK3588 C-PHY摄像头驱动升级踩坑记:从‘Only CSI2 supported’报错到成功取流
本文详细记录了在RK3588平台上调试C-PHY摄像头驱动的全过程,从‘Only CSI2 supported’报错分析到成功取流。内容涵盖C-PHY与CSI-2协议差异、SDK版本对比、V4L2框架下的bus-type解析机制,以及硬件排查与寄存器调优实战经验,为嵌入式Camera驱动工程师提供宝贵参考。
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...
电子元件及其规格书的查找与理解
本内容收录:在电子开发或维修过程中,查找电子元件及其规格书心得体会,以及元件规格书的理解,系个人多年实战经验的系统梳理。内容着重介绍贴片元件代码反查型号的实用技巧,并以三款典型疑难元件为例,详述其完整查找过程与最终型号确认。
linux v3h平台开发系列详解(GMSL摄像头篇):1.12 解串器MAX96712输出4 lane 变 2 lane的配置
本文详细介绍了在Linux v3h平台上,针对Max96712解串器进行MIPI 4lane到2lane配置。内容包括串行器解串器介绍、链路框架、硬件连接、以及软件寄存器如何配值和一些问题的解决方法。
zoj 1155 Triangle War
位运算
我的世界进阶模组开发教程——制作机械动力附属模组
摘要: Create是Minecraft的机械动力模组,其代码结构分为多个关键模块: 数据生成系统:通过CreateRecipeProvider基类实现配方自动化生成,支持多步骤序列化装配配方(SequencedAssemblyRecipeGen),采用建造者模式链式调用; 注册管理:CreateRegistrate扩展了Registrate库,统一管理方块、流体、实体等注册,集成标签页分类和工具提示定制; 伤害系统:DamageTypeTagGen为机械伤害(如钻头、风扇火焰)定义原版兼容的标签; 客户端
poj 1085 Triangle War
人生第一道真正意义上的极大极小过程+alphabeta剪枝。 其实一开始让我写alphabeta剪枝我是拒绝的,于是我写了个记忆化搜索,TLE了。。。。。。。 哦然后优化了一下,300多MS A了 但是不爽啊 说好的博弈论呢 当然要用正解了 于是学了下alphabeta剪枝,其实挺简单的,就是alpha为已知max游戏者的下界,beta为min游戏者的上界,如果beta 假设在博弈树
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个点 求: 任意改变开关状态后 最多能有几个关着。 为什么这么像高斯消元!!! 每个点的状...
ssm框架搭建
这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载
Poj 1085 Triangle War (极大极小搜索)
题目链接:http://poj.org/problem?id=1085 题意:两个人轮流在九个小正三角形组成的大三角形上面选取边,如果当前选择的边刚好为某些三角形最后一个未选取的边,则该玩家得分为这些三解形数目,如果当前玩家取 得三角形,则可以得到另一个机会选择。
复分析 阿尔福斯(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...
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
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
1381



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



