POJ - 3207 Ikki's Story IV - Panda's Trick && BZOJ1997 [HNOI2010]Planar【2-SAT】

POJ - 3207 Ikki’s Story IV - Panda’s Trick

Time limit 1000 ms
Memory limit 131072 kB

liympanda, one of Ikki’s friend, likes playing games with Ikki. Today after minesweeping with Ikki and winning so many times, he is tired of such easy games and wants to play another game with Ikki.

liympanda has a magic circle and he puts it on a plane, there are n points on its boundary in circular border: 0, 1, 2, …, n − 1. Evil panda claims that he is connecting m pairs of points. To connect two points, liympanda either places the link entirely inside the circle or entirely outside the circle. Now liympanda tells Ikki no two links touch inside/outside the circle, except on the boundary. He wants Ikki to figure out whether this is possible…

Despaired at the minesweeping game just played, Ikki is totally at a loss, so he decides to write a program to help him.

Input

The input contains exactly one test case.

In the test case there will be a line consisting of of two integers: n and m (n ≤ 1,000, m ≤ 500). The following m lines each contain two integers ai and bi, which denote the endpoints of the ith wire. Every point will have at most one link.

Output

Output a line, either “panda is telling the truth…” or “the evil panda is lying again”.


题目大意

平面上有一个圆
圆的边界上顺时针分布着n个点
有m条线链接任意两个点,这些线可以在圆外或圆内,但不相交
保证每个点至多只连一条线,问是否合法


题目分析

对每条线用两个点分别表示在圆内(i)还是在圆外(i+m)
将m条线枚举两两组合
设当前枚举到的两条线为i和j
若他们同在圆内时会相交(可以证明此时如果同在圆外也会相交)
那么连边 a d d ( i , j + m ) , a d d ( i + m , j ) , a d d ( j , i + m ) , a d d ( j + m , i ) add(i,j+m),add(i+m,j),add(j,i+m),add(j+m,i) add(i,j+m),add(i+m,j),add(j,i+m),add(j+m,i)
表示如果其中一条在圆内(外),另一条必须在圆外(内)
之后2-SAT判断即可


#include<iostream>
#include<stack>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long lt;

int read()
{
    int f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}

const int maxn=2010;
int n,m,test;
struct node{int v,nxt;}E[2000010];
int head[maxn],tot;
struct node2{int x,y;}rem[maxn];
int low[maxn],dfn[maxn],cnt;
int col[maxn],ins[maxn],colnum;
int st[maxn],top;

void add(int u,int v)
{
	E[++tot].nxt=head[u];
	E[tot].v=v;
	head[u]=tot;
}

void tarjan(int u)
{
    low[u]=dfn[u]=++cnt;
    st[++top]=u; ins[u]=1;
    for(int i=head[u];i;i=E[i].nxt)
    {
        int v=E[i].v;
        if(!dfn[v]){ tarjan(v); low[u]=min(low[u],low[v]);}
        else if(ins[v]) low[u]=min(low[u],dfn[v]);
    }
    if(low[u]==dfn[u])
    {
        ++colnum;
        do{
            col[st[top]]=colnum;
            ins[st[top]]=0;
        }
        while(st[top--]!=u);
    }
} 

int judge(int a,int b,int c,int d)
{
	if(a<c&&c<b&&b<d)return 1;
	if(c<a&&a<d&&d<b)return 1;
	return 0;
}

int main()
{
	n=read();m=read();
	for(int i=1;i<=m;++i)
	{
		int x=read()+1,y=read()+1;
		if(x>y) swap(x,y);
		rem[i].x=x; rem[i].y=y;
		
		for(int j=1;j<i;++j)
		if(judge(x,y,rem[j].x,rem[j].y))
		add(i,j+m),add(i+m,j),add(j,i+m),add(j+m,i);
	}
	
	for(int i=1;i<=m<<1;++i)
	if(!dfn[i])tarjan(i);
	
	for(int i=1;i<=m;++i)
	if(col[i]==col[i+m]){test=1;break;}
	
	if(test)printf("the evil panda is lying again");
	else printf("panda is telling the truth...");
	return 0;
}


BZOJ1997 [HNOI2010]Planar

Time Limit: 10 Sec
Memory Limit: 64 MB

Description

在这里插入图片描述

Input在这里插入图片描述
题目分析

