CodeForces - 417E(随机数)

Square Table

Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

While resting on the ship after the "Russian Code Cup" a boy named Misha invented an interesting game. He promised to give his quadrocopter to whoever will be the first one to make a rectangular table of size n × m, consisting of positive integers such that the sum of the squares of numbers for each row and each column was also a square.

Since checking the correctness of the table manually is difficult, Misha asks you to make each number in the table to not exceed 108.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100)  — the size of the table.

Output

Print the table that meets the condition: n lines containing m integers, separated by spaces. If there are multiple possible answers, you are allowed to print anyone. It is guaranteed that there exists at least one correct answer.

Sample Input

Input

1 1

Output

1

Input

1 2

Output

3 4

Source

RCC 2014 Warmup (Div. 2)

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
bool pd(int s)
{
    int k=sqrt(s);
    return k*k==s;
}
int main()
{
    int n,m,a,b,c,d,i,j;
    while(cin>>n>>m)
    {
       for (a=1;a<=100;a++)
       for (b=1;b<=100;b++)
       for (c=1;c<=100;c++)
       for (d=1;d<=100;d++)
       {
           int s1=(m-1)*a*a+b*b;
           int s2=(n-1)*a*a+c*c;
           int s3=(n-1)*b*b+d*d;
           int s4=(m-1)*c*c+d*d;
           if (pd(s1)&&pd(s2)&&pd(s3)&&pd(s4))
           goto next;
       }
       next:
       for (i=1;i<n;i++)
       {
           for (j=1;j<m;j++)
           cout<<a<<" ";
           cout<<b<<endl;
       }
       for (i=1;i<m;i++)
       cout<<c<<" ";
       cout<<d<<endl;
    }
    return 0;
}
时间: 2024-10-10 00:12:31

CodeForces - 417E(随机数)的相关文章

Codeforces 101482F(gym)随机数

给出n个点,求是否存在一条直线,使得落在直线上的点占所有点的p%以上. n<=100000 2<=p<=100 #include<iostream> #include<cstdio> #include<cstring> #include<ctime> #include<cstdlib> #define maxn 100010 using namespace std; int n; int p; struct node{ long

Codeforces Round #354 (Div. 2)

5/5 水了场CF,写个水水地题解~~ 题A CodeForces 676A 题意:给你一个排列,问你交换一次,最大最小位置最远是多少? 题解:暴力交换,暴力算,反正数据小.偷懒被hack更惨!! 1 /*zhen hao*/ 2 #include <bits/stdc++.h> 3 using namespace std; 4 5 #define lson l, m, rt*2 6 #define rson m + 1, r, rt*2+1 7 #define xx first 8 #def

Codeforces #246(div2)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <ti

Codeforces 947E Perpetual Subtraction (线性代数、矩阵对角化、DP)

手动博客搬家: 本文发表于20181212 09:37:21, 原地址https://blog.csdn.net/suncongbo/article/details/84962727 呜啊怎么又是数学了啊...数学比例\(\frac{16}{33}=0.4848\) orz yhx-12243神仙 题目链接: https://codeforces.com/contest/947/problem/E 题意: 有一个\([0,n]\)的随机数\(x\)初始为\(i\)的概率为\(p_i\). \(m

codeforces#1305F. Kuroni and the Punishment(随机算法)

题目链接: https://codeforces.com/contest/1305/problem/F 题意: 给出$n$个数,最少执行多少次操作可以使得$n$个数最大公约数不为1 每次操作可以给某个数加一或者减一 分析: 由于因子为$2$时,最多需要执行$n$次操作 所以在寻找到最优因子的情况下,执行两次操作的数的数量不可能多于$\frac{1}{2}$ 那么任意选择数组中的一个数$a[i]$,最优因子是$a[i],a[i]+1,a[i]-1$的因子的概率是$\frac{1}{2}$ 那么在数

【codeforces 718E】E. Matvey&#39;s Birthday

题目大意&链接: http://codeforces.com/problemset/problem/718/E 给一个长为n(n<=100 000)的只包含‘a’~‘h’8个字符的字符串s.两个位置i,j(i!=j)存在一条边,当且仅当|i-j|==1或s[i]==s[j].求这个无向图的直径,以及直径数量. 题解:  命题1:任意位置之间距离不会大于15. 证明:对于任意两个位置i,j之间,其所经过每种字符不会超过2个(因为相同字符会连边),所以i,j经过节点至多为16,也就意味着边数至多

Codeforces 124A - The number of positions

题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing b

Codeforces 841D Leha and another game about graph - 差分

Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or  - 1. To pass th

Codeforces Round #286 (Div. 1) A. Mr. Kitayuta, the Treasure Hunter DP

链接: http://codeforces.com/problemset/problem/506/A 题意: 给出30000个岛,有n个宝石分布在上面,第一步到d位置,每次走的距离与上一步的差距不大于1,问走完一路最多捡到多少块宝石. 题解: 容易想到DP,dp[i][j]表示到达 i 处,现在步长为 j 时最多收集到的财富,转移也不难,cnt[i]表示 i 处的财富. dp[i+step-1] = max(dp[i+step-1],dp[i][j]+cnt[i+step+1]) dp[i+st