POJ 3207 Ikki's Story IV - Panda's Trick 【经典2-SAT】

探讨了POJ3207题目中,如何通过2-SAT算法判断在圆上的n个点间连接m条线,使线段在圆内外交替且不相交的问题。通过构建2-SAT图并进行可行性判断,实现了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


传送门:POJ 3207


Ikki's Story IV - Panda's Trick
Time Limit: 1000MS Memory Limit: 131072K

Problem Description
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”.

Sample Input
4 2
0 1
3 2

Sample Output
panda is telling the truth…



题意:
出一个圆上的 n 个点(0~n-1编号),然后在指定的 m 对点之间各连一条线(可以在圆内,也可以在圆外,可以是曲线),然后问你是否能使这些线都不相交。
在这里插入图片描述
题意有点难懂,看 oj 上的discuss上一个人的解释才看懂。


题解:
对于每一条边都有两个状态:连线在圆内和连线在圆外。再加上有m个边,可以看成是2-sat的模子。
那么题目的限制条件是线不相交,所以我们考虑圆上两线相交的条件。

假设有两条边i,j,第一条边两个端点为a1,b1,第二条边为a2,b2;
我们可以看成如果 a 1 &lt; a 2 且 b 1 &lt; b 2 且 b 1 &gt; a 2 a1&lt;a2且b1&lt;b2且b1&gt;a2 a1<a2b1<b2b1>a2 的话两条线在圆的同一侧是一定相交的。
那么我们对于这两条边就可以这样建2-sat的图:
先将m条边按 a a a 有小到大排序
i i i 表示第 i 条边连在圆内, i ′ i&#x27; i 表示第 j 条边连在圆外。
那么建边就应该是:
i i i - > j ′ j&#x27; j i ′ i&#x27; i - > j j j j j j - > i ′ i&#x27; i j ′ j&#x27; j - > i i i
( i i i - > j ′ j&#x27; j表示边 i 连在圆内,边 j 就得连在圆外。其他的同理)。

建完图后,我们只要用2-sat跑一下判断可行性就行。



AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N=1100;
int n,m,top;
bool mark[2*N];
int stack[2*N];
vector<int> g[2*N];
struct Node
{
  int a,b;
}edges[N];
bool cmp(Node x,Node y)
{
  return x.a<y.a;
}
void init()
{
  memset(mark,false,sizeof(mark));
  for(int i=0;i<2*N;i++)
  {
    g[i].clear();
  }
}
void addedge(int x,int idx,int y,int idy)
{
  x=2*x+idx;
  y=2*y+idy;
  g[x].push_back(y);
}
bool dfs(int x)
{
  if(mark[x^1]) return false;
  if(mark[x]) return true;
  mark[x]=true;
  stack[++top]=x;
  int len=g[x].size();
  for(int i=0;i<len;i++)
  {
    if(!dfs(g[x][i])) return false;
  }
  return true;
}
bool twosat()
{
  for(int i=0;i<2*n;i+=2)
  {
    if(!mark[i]&&!mark[i+1])
    {
      top=0;
      if(!dfs(i))
      {
        while(top>0)
          mark[stack[top--]]=false;
        if(!dfs(i+1)) return false;
      }
    }
  }
  return true;
}
int main()
{
  while(scanf("%d%d",&n,&m)!=EOF)
  {
    init();
    for(int i=0;i<m;i++)
    {
      scanf("%d%d",&edges[i].a,&edges[i].b);
      if(edges[i].a>edges[i].b)
      {
        int tmp=edges[i].a;
        edges[i].a=edges[i].b;
        edges[i].b=tmp;
      }
    }
    sort(edges,edges+m,cmp);
    for(int i=0;i<m;i++)
    {
      for(int j=i+1;j<m;j++)
      {
        if(edges[j].b>edges[i].b&&edges[i].b>edges[j].a)
        {
          addedge(i,0,j,1);
          addedge(i,1,j,0);
          addedge(j,0,i,1);
          addedge(j,1,i,0);
        }
      }
    }
    if(twosat()) printf("panda is telling the truth...\n");
    else printf("the evil panda is lying again\n");
  }
  return 0;
}

内容概要:该研究通过在黑龙江省某示范村进行24小时实地测试,比较了燃煤炉具与自动/手动进料生物质炉具的污染物排放特征。结果显示,生物质炉具相比燃煤炉具显著降低了PM2.5、CO和SO2的排放(自动进料分别降低41.2%、54.3%、40.0%;手动进料降低35.3%、22.1%、20.0%),但NOx排放未降低甚至有所增加。研究还发现,经济性和便利性是影响生物质炉具推广的重要因素。该研究不仅提供了实际排放数据支持,还通过Python代码详细复现了排放特征比较、减排效果计算和结果可视化,进一步探讨了燃料性质、动态排放特征、碳平衡计算以及政策建议。 适合人群:从事环境科学研究的学者、政府环保部门工作人员、能源政策制定者、关注农村能源转型的社会人士。 使用场景及目标:①评估生物质炉具在农村地区的推广潜力;②为政策制定者提供科学依据,优化补贴政策;③帮助研究人员深入了解生物质炉具的排放特征和技术改进方向;④为企业研发更高效的生物质炉具提供参考。 其他说明:该研究通过大量数据分析和模拟,揭示了生物质炉具在实际应用中的优点和挑战,特别是NOx排放增加的问题。研究还提出了多项具体的技术改进方向和政策建议,如优化进料方式、提高热效率、建设本地颗粒厂等,为生物质炉具的广泛推广提供了可行路径。此外,研究还开发了一个智能政策建议生成系统,可以根据不同地区的特征定制化生成政策建议,为农村能源转型提供了有力支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值