CodeForces - 417E(随机数)
Time Limit: 1000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
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
1 1
1
1 2
3 4
Source
#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=;a<=;a++)
for (b=;b<=;b++)
for (c=;c<=;c++)
for (d=;d<=;d++)
{
int s1=(m-)*a*a+b*b;
int s2=(n-)*a*a+c*c;
int s3=(n-)*b*b+d*d;
int s4=(m-)*c*c+d*d;
if (pd(s1)&&pd(s2)&&pd(s3)&&pd(s4))
goto next;
}
next:
for (i=;i<n;i++)
{
for (j=;j<m;j++)
cout<<a<<" ";
cout<<b<<endl;
}
for (i=;i<m;i++)
cout<<c<<" ";
cout<<d<<endl;
}
return ;
}
CodeForces - 417E(随机数)的更多相关文章
- Codeforces 417E Square Table(随机算法)
题目链接:Codeforces 417E Square Table 题目大意:给出n和m.要求给出一个矩阵,要求每一列每一行的元素的平方总和是一个平方数. 解题思路:构造.依照 a a a b a a ...
- Codeforces 417E
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #inclu ...
- Codeforces 1114E - Arithmetic Progression - [二分+随机数]
题目链接:http://codeforces.com/problemset/problem/1114/E 题意: 交互题,有一个 $n$ 个整数的打乱顺序后的等差数列 $a[1 \sim n]$,保证 ...
- Codeforces 1114 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1114 A - Got Any Grapes? 题意:甲乙丙三个人吃葡萄,总共有三种葡萄:绿葡萄.紫葡萄和黑葡萄,甲乙丙三个人至少要 ...
- Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)
https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...
- [codeforces gym Matrix God]随机矩阵乘法
题目链接:http://codeforces.com/gym/101341/problem/I 随机真是一个神奇的方法.原本矩阵乘法是n^3的复杂度,但是这个题是让判断两个矩阵是否相等,只需要在两个矩 ...
- Codeforces Round 254 (Div. 2)
layout: post title: Codeforces Round 254 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces 947E Perpetual Subtraction (线性代数、矩阵对角化、DP)
手动博客搬家: 本文发表于20181212 09:37:21, 原地址https://blog.csdn.net/suncongbo/article/details/84962727 呜啊怎么又是数学 ...
- .Net使用system.Security.Cryptography.RNGCryptoServiceProvider类与System.Random类生成随机数
.Net中我们通常使用Random类生成随机数,在一些场景下,我却发现Random生成的随机数并不可靠,在下面的例子中我们通过循环随机生成10个随机数: ; i < ; i++) { Rando ...
随机推荐
- 【uoj150】 NOIP2015—运输计划
http://uoj.ac/problem/150 (题目链接) 题意 给出一棵树以及m个询问,可以将树上一条边的权值修改为0,求经过这样的修改之后最长的边最短是多少. Solution 老早就听说过 ...
- BZOJ3172 后缀数组
题意:求出一篇文章中每个单词的出现次数 对样例的解释: 原文是这样的: a aa aaa 注意每个单词后都会换行 所以a出现次数为6,aa为3 (aa中一次,aaa中两次),aaa为1 标准解法好像是 ...
- event driven的一些概念
1. event :Something that happens during your application that requires a response. 2.event object:Th ...
- sublime text2 ctrl+b出现错误
查看提示的那个文件,发现是path那里写了一个/,是不符合条件的,得写 //
- 深入浅出Redis01安装
一 什么是Redis? Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API. Redis是一个高性能的Key-Va ...
- UVA1262Password(第K字典序)
题目链接 紫书P323 题意:两个6*5的字母矩阵,两个矩阵每列相同的字母,每列取一个,求按照字典序第k小的序列 分析: 对于第一个样例来说,我们得到{ACDW}.{BOP}.{GMOX}.{AP}. ...
- jquery中datagrid中getSelected和getSelections的应用
http://blog.sina.com.cn/s/blog_8e50ede90101fff9.html 刚开始使用jquery的datagrid就知道如果要对特定的一行进行编辑,可以是 $('#on ...
- The file couldn’t be opened because you don’t have permission to view it
because you dont have permission to view it 解决办法 Project---Build Setting中 修改这一项,变成Default Compiler(A ...
- hoj3152-Dice 等比数列求和取模
http://acm.hit.edu.cn/hoj/problem/view?id=3152 Dice My Tags (Edit) Source : Time limit : sec Memory ...
- tyvj1213 嵌套矩形
描述 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a<c,b<d或者b<c,a<d(相当于旋转X90度).例如 ...