Poj P3207 Ikki's Story IV - Panda's Trick___2-SAT

版权声明:欢迎借鉴,谢绝抄搬。 https://blog.csdn.net/Gx_Man_VIP/article/details/80394764









#define N 1000005
#define M 505

using namespace std;  

struct Edge{  
    int u, v, next;  

int Ls[N], instack[N], dfn[N], low[N], belong[N], px[M], py[M];  
int n, m, tot, num, cnt;

void addedge(int u, int v){  
    a[tot].u = u; a[tot].v = v; 
    a[tot].next = Ls[u];  Ls[u]=tot;  

stack <int>st;  

void tarjan(int u) { 
    dfn[u] = low[u] = ++num;  
    instack[u] = 1;  
    for (int i = Ls[u]; i; i = a[i].next) {   
         int v = a[i].v;  
         if (!dfn[v]){  
             low[u] = min(low[u], low[v]);  
         else if (instack[v]) low[u] = min(low[u], dfn[v]);  

    if (low[u] == dfn[u]) {  
         int rp;
         while ("rp++") {
                rp = st.top(); 
                instack[rp] = 0;  
                belong[rp] = cnt;  
                if (rp == u) break;

void solve_problem() {    
    num = cnt = 0;  
    for (int i = 1; i <= 2 * m; i++) 
         instack[i] = belong[i] = dfn[i] = low[i] = 0;
    for (int i = 1; i <= 2 * m; i++)
         if (!dfn[i]) tarjan(i);  

int main(){  
    while(~scanf("%d %d", &n, &m)){    
           for (int i = 1; i <= m; i++) {   
                scanf("%d %d", &px[i], &py[i]);  
                if (px[i] > py[i]) swap(px[i], py[i]);
           for (int i = 1; i <= 2 * m; i++) Ls[i] = 0;
           tot = 0;    
           for (int i = 1; i <= m; i++) {  
                for (int j = i + 1; j <= m; j++)   
                     if (px[j] >= px[i] && px[j] <= py[i] && py[j] >= py[i] || 
                         py[j] >= px[i] && py[j] <= py[i] && px[j] <= px[i]) {  
                         addedge(i, j + m);
                         addedge(j, i + m);  
                         addedge(i + m, j);  
                         addedge(j + m, i);  
           bool check = 1;  
           for (int i = 1; i <= m; i++)  
                if (belong[i] == belong[i+m]) check = 0;
           if (check) printf("panda is telling the truth...\n");  
                 else printf("the evil panda is lying again\n");  
    return 0;  

TN's Kingdom IV - Collapse


DescriptionnnTo conclude on TN's life as a short-lived king, I would like to mention the collapse of his regime. nFrankly speaking, TN was an inexperienced king, which was partly proved by his failed assassination of Dzx and well demonstrated by the defeat in his battle against Ikki's invasion which led to his capture and decapitation. nnAccording to studies of some historians, ever since he established his reign, TN had paid little attention to the fact that resource storage of the kingdom was imbalanced. Some crucial resources, including ammunition, were concentrated in a western bordering city. When he noticed that, it was all too late. The army of Ikki's kingdom had already launched invasion from the east. Now TN's most important city on the eastern border was under siege. nnHad TN had the expressways in the kingdom well built it would have been enough time to transport everything in need from the west to the east. But sentences like “had it been” won't describe history. Poor traffic conditions prevented the city from avoiding falling into Ikki's hands. nnHistorians want to know the exact situation TN faced. Yet due to lack of records in written history this is impossible. However, they are able to find out the complete expressway system (there were more expressways built following those first ones) of TN's kingdom where as mentioned before, expressways were straight and didn't cross each other due to technical limitations. Traffic on an expressway could go in either direction. But the total amount of traffic was limited. The historians rate by estimation the capacity of each expressway in real numbers where greater figure denotes greater capacity. They want to know the maximum transport rate from the western city and the eastern city. nnInputnnThe input consists of a single test case. The first line of input contains two positive integers N not exceeding 105 and M which are the numbers of cities and expressways. The follow N + M lines. The first N lines give the coordinates of the cities in the same way as in TN's Kingdom II - Construction assuming the positive direction of the x-axis points east and that of the y-axis points north. Among them are two cities which are uniquely the farthest to the west and to the east. They were the two bordering cities. The last M lines give the details of the expressway system. Each line contains two integers i, j and a real number c, meaning there was an expressway of estimated capacity c connecting the cities that appear in the (i + 1)-th and (j + 1)-th lines of the input. nOutputnnYour solution should output a single line containing the desired maximum transport rate rounded to four decimal places. nSample Inputnn2 1n0 0n1 0n0 1 1nSample Outputnn1.0000


  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他