[V0.1.0]Random problem
来源:互联网 发布:喀秋莎软件 编辑:程序博客网 时间:2024/06/04 19:49
input file:in.txt output file:out.txt
time limit: 500ms
language:ASM、C、C++、C#、Java、VB
Difficulty:★
Describe:
Assume that you have m unit cubes(whose edge lengths is 1) and a 3 - dimensional container .Your simple task is to put these cubes in random different integer coordinates of the container.
Input:
The first line:Three interger x,y,z(0<x,y,z<50)separated by whitespace, denoting the lengths of the 3 - dimensional container on each dimensional ;
The second line:A single interger m,denoting the number of cubes(0<m<=x*y*z);
The following m lines:A single string,denoting the name of each unit cube.
Output:
For each unit cube, output one line containing the coordinate of the cube in the format shown in the sample output.
Sample Input:
2 3 2
4
方块A
方块B
方块C
方块D
Sample Output:
方块A (2,1,2)
方块B (1,2,2)
方块C (1,1,2)
方块D (2,3,1)
Solution:
//C#4.0 Console Applicationusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.IO;using System.Collections;namespace RapidProtyping0_1_0{ struct point3d { public int x, y, z; public point3d(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } } class Program { static void Main(string[] args) { using (StreamReader sr = new StreamReader("in.txt", System.Text.Encoding.GetEncoding("GB2312"))) { using (StreamWriter sw = new StreamWriter("out.txt")) { readinfo(sr, sw); } } } static void readinfo(StreamReader sr, StreamWriter sw) { int x, y, z; string line = sr.ReadLine(); setXYZ(out x, out y, out z, line); int n = Convert.ToInt32(sr.ReadLine()); point3d[] parray = new point3d[n]; for (int i = 0; i < n; i++) { string line2 = sr.ReadLine(); int x1, y1, z1; getRandomPoint(parray, i, x, y, z, out x1, out y1, out z1); point3d pt = new point3d(x1, y1, z1); parray[i] = pt; sw.WriteLine(line2 + " (" + x1 + "," + y1 + "," + z1 + ")"); } } static private void getRandomPoint(point3d[] plist, int i, int x, int y, int z, out int x1, out int y1, out int z1) { do { Random r = new Random(); x1 = r.Next(1, x + 1); y1 = r.Next(1, y + 1); z1 = r.Next(1, z + 1); } while (Exist(x1, y1, z1, plist, i)); } static private bool Exist(int x1, int y1, int z1, point3d[] plist, int i) { for (int j = 0; j < i; j++) { if (plist[j].x == x1 && plist[j].y == y1 && plist[j].z == z1) return true; } return false; } static private void setXYZ(out int x, out int y, out int z, string line) { string[] s = line.Split(' '); x = Convert.ToInt32(s[0]); y = Convert.ToInt32(s[1]); z = Convert.ToInt32(s[2]); } }}
- [V0.1.0]Random problem
- [V0.1.0]Random problem
- Indicator random variables --Hat check problem
- [V0.1.1]Backtrack problem in a 4 - dimensional container
- [V0.1.1]Backtrack problem in a 4 - dimensional container.
- Random Select Problem(数组中前k大数问题)
- Random Contraction Algorithm for the min-cut problem
- random
- Random();
- random
- Random
- Random
- random
- Random
- Random
- Random
- Random
- Random
- Ubuntu中如何切换到超级用户(root)及在VMware虚拟机中Linux在虚拟终端之间切换的方法
- suncluster3.1无法启动处理总结
- Lucene的算法原理
- HDU 4123 树状DP+RMQ
- sql中实现提醒生日在今天内未来5天的用户DateAdd的用法
- [V0.1.0]Random problem
- 虚拟机下 USB 转串口 minicom 配置
- servlet过滤器
- Vim正则表达式
- ADF查询功能页面和修改功能页面优化设计
- CSharp转换System.Datetime为MySqlDatetime类型
- MAT使用
- 新一代弹性云计算平台cloudxy发布0.1版
- 隐蔽后门