和上题几乎一样,就是饶了点弯子告诉你圆上点的顺时针顺序
以及还得知道 平面图一定满足 m ≤ 3 n − 6 m\leq 3n-6 m3n6这个结论,不然数据范围确实大的可怕了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
using namespace std;
typedef long long lt;

int read()
{
    int x=0,f=1;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return x*f;
}

const int maxn=50010;
int T,n,m;
struct edge{int u,v;}rem[maxn];
struct node{int v,nxt;}E[maxn<<3];
int head[maxn],tot;
int dfn[maxn],low[maxn],col[maxn],colnum;
int st[maxn],ins[maxn],top,cnt;
int pos[maxn];

void add(int u,int v)
{
    E[++tot].nxt=head[u];
    E[tot].v=v;
    head[u]=tot;
}

int check(int x,int y)
{
    int a=rem[x].u,b=rem[x].v;
    int c=rem[y].u,d=rem[y].v;
    if(a<c&&c<b&&b<d) return 1;
    if(c<a&&a<d&&d<b) return 1;
    return 0;
}

void tarjan(int u)
{
    dfn[u]=low[u]=++cnt;
    st[++top]=u; ins[u]=1;
    for(int i=head[u];i;i=E[i].nxt)
    {
        int v=E[i].v;
        if(!dfn[v]){ tarjan(v); low[u]=min(low[u],low[v]);}
        else if(ins[v]) low[u]=min(low[u],dfn[v]);
    }
    if(low[u]==dfn[u])
    {
        colnum++;
        do{
            col[st[top]]=colnum;
            ins[st[top]]=0;
        }while(st[top--]!=u);
    }
}

void init()
{
    cnt=tot=0;
    memset(head,0,sizeof(head));
    memset(dfn,0,sizeof(dfn));
    memset(low,0,sizeof(low));
    memset(col,0,sizeof(col));
}

int main()
{
    T=read();
    while(T--)
    {
        n=read();m=read(); init();
        for(int i=1;i<=m;++i)
        rem[i].u=read(),rem[i].v=read();
        
        for(int i=1;i<=n;++i) pos[read()]=i;
        if(m>3*n-6){ printf("NO\n"); continue;}
        
        for(int i=1;i<=m;++i)
        {
            rem[i].u=pos[rem[i].u]; rem[i].v=pos[rem[i].v];
            if(rem[i].u>rem[i].v) swap(rem[i].u,rem[i].v);
            
            for(int j=1;j<i;++j)
            if(check(i,j)) 
            add(i,j+m),add(j,i+m),add(i+m,j),add(j+m,i);
        }
        
        for(int i=1;i<=m<<1;++i)
        if(!dfn[i]) tarjan(i);
        
        int judge=0;
        for(int i=1;i<=m;++i)
        if(col[i]==col[i+m]){ judge=1; break;}
        
        if(judge) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园建设方案旨在通过融合先进技术,如物联网、大数据、人工智能等,实现校园的智能化管理与服务。政策的推动和技术的成熟为智慧校园的发展提供了基础。该方案强调了数据的重要性,提出通过数据的整合、开放和共享,构建产学研资用联动的服务体系,以促进校园的精细化治理。 智慧校园的核心建设任务包括数据标准体系和应用标准体系的建设,以及信息化安全与等级保护的实施。方案提出了一站式服务大厅和移动校园的概念,通过整合校内外资源,实现资源共享平台和产教融合就业平台的建设。此外,校园大脑的构建是实现智慧校园的关键,它涉及到数据中心化、数据资产化和数据业务化,以数据驱动业务自动化和智能化。 技术应用方面,方案提出了物联网平台、5G网络、人工智能平台等新技术的融合应用,以打造多场景融合的智慧校园大脑。这包括智慧教室、智慧实验室、智慧图书馆、智慧党建等多领域的智能化应用,旨在提升教学、科研、管理和服务的效率和质量。 在实施层面,智慧校园建设需要统筹规划和分步实施,确保项目的可行性和有效性。方案提出了主题梳理、场景梳理和数据梳理的方法,以及现有技术支持和项目分级的考虑,以指导智慧校园的建设。 最后,智慧校园建设的成功依赖于开放、协同和融合的组织建设。通过战略咨询、分步实施、生态建设和短板补充,可以构建符合学校特色的生态链,实现智慧校园的长远发展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值