Compromise

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 155    Accepted Submission(s): 47

Problem Description
Xiaoqiang and Amoeba (AMB for short) are good friends. Friends as they are, they are inevitably self-centered beings. So their life together is full of concession and compromise. To further promote their ongoing relationship, Xiaoqiang
studies his interaction with AMB from a game theoretical perspective. He views his everyday life with AMB as a game.



The game has N "nodes" corresponding to different "states" of life. Each node has several outgoing "edges" representing "actions". A node either belongs to Xiaoqiang or AMB. The nodes and edges form a connected DAG (Directed Acyclic Graph, a graph without cycles).
Each node without outgoing edges has two "utility" values for Xiaoqiang and AMB respectively.



For example, consider the following game:

● Node S: The day begins. AMB has two actions leading to A and B respectively.

● Node A: AMB goes to University P. Xiaoqiang has two actions leading to C and D respectively.

● Node B: AMB goes to University T. Xiaoqiang has two actions leading to D and E respectively.

● Node C: Xiaoqiang and AMB both go to University P. AMB's utility is 102, Xiaoqiang's utility is 99.

● Node D: Xiaoqiang and AMB go to different universities. AMB's utility is 51, Xiaoqiang's utility is 0.

● Node E: Xiaoqiang and AMB both go to University T. AMB's utility is 100, Xiaoqiang's utility is 101.



Life starts from Node S. At each node, either Xiaoqiang or AMB can take an action. Xiaoqiang's aim is to maximize his own utility (and cares nothing about AMB) and AMB's aim is also to maximize his own utility.



AMB thinks, if he goes to node A then Xiaoqiang's best response will be going to node C and he can happily live in University P with Xiaoqiang. In this case AMB's utility is 102 and Xiaoqiang's is 99. Xiaoqiang is not satisfied with this, but it seems there
is nothing Xiaoqiang can do about this. This is the so called Nash Equilibrium.



Until one day Xiaoqiang claims (or, to be exact, swears): "Listen, I was attacked by a paramecium and I became insane. If I am in Node B, I will surely go to Node E. But if I am in Node A, I will go to Node D without hesitation." In this way, he reveals his
whole strategy to AMB, which encodes for each node what Xiaoqiang will do if he arrives at the node. Notice that in this strategy Xiaoqiang's action (going to University T) at a node does not depend on which path is used to arrive at the node. This strategy
is not rational, because at Node A Xiaoqiang's best action should be going to Node C.



But Xiaoqiang makes his claim in such a convincing voice that AMB believes that Xiaoqiang will follow this strategy at all cost however irrational it is. Then AMB finds out that his best strategy will be going to node B, and they will end up at Node E. In this
case, Xiaoqiang's utility is 101. Notice that Xiaoqiang must keep his words after the claim. That is, after the claim Xiaoqiang's strategy is fixed, and AMB will make decisions to maximize his own utility provided Xiaoqiang's strategy.



Given a game, you are to determine:

(1) Xiaoqiang's best utility if he cannot make the claim.

(2) Xiaoqiagn's best utility if he can make the claim.

To make things simple, all utility values are distinct.



Remark: The real world situation is, Xiaoqiang and AMB are currently in Node D because AMB failed to get himself to University T through the entrance exam.
 
Input
The first line contains an integer T, denoting the number of the test cases.



Each test case begins with one integer N, the number of nodes. 1<=N<=200. Life starts from the first node.



Then follows N lines. Each line begins with an integer M indicating the number of actions. 0<=M<N



If M is nonzero, M integers follow. Each integer (in range [1, N]) represents the destination of an outgoing edge. At the end of the line is a character being either 'A' or 'X' describing whether this node belongs to AMB or Xiaoqiang.



If M is zero, two integers follow representing AMB's utility and Xiaoqiang's utility respectively. Utility values are in range [0, 10000] and are distinct.
 
Output
For each test case, output one line containing two integers representing the answers separated by a space.
 
Sample Input
1
6
2 5 6 A
0 102 99
0 50 0
0 100 101
2 2 3 X
2 3 4 X
 
Sample Output
99 101
 
Source
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5061 

pid=5060" target="_blank">5060 5059 5058 5057 

 

解法:

第一问:直接从后向前Dp

第二问:

因为2人目标不同。我们仅仅考虑某个节点V是否能走到。

退一步,考虑calm X是否能让A走到V或比V更糟的节点

假设办不到。A一定能去比V更优的节点。V走不到

否则,考虑是否能在该策略走到V. //有可能仅仅存在到比V更糟的路径

定义一个节点avi,当且仅当该节点能让A走到V或比V更糟的节点

那么若存在一条1->V的路径皆为avi就可以

