UVa 488 - Triangle Wave

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=94&page=show_problem&problem=429

题目:每个例子输入2个数,一个是wave的幅度,一个是重复的个数。

例如:Input1

32

output:122333221

122333221

思路: 将1,22,333,···,999999999.字符串存在数组里。按照幅度打印输出就好。然后注意一下空行。

 1 #include<iostream>
 2 #include<cstdio>
 3 using namespace std;
 4
 5 char cc[9][10]={"1","22","333","4444","55555","666666","7777777","88888888","999999999"};
 6
 7 int main()
 8 {
 9   // freopen("input.txt","r",stdin);
10   // freopen("output.txt","w",stdout);
11    int t,n,m,i,j,k;
12    cin>>t;
13    while(t--)
14    {
15       cin>>n>>m;
16       for(i=0;i<m;i++)
17       {
18        for(j=0;j<n;j++)
19           cout<<cc[j]<<‘\n‘;
20        for(j=n-2;j>=0;j--)
21           cout<<cc[j]<<‘\n‘;
22        if(i<m-1)
23         cout<<‘\n‘;
24       }
25        if(t>0)
26         cout<<‘\n‘;
27
28     }
29     return 0;
30 }     
时间: 2024-09-30 07:23:27

UVa 488 - Triangle Wave的相关文章

UVA - 11437 - Triangle Fun (计算几何~)

UVA - 11437 Triangle Fun Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem A Triangle Fun Input: Standard Input Output: Standard Output In the picture below you can see a triangle ABC. Point D, E

uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)

题目链接:uva 1478 - Delta Wave 题目大意:对于每个位置来说,可以向上,水平,向下,坐标不能位负,每次上下移动最多为1, 给定n问说有多少种不同的图.结果对10100取模. 解题思路:因为最后都要落回y=0的位置,所以上升的次数和下降的次数是相同的,并且上升下降的关系满足出栈入栈的关系.即卡特兰数. 所以每次枚举i,表示有i个上升,i个下降,用组合数学枚举出位置,然后累加求和. C(2?in)?f(i)=C(2?i?2n)?f(i?1)?(n?2?i+1)?(n?2?i+2)

UVA 11401 - Triangle Counting(数论+计数问题)

题目链接:11401 - Triangle Counting 题意:有1,2,3....n的边,求最多能组成的三角形个数. 思路:利用三角形不等式,设最大边为x,那么y + z > x 得 x - y < z < x 然后y取取值,可以从1取到x - 1,y为n时候,有n - 1个解,那么总和为0 + 1 + 2 +...+ (x - 2) = (x - 1) * ( x- 2) / 2; 然后扣除掉重复的y = z的情况,在y > x / 2时,每个y取值会出现一次y = z.

UVA - 11401 - Triangle Counting (递推!)

UVA - 11401 Triangle Counting Time Limit: 1000MS Memory Limit: Unknown 64bit IO Format: %lld & %llu Submit Status Description Problem G Triangle Counting Input: Standard Input Output: Standard Output You are given n rods of length 1, 2-, n. You have

uva 194 - Triangle(几何)

题目链接:uva 194 - Triangle 注意两边一角,并接角的对边确定时(即用正弦定理求解时,可能会有多解的情况) #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double pi = 4 * atan(1); const double eps = 1e-4; double A[6]; void

uva 11401 - Triangle Counting(数论)

题目链接:uva 11401 - Triangle Counting 题目大意:有多少种方法可以从1,2,3...n中选出3个不同的数组成三角形,给出n,求种数. 解题思路:加法原理,设最大边为x的三角形有c(x)个,那么另外两条边长分别为y和z,根据三角形的形式可以的y+z>x,所以z的范围即为x?y<z<x 根据这个不等式可以得到每个y值所对应的z值个数,为等差数列,所以 c(x)=(x?1)?(x?2)2??x?12?2 然后根据递推:f(n)=∑i=1nc(i) 代码 #incl

UVA 10746 Crime Wave – The Sequel(费用流)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1687 ProblemG CrimeWave – The Sequel Input: StandardInput Output: StandardOutput TimeLimit: 2 Seconds n bankshave been robbed this fine day. m (grea

UVA 11401 - Triangle CountingTriangle Counting 数学

You are given n rods of length 1,2, . . . , n. You have to pick any 3 of them and build a triangle. Howmany distinct triangles can you make? Note that, two triangles will be considered di?erent if they haveat least 1 pair of arms with di?erent length

UVA - 1478 Delta Wave (大数+卡特兰数)

Description A delta wave is a high amplitude brain wave in humans with a frequency of 1 - 4 hertz which can be recorded with an electroencephalogram (EEG) and is usually associated with slow-wave sleep (SWS). - from Wikipedia The researchers have dis