uva 1605

构造法,,,,hahaha

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
char bb[60]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int main()
{
    while(~scanf("%d",&n))
    {
        printf("2 %d %d\n",n,n);
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
                printf("%c",bb[i]);
            printf("\n");
        }
        printf("\n");
        for(int i=0; i<n; i++)
        {
            for(int j=0; j<n; j++)
                printf("%c",bb[j]);
            printf("\n");
        }
    }
    return 0;
}
时间: 2024-07-31 22:15:12

uva 1605的相关文章

(白书训练计划)UVa 1605 Building for UN(构造法)

题目地址:UVa 1605 一道答案特判的题.最简单的方法是只构造两层,第一层中第i行全是i国家,第二层中第i列全是i国家.这样就保证了所有的国家都会相邻. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h&

UVa 1605 - Building for UN

链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4480 题意: 你的任务是设计一个包含若干层的联合国大楼,其中每层都是一个等大的网格.有若干国家需要在联合国大楼里办公,你需要把每个格子都分配给其中一个国家,使得任意两个不同的国家都有一对相邻的格子(要么是同层中相邻的格子,要么是相邻层的同一个格子),一个国家可以有多个相互连通的格子

UVa 1605 联合国大楼

https://vjudge.net/problem/UVA-1605 题意:有n个国家,要求设计一栋楼并为这n个国家划分房间,要求国家的房间必须连通,且每两个国家之间必须有一间房间是相邻的. 思路:乍一看很难的样子,但真的是很简单.一共只要两层,每层都是n*n的,第一层第i行全是国家i,第二层第j列全是国家j. 但是如果不是这样做的话好像还是挺难的. 1 #include<iostream> 2 #include<algorithm> 3 #include<string&g

UVA - 1605 Building for UN (联合国大楼)

题意:一个联合国大楼每层都有数量相等大小相同的格子,将其分配给n个国家,使任意两个不同的国家都相邻(同层有公共边或相邻层的同一个格子). 分析:可以设计一个只有两层的大楼,第一层每个国家占一行,第二层每个国家占一列,即每层都是n*n的. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib>

uva 1605 building for UN ——yhx

The United Nations has decided to build a new headquarters in Saint Petersburg, Russia. It will have aform of a rectangular parallelepiped and will consist of several rectangular oors, one on top of another.Each oor is a rectangular grid of the same

UVa 1605 (构造) Building for UN

题意: 有n个国家,要设计一栋长方体的大楼,使得每个单位方格都属于其中一个国家,而且每个国家都要和其他国家相邻. 分析: 紫书上有一种很巧妙的构造方法: 一共有2层,每层n×n.一层是每行一个国家,另一层是每列一个国家. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn = 50; 7 char b[2][max

《算法竞赛入门经典》之“算法设计与优化策略”

一.构造法 UVA 120 Stacks of Flapjacks Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug Description Background Stacks and Queues are often considered the bread and butter of data structures and find use in architecture, parsing, op

UVA 562 Dividing coins --01背包的变形

01背包的变形. 先算出硬币面值的总和,然后此题变成求背包容量为V=sum/2时,能装的最多的硬币,然后将剩余的面值和它相减取一个绝对值就是最小的差值. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define N 50007 int c[102],d

UVA 10341 Solve It

Problem F Solve It Input: standard input Output: standard output Time Limit: 1 second Memory Limit: 32 MB Solve the equation: p*e-x + q*sin(x) + r*cos(x) + s*tan(x) + t*x2 + u = 0 where 0 <= x <= 1. Input Input consists of multiple test cases and te