hdu 4115 Eliminate the Conflict

Eliminate the Conflict

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1118    Accepted Submission(s): 472


Problem Description
Conflicts are everywhere in the world, from the young to the elderly, from families to countries. Conflicts cause quarrels, fights or even wars. How wonderful the world will be if all conflicts can be eliminated.
Edward contributes his lifetime to invent a 'Conflict Resolution Terminal' and he has finally succeeded. This magic item has the ability to eliminate all the conflicts. It works like this:
If any two people have conflict, they should simply put their hands into the 'Conflict Resolution Terminal' (which is simply a plastic tube). Then they play 'Rock, Paper and Scissors' in it. After they have decided what they will play, the tube should be opened and no one will have the chance to change. Finally, the winner have the right to rule and the loser should obey it. Conflict Eliminated!
But the game is not that fair, because people may be following some patterns when they play, and if the pattern is founded by others, the others will win definitely.
Alice and Bob always have conflicts with each other so they use the 'Conflict Resolution Terminal' a lot. Sadly for Bob, Alice found his pattern and can predict how Bob plays precisely. She is very kind that doesn't want to take advantage of that. So she tells Bob about it and they come up with a new way of eliminate the conflict:
They will play the 'Rock, Paper and Scissors' for N round. Bob will set up some restricts on Alice.
But the restrict can only be in the form of "you must play the same (or different) on the ith and jth rounds". If Alice loses in any round or break any of the rules she loses, otherwise she wins.
Will Alice have a chance to win?
 

Input
The first line contains an integer T(1 <= T <= 50), indicating the number of test cases.
Each test case contains several lines.
The first line contains two integers N,M(1 <= N <= 10000, 1 <= M <= 10000), representing how many round they will play and how many restricts are there for Alice.
The next line contains N integers B 1,B 2, ...,B N, where B i represents what item Bob will play in the i th round. 1 represents Rock, 2 represents Paper, 3 represents Scissors.
The following M lines each contains three integers A,B,K(1 <= A,B <= N,K = 0 or 1) represent a restrict for Alice. If K equals 0, Alice must play the same on A th and B th round. If K equals 1, she must play different items on Ath and Bthround.
 

Output
For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is "yes" or "no" represents whether Alice has a chance to win.
 

Sample Input
  
  
2 3 3 1 1 1 1 2 1 1 3 1 2 3 1 5 5 1 2 3 2 1 1 2 1 1 3 1 1 4 1 1 5 1 2 3 0
 

Sample Output
  
  
Case #1: no Case #2: yes
Hint
'Rock, Paper and Scissors' is a game which played by two person. They should play Rock, Paper or Scissors by their hands at the same time. Rock defeats scissors, scissors defeats paper and paper defeats rock. If two people play the same item, the game is tied..
 
 
题意:Bob和Alice玩剪刀石头布的游戏,游戏有n个回合。Alice事先已经知道Bob分别在这n个回合里会出什么。游戏有m个约束条件A B K,若K=0,则Alice在回合A和回合B出的必须是相同的,若K=1,则Alice在回合A和回合B出的必须是不相同的。规定若Alice违反任何一个约束条件或者Alice在任何一个回合输了,则Alice在整个游戏输了。给出上述情况,问Alice是否有机会赢。
思路:要使Alice有机会赢,则要保证Alice不违反任何一个约束条件,而且任何一个回合,要么Alice赢,要么平手,这样对于每一个回合,Alice都有两个选择,符合2-sat问题。可以先根据Bob每个回合出什么,记录Alice在每个回合的两种选择。然后还要根据约束条件找矛盾的关系,构图。
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <cstdlib>
#define L(rt) (rt<<1)
#define R(rt) (rt<<1|1)
#define ll long long
#define eps 1e-6
using namespace std;