此时X会向V决策,A因为不能去比V更优的节点,也向V决策

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (200+10)
#define MAXM (200*200+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int T,n;
int edge[MAXM],next[MAXM],pre[MAXN],size=0;
void addedge(int u,int v)
{
edge[++size]=v;
next[size]=pre[u];
pre[u]=size;
}
int dp[MAXN][2],who[MAXN];
void max(int &max1,int &max2,int max3)
{
if (max3>=max1) max2=max1,max1=max3;
else if (max3>=max2) max2=max3;
}
bool b[MAXN]; void dfs1(int i)
{
if (who[i]==2||b[i]) return;
b[i]=1;
Forp(i)
{
int v=edge[p];
dfs1(v);
if (dp[i][0]<0||(dp[i][who[i]]<dp[v][who[i]])) memcpy(dp[i],dp[v],sizeof(int)*2);
}
}
bool avi[MAXN];
void dfs_avi(int i,int value)
{
if (b[i]) return;
b[i]=1;
if (who[i]==2)
{
avi[i]=(bool)(dp[i][0]<=value);
return;
} avi[i]=!who[i];
Forp(i)
{
int v=edge[p];
dfs_avi(v,value);
if (!who[i]) avi[i]&=avi[v];
else avi[i]|=avi[v];
}
}
bool dfs_path(int i,int value)
{
if (b[i]) return 0;
b[i]=1;
if (who[i]==2)
{
return (dp[i][0]==value);
}
Forp(i)
{
int v=edge[p];
if (avi[v]) if (dfs_path(v,value)) return 1; } return 0; } int main()
{
// freopen("hdu5005.in","r",stdin);
// freopen(".out","w",stdout);
cin>>T;
while(T--)
{
MEM(pre) size=0;
MEMi(dp) MEM(who)
cin>>n;
For(i,n)
{
int m;
scanf("%d",&m);
if (m)
{
For(j,m) {int v;scanf("%d",&v);addedge(i,v);}
char s[2];
scanf("%s",s); if (s[0]=='A') who[i]=0;else who[i]=1;
}
else
{
who[i]=2;
scanf("%d%d",&dp[i][0],&dp[i][1]);
}
}
MEM(b) dfs1(1); int ans2=-1;
For(i,n) if(who[i]==2)
{
if (ans2<dp[i][1])
{
MEM(avi) MEM(b)
dfs_avi(1,dp[i][0]);
if (avi[1])
{
MEM(b)
if (dfs_path(1,dp[i][0])) ans2=dp[i][1];
}
}
} printf("%d %d\n",dp[1][1],ans2); } return 0;
}

HDU 5005(Compromise-双人目标为最大化不同值的博弈)的更多相关文章

  1. geotrellis使用(二十二)实时获取点状目标对应的栅格数据值

    目录 前言 实现方法 总结 一.前言        其实这个功能之前已经实现,今天将其采用1.0版的方式进行了重构与完善,现将该内容进行总结.        其实这个功能很常见,比如google地球上 ...

  2. HDU.2516 取石子游戏 (博弈论 斐波那契博弈)

    HDU.2516 取石子游戏 (博弈论 斐波那契博弈) 题意分析 简单的斐波那契博弈 博弈论快速入门 代码总览 #include <bits/stdc++.h> #define nmax ...

  3. HDU 1242 dFS 找目标最短路

    //多个起点,要最短得目标,不妨倒过来从目标出发,去找最近的点更新!!!!!!递归时思路要清楚 #include<iostream> #include<cstring> usi ...

  4. 目标跟踪之meanshift---均值漂移搞起2000过时的

    基于灰度均值分布的目标跟踪! http://blog.csdn.net/wds555/article/details/24499599 但他有些有点: 1.不会受遮挡太多影响 Mean Shift跟踪 ...

  5. HDU 1863:畅通project(带权值的并查集)

    畅通project Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. hdu 1847 Good Luck in CET-4 Everybody!(巴什博弈)

    Good Luck in CET-4 Everybody! HDU - 1847 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都没工夫练习了,反正我知道的Kiki和Ci ...

  7. HDU 5289 Assignment (ST算法区间最值+二分)

    题目链接:pid=5289">http://acm.hdu.edu.cn/showproblem.php?pid=5289 题面: Assignment Time Limit: 400 ...

  8. HDU 1848 Fibonacci again and again (斐波那契博弈SG函数)

    Fibonacci again and again Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & ...

  9. HDU 2516 取石子游戏(斐波那契博弈)

    取石子游戏 Time Limit: 2000/1000 MS(Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...

随机推荐

  1. JVM堆内存的分代

    虚拟机的堆内存共划分为三个代:年轻代(Young Generation).年老代(Old Generation)和持久代(PermanentGeneration).其中持久代主要存放的是Java类的类 ...

  2. mysql 存储过程案列一个。

    -- 设置分隔符 DELIMITER // /*初始化*/ DROP PROCEDURE IF EXISTS useCursor // /*建立 存储过程 create */ CREATE PROCE ...

  3. mysql 监控工具

    zabbix和grafana是绝配.  pmm的prometheus太占资源了

  4. 软件版本GA,RC,alpha,beta,Build 含义

    (1)RC:(Release Candidate) Candidate是候选人的意思,用在软件上就是候选版本.Release.Candidate.就是发行候选版本.和Beta版最大的差别在于Beta阶 ...

  5. 介紹 IIS 8 全新的 HttpPlatformHandler 模組與 ASP.NET 5 Beta8 重大變更

    HttpPlatformHandler 是一個支援 IIS 8 與 IIS 8.5 的原生模組 (native module),主要使用於 Microsoft Azure Websites 網站服務中 ...

  6. pytest文档3-pycharm运行pytest

    前言 上一篇pytest文档2-用例运行规则已经介绍了如何在cmd执行pytest用例,平常我们写代码在pycharm比较多 写完用例之后,需要调试看看,是不是能正常运行,如果每次跑去cmd执行,太麻 ...

  7. Openshift 3.11和LDAP的集成

    1. OpenLDAP的安装 只记录主要步骤,详细可参考 https://access.redhat.com/solutions/2484371 # yum install -y openldap o ...

  8. Pydoc 本地 HTML 形式查看

    Pydoc 本地 HTML 形式查看 我们在编写Python代码时,常常会去查询某些模块及函数的使用,会选择 dir() 及 help() 函数.或查看 CHM 格式的Python帮助文档.或查看Py ...

  9. ASP.NET 5 的Roadmap(转)

    这次随 Visual Studio 2015 发布的 ASP.NET 版本是 ASP.NET 4.6 与 ASP.NET 5 beta5.在 VS2015 发布的同时,微软也发布了 ASP.NET 5 ...

  10. CSS_LESS 语法/函数详解

    嵌套规则 01 #header { color: black; }#header .navigation {  font-size: 12px; 02 }#header .logo {  03   w ...