Home > Web Front-end > HTML Tutorial > Codeforces(441B) Round #252 (Div. 2)_html/css_WEB-ITnose

Codeforces(441B) Round #252 (Div. 2)_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:03:14
Original
1125 people have browsed it

Question link: http://codeforces.com/contest/441/problem/C

Tips: There is an n*m matrix, and you need to fill it with k pipes For rectangular shapes, pipes can only be placed horizontally or vertically, not diagonally. Allows you to output the coordinates of the passing points of the pipeline for each line. Because there are many placement methods, you only need to output any one that meets the conditions.

Since n,?m,?k (2?≤?n,?m?≤?300; 2?≤?2k?≤?n·m), the first k-1 pipes only need It occupies two points and the last pipe has a serpentine trajectory, so that all situations are satisfied.

#include <iostream>#include <cstdio>#define MAX_N 300using namespace std;int main(){        #ifndef ONLINE_JUDGE            freopen("D:/out.txt","w",stdout);    #endif  //ONLINE_JUDGE    int n,m,k;    scanf("%d%d%d",&n,&m,&k);    int i=1;    int j=1;    bool s=true;    for(int p=1;p<k;p++)    {        printf("2");        for(int t=1;t<=2;t++)        {            if(!s&&t==2&&j==1)            {                printf(" %d %d",i++,j);                s=true;            }            else if(s&&t==2&&j==m)            {                printf(" %d %d",i++,j);                s=false;            }            else if(s&&t==1&&j==m)            {                printf(" %d %d",i++,j);                s=false;                }            else if(s)            {                printf(" %d %d",i,j);                j++;            }            else            {                printf(" %d %d",i,j);                j--;            }        }        printf("\n");    }    printf("%d ",n*m-(k-1)*2);    for(;i<=n;i+=2)    {        if(s)        {            for(;j<=m;j++)                printf("%d %d ",i,j);            j--;            if(i<n)            {                for(;j>=1;j--)                    printf("%d %d ",i+1,j);            }            j++;        }        else        {            for(;j>=1;j--)            {                printf("%d %d ",i,j);            }            j++;            if(i<n)            {                for(;j<=m;j++)                    printf("%d %d ",i+1,j);            }            j--;        }    }    return 0;}
Copy after login


Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template