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 ...
随机推荐
- 【codevs1257】 打砖块
http://codevs.cn/problem/1257/ (题目链接) 题意 在等腰三角形上打砖块,总共有m发炮弹,每块砖有一个权值,求打出的最大权值 Solution 今天考试题,考场上的2个小 ...
- HYSBZ 4197 寿司晚宴
Description 为了庆祝 NOI 的成功开幕,主办方为大家准备了一场寿司晚宴.小 G 和小 W 作为参加 NOI 的选手,也被邀请参加了寿司晚宴. 在晚宴上,主办方为大家提供了 n−1 种不同 ...
- Eclips将lib打入war中
在项目的属性, java build path -> Libraries -> Add library.. -> Web app Libraries .即可. 在属性中, Deplo ...
- HDU 1054 Strategic Game(最小点覆盖+树形dp)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=106048#problem/B 题意:给出一些点相连,找出最小的点数覆盖所有的 ...
- POJ2586Y2K Accounting Bug(贪心 + 不好想)
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12251 Accepted: 62 ...
- shell脚本等的操作
1.命令替换:`` 反向单引号,也称重音符.键盘上和~键在一起的那个键呦,千万不要敲成单引号. A. 使用了``后,shell首先替换输出中``括起来的date命令,然后执行整个输出命令. B.命令替 ...
- html5+ 获取当前设备的加速度信息
getCurrentAcceleration 获取当前设备的加速度信息 void plus.accelerometer.getCurrentAcceleration( successCB, error ...
- java中request,application,session三个域及参数简单示例
直接上代码: java代码: public class HelloAction implements Action { @Override public String execute() throws ...
- photon mapping阶段性总结
PM算法看了这么久,也该是到了总结的时候了.自己实现的是PPPM(Probabilistic progressive photon mapping)的一个简化形式.之所以是简化形式是由于我的光子搜集时 ...
- php中文字符串翻转
转自:http://www.oschina.net/code/snippet_613962_17070 <?php header("content-type:text/html;cha ...