POJ 3905 Perfect Election(简单2
POJ 3905 Perfect Election(简单2-SAT) http://poj.org/problem?id=3905 题意: 这里有1到N个人正在进行议员选举,每个人有2种结果,选上(0),未选上(1).现在的问题是,有M个选民的议员,结果必须符合这M条意愿,问你是否存在这种选举结果. 分析: 由于每条意愿都是
POJ 3905 Perfect Election(简单2-SAT)
http://poj.org/problem?id=3905
题意:
这里有1到N个人正在进行议员选举,每个人有2种结果,选上(0),未选上(1).现在的问题是,有M个选民的议员,结果必须符合这M条意愿,问你是否存在这种选举结果.
分析:
由于每条意愿都是或的关系.则直接用2-sat添加对应边即可.
简单2-SAT问题,注意把候选人序号改成0到N-1即可.
AC代码:
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> using namespace std; const int maxn = 1000+10; struct TwoSAT { int n; vector<int> G[maxn*2]; int S[maxn*2],c; bool mark[maxn*2]; bool dfs(int x) { if(mark[x^1]) return false; if(mark[x]) return true; mark[x]= true; S[c++]=x; for(int i=0;i<g if return false true void init n this->n=n; for(int i=0;i<n g memset void add_clause x xval y yval bool solve for i="0;i<2*n;i+=2)" if c="0;" while>0) mark[S[--c]]=false; if(!dfs(i+1)) return false; } } return true; } }TS; int main() { int n,m; while(scanf("%d%d",&n,&m)==2) { TS.init(n); for(int i=0;i<m int a scanf ts.add_clause printf return><br> <br> </m></n></g></int></vector></algorithm></cstring></cstdio>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The hard disk serial number is an important identifier of the hard disk and is usually used to uniquely identify the hard disk and identify the hardware. In some cases, we may need to query the hard drive serial number, such as when installing an operating system, finding the correct device driver, or performing hard drive repairs. This article will introduce some simple methods to help you check the hard drive serial number. Method 1: Use Windows Command Prompt to open the command prompt. In Windows system, press Win+R keys, enter "cmd" and press Enter key to open the command

How to write a simple online reservation system through PHP. With the popularity of the Internet and users' pursuit of convenience, online reservation systems are becoming more and more popular. Whether it is a restaurant, hospital, beauty salon or other service industry, a simple online reservation system can improve efficiency and provide users with a better service experience. This article will introduce how to use PHP to write a simple online reservation system and provide specific code examples. Create database and tables First, we need to create a database to store reservation information. In MyS

How to write a simple student performance report generator using Java? Student Performance Report Generator is a tool that helps teachers or educators quickly generate student performance reports. This article will introduce how to use Java to write a simple student performance report generator. First, we need to define the student object and student grade object. The student object contains basic information such as the student's name and student number, while the student score object contains information such as the student's subject scores and average grade. The following is the definition of a simple student object: public

Quick Start: Implementing a Simple Library Management System Using Go Language Functions Introduction: With the continuous development of the field of computer science, the needs of software applications are becoming more and more diverse. As a common management tool, the library management system has also become one of the necessary systems for many libraries, schools and enterprises. In this article, we will use Go language functions to implement a simple library management system. Through this example, readers can learn the basic usage of functions in Go language and how to build a practical program. 1. Design ideas: Let’s first

How to write a simple music recommendation system in C++? Introduction: Music recommendation system is a research hotspot in modern information technology. It can recommend songs to users based on their music preferences and behavioral habits. This article will introduce how to use C++ to write a simple music recommendation system. 1. Collect user data First, we need to collect user music preference data. Users' preferences for different types of music can be obtained through online surveys, questionnaires, etc. Save data in a text file or database

Introduction to how to use PHP to develop simple file management functions: File management functions are an essential part of many web applications. It allows users to upload, download, delete and display files, providing users with a convenient way to manage files. This article will introduce how to use PHP to develop a simple file management function and provide specific code examples. 1. Create a project First, we need to create a basic PHP project. Create the following file in the project directory: index.php: main page, used to display the upload table

A web crawler is an automated program that automatically visits websites and crawls information from them. This technology is becoming more and more common in today's Internet world and is widely used in data mining, search engines, social media analysis and other fields. If you want to learn how to write a simple web crawler using PHP, this article will provide you with basic guidance and advice. First, you need to understand some basic concepts and techniques. Crawling target Before writing a crawler, you need to select a crawling target. This can be a specific website, a specific web page, or the entire Internet

A simple calculator is a calculator that performs some basic operations, such as "+", "-", "*", "/". The calculator can perform basic operations quickly. We will use the switch statement to make a calculator. Example Operator−‘+’=>34+324=358Operator−‘-’=>3874-324=3550Operator−‘*’=>76*24=1824O