const int maxn=20005;
struct node
{
    int v,next;
}edge[maxn*20];
int head[maxn],scc[maxn],stack[maxn];
int low[maxn],dfn[maxn],alice[maxn];
bool ins[maxn];
int n,m,num,cnt,top,snum;
void init()
{
    memset(head,-1,sizeof(head));
    num=0;
}
void add(int u,int v)
{
    edge[num].v=v;
    edge[num].next=head[u];
    head[u]=num++;
}
void input()
{
    int bob,a,b,k;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&bob);
        if(bob==1||bob==2)
        {
            alice[i]=bob;
            alice[i+n]=bob+1;
        }
        else
        {
            alice[i]=3;
            alice[i+n]=1;
        }
    }
    while(m--)
    {
        scanf("%d%d%d",&a,&b,&k);
        if(k==0)
        {
            if(alice[a]!=alice[b])
            {
                add(a,b+n);
                add(b,a+n);
            }
            if(alice[a]!=alice[b+n])
            {
                add(a,b);
                add(b+n,a+n);
            }
            if(alice[a+n]!=alice[b])
            {
                add(a+n,b+n);
                add(b,a);
            }
            if(alice[a+n]!=alice[b+n])
            {
                add(a+n,b);
                add(b+n,a);
            }
        }
        else
        {
            if(alice[a]==alice[b])
            {
                add(a,b+n);
                add(b,a+n);
            }
            if(alice[a]==alice[b+n])
            {
                add(a,b);
                add(b+n,a+n);
            }
            if(alice[a+n]==alice[b])
            {
                add(a+n,b+n);
                add(b,a);
            }
            if(alice[a+n]==alice[b+n])
            {
                add(a+n,b);
                add(b+n,a);
            }
        }
    }
}
void dfs(int u)
{
    int x;
    dfn[u]=low[u]=++cnt;
    stack[top++]=u;
    ins[u]=true;
    for(int i=head[u];i!=-1;i=edge[i].next)
    {
        int v=edge[i].v;
        if(!dfn[v])
        {
            dfs(v);
            low[u]=min(low[u],low[v]);
        }
        else if(ins[v]) low[u]=min(low[u],dfn[v]);
    }
    if(low[u]==dfn[u])
    {
        snum++;
        do{
            x=stack[--top];
            ins[x]=false;
            scc[x]=snum;
        }while(x!=u);
    }
}
void tarjan()
{
    memset(dfn,0,sizeof(dfn));
    memset(ins,false,sizeof(ins));
    cnt=top=snum=0;
    for(int i=1;i<=2*n;i++)
    if(!dfn[i]) dfs(i);
}
void solve()
{
    for(int i=1;i<=n;i++)
    if(scc[i]==scc[i+n])
    {
        printf("no\n");
        return;
    }
    printf("yes\n");
}
int main()
{
    int t,c=0;
    scanf("%d",&t);
    while(t--)
    {
       init();
       input();
       tarjan();
       printf("Case #%d: ",++c);
       solve();
    }
    return 0;
}


内容概要:本文详细探讨了双馈风力发电机(DFIG)在Simulink环境下的建模方法及其在不同风速条件下的电流与电压波形特征。首先介绍了DFIG的基本原理,即定子直接接入电网,转子通过双向变流器连接电网的特点。接着阐述了Simulink模型的具体搭建步骤,包括风力机模型、传动系统模型、DFIG本体模型和变流器模型的建立。文中强调了变流器控制算法的重要性,特别是在应对风速变化时,通过实时调整转子侧的电压和电流,确保电流和电压波形的良好特性。此外,文章还讨论了模型中的关键技术和挑战,如转子电流环控制策略、低电压穿越性能、直流母线电压脉动等问题,并提供了具体的解决方案和技术细节。最终,通过对故障工况的仿真测试,验证了所建模型的有效性和优越性。 适用人群:从事风力发电研究的技术人员、高校相关专业师生、对电力电子控制系统感兴趣的工程技术人员。 使用场景及目标:适用于希望深入了解DFIG工作原理、掌握Simulink建模技能的研究人员;旨在帮助读者理解DFIG在不同风速条件下的动态响应机制,为优化风力发电系统的控制策略提供理论依据和技术支持。 其他说明:文章不仅提供了详细的理论解释,还附有大量Matlab/Simulink代码片段,便于读者进行实践操作。同时,针对一些常见问题给出了实用的调试技巧,有助于提高仿真的准确性和可靠性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值