Home Database Mysql Tutorial POJ 3683 Priest John's Busiest Day(2

POJ 3683 Priest John's Busiest Day(2

Jun 07, 2016 pm 03:48 PM
amp b

POJ 3683 Priest John's Busiest Day(2-SAT输出方案) http://poj.org/problem?id=3683 题意: 有N对新人举行婚,且每次婚需要持续d时间,从s时间到t时间之间举行且只能选择s到sd时间或t-d到t时间这两个完整的时间段举行.现在只有一个神父,问他有没有可能参加所

POJ 3683 Priest John's Busiest Day(2-SAT输出方案)

http://poj.org/problem?id=3683

题意:

        有N对新人举行婚礼,且每次婚礼需要持续d时间,从s时间到t时间之间举行且只能选择s到s+d时间或t-d到t时间这两个完整的时间段举行.现在只有一个神父,问他有没有可能参加所有新人的婚礼(待完整段时间且任意两对新人的婚礼时间不重叠)? 输出一个可行的方案.

分析:

        每对新人的婚礼时间只有两种选择,直接就可以转化为2-SAT问题.其中如果对于第i个婚礼与第j个婚礼来说:

        假设i先办的时间区间为[a,b]而j后办的时间区间为[c,d],如何判断[a,b]与[c,d]是否发生了冲突呢?(边界相交不算).

        只有下面两种情况下区间[s1,e1]与区间[s2,e2]才规范相交.

        1. s1

        2. s2

        仔细一看上面两种情况是相同的,只要相交的两个区间的e1 e2 > s1 s2 即可保证这两个区间相交.

        (仔细想想上面情况)

        然后对于冲突的每对新人添加边即可.

AC代码:

#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int maxn=1000+10;
struct Time
{
    int s,e,d;//开始,结束,持续
    Time(){}
    Time(int s,int e,int d):s(s),e(e),d(d){}
}t[maxn];
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(!mark[i]" c="0;" if while>0) mark[S[--c]]=false;
                if(!dfs(i+1)) return false;
            }
        }
        return true;
    }
}TS;
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n int sh scanf t ts.init for i="0;i<n;i++)" j="i+1;j<n;j++)" if ts.add_clause printf else return><br>
<br>


</n></n></g></int></vector></cstring></cstdio>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to install Windows 11 on ASUS b450 motherboard How to install Windows 11 on ASUS b450 motherboard Dec 31, 2023 am 10:10 AM

ASUS b450 is a very excellent motherboard with many users. If you want to install the win11 system on this motherboard, you need to enable tpm2.0 and the secure boot option. Many friends may not know how to enable it. The editor below will Let’s take a look at how to operate it. How to install win11 on ASUS b450: 1. First, we restart the system, use "F2" to enter the bios settings, and then click "Advanced Mode" in the lower right corner to enter. 2. Then enter "Secure Boot" under the "Startup" option 3. Then select "Windows UEFI Mode" to the right of "Operating System Type" 4. After the settings are completed, click "search" in the upper right corner to enter the search. 5. Then search for “PTT” and click

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

What coin is AMP? What coin is AMP? Feb 24, 2024 pm 09:16 PM

What is AMP Coin? The AMP token was created by the Synereo team in 2015 as the main trading currency of the Synereo platform. AMP token aims to provide users with a better digital economic experience through multiple functions and uses. Purpose of AMP Token The AMP Token has multiple roles and functions in the Synereo platform. First, as part of the platform’s cryptocurrency reward system, users are able to earn AMP rewards by sharing and promoting content, a mechanism that encourages users to participate more actively in the platform’s activities. AMP tokens can also be used to promote and distribute content on the Synereo platform. Users can increase the visibility of their content on the platform by using AMP tokens to attract more viewers to view and share

Download link of the virtual currency website mobile version APP (the top ten recommended in the world) Download link of the virtual currency website mobile version APP (the top ten recommended in the world) Mar 04, 2025 pm 03:48 PM

This article compares and reviews nine mainstream cryptocurrency exchanges in OKX, Binance, Gate.io, Huobi, Kraken, Coinbase, KuCoin, Crypto.com and Bitstamp. The article conducts detailed analysis and comparison of each exchange from multiple dimensions such as technical advantages, security system, product innovation, global layout, compliance progress, fees, user experience, ecosystem, market position, etc., aiming to help users choose the platform that best suits their needs. OKX is famous for its distributed architecture and derivative trading; Binance occupies a leading position with the world's largest trading volume and rich ecosystem; Gate.io focuses on wide currency coverage and low rates; Huobi focuses on localized services and technical strength;

Top 10 virtual cryptocurrency app trading platforms in 2025 Top 10 virtual cryptocurrency app trading platforms in 2025 Mar 07, 2025 pm 06:39 PM

The top ten virtual cryptocurrency App trading platforms in 2025 are: 1. OKX; 2. Binance; 3. Gate.io; 4. Kraken; 5. Coinbase; 6. Huobi; 7. KuCoin; 8. Crypto.com; 9. Bitfinex; 10. Gemini. When choosing a platform, you need to consider: 1. Security; 2. Transaction fees; 3. Trading products; 4. User experience; 5. Customer service support.

How many times has Bitcoin experienced a plunge in history? Where to trade? How many times has Bitcoin experienced a plunge in history? Where to trade? Mar 12, 2025 pm 07:06 PM

Bitcoin price has experienced many violent fluctuations in history, and multiple plunges have caused heavy losses to investors. This article will review the many major plunges of Bitcoin since 2011, including the 85% drop caused by hackers in 2011, the plunge caused by the Mt.Gox incident in 2013 and 2014, as well as the multiple sharp drops caused by factors such as the epidemic period from 2017 to 2018, 2020, China's cryptocurrency ban and the Federal Reserve's interest rate hike, as well as the 66% drop caused by the LUNA/UST collapse in 2022, and even the 6.83% plunge in February 2025, with losses of up to US$2.21 billion. Understanding these historical events will help investors better understand the risks of the Bitcoin market and do

Analysis of the most promising virtual currency in 2025 Top 10 potential virtual currency inventory in 2025 Analysis of the most promising virtual currency in 2025 Top 10 potential virtual currency inventory in 2025 Feb 15, 2025 pm 05:51 PM

The virtual currency market is constantly evolving and exciting growth is expected in the coming years. In 2025, some cryptocurrencies are expected to stand out and become the most promising investments in the space. This article analyzes some of the most promising virtual currencies in 2025, covering their unique capabilities, growth potential and possibilities that impact the future. These currencies include Ethereum, Bitcoin, Cardano, Polkadot and Binance Coin, which play a key role in the development of decentralized finance, smart contracts and blockchain technologies. Understanding the potential of these virtual currencies, investors can be prepared to seize the opportunities brought by the virtual currency market in 2025.

The top10 official website registration portal for currency trading platform The top10 official website registration portal for currency trading platform Mar 04, 2025 pm 09:00 PM

Currency trading is currently a popular investment method, and choosing the right platform is crucial. This article lists the top 10 most recognized currency trading platforms in the industry, providing investors with a comprehensive reference guide. These platforms are known for their superior security, convenient trading capabilities and a wide range of cryptocurrency options. This article highlights the key features of each platform to help investors make informed decisions and choose the platform that best suits their needs and investment strategies.

See all articles