Skip to main content
  1. Posts/

uva 152 Tree's a Crowd

·2 mins
Note: This article is available in Chinese only. 本文暂无英文版本。 View original

题意:题意:给你一组三维空间中的点,每个点到其它点都有个距离,其中有个最小距离,如果这个最小距离小于10,就将对应的距离的点个数加1,最后输出距离为0,1,2…8,9的点的个数。(from 百度) 老实说,上面这题意也讲的不明不白,其实这题非常水,就是对每个点进行判断,找出和其他点最短的距离,在下标为该距离的数组上+1,最后输出数组下标0-9的数。 trick:其实最小距离大于9的就不用存放了,只要开个大小10的数组。(不会概括。。。抄的别人的)

好坑啊。。。最后要多一个换行。。不然会WA…题目中又木有说。。。WA到死了好么。。。。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年01月21日 星期四 00时08分50秒
 4File Name :uva/152.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#include <cassert>
20#define fst first
21#define sec second
22#define lson l,m,rt<<1
23#define rson m+1,r,rt<<1|1
24#define ms(a,x) memset(a,x,sizeof(a))
25typedef long long LL;
26#define pi pair < int ,int >
27#define MP make_pair
28
29using namespace std;
30const double eps = 1E-8;
31const int dx4[4]={1,0,0,-1};
32const int dy4[4]={0,-1,1,0};
33const int inf = 0x3f3f3f3f;
34const int N=5E3+11;
35int n;
36int cnt;
37int ans[30];
38int dblcmp( double d)
39{
40    return d<-eps?-1:d>eps;
41}
42struct point
43{
44    int x,y,z;
45
46    int dis(point q)
47    {
48	int res = (x-q.x)*(x-q.x)+(y-q.y)*(y-q.y)+(z-q.z)*(z-q.z);
49	return  (int)sqrt(res);
50    }
51
52}p[N];
53int main()
54{
55	#ifndef  ONLINE_JUDGE
56	freopen("code/in.txt","r",stdin);
57  #endif
58
59	ms(ans,0);
60	cnt =  0;
61
62	while (scanf("%d%d%d",&p[cnt].x,&p[cnt].y,&p[cnt].z)!=EOF)
63	{
64	    if (p[cnt].x==0&&p[cnt].y==0&&p[cnt].z==0) break;
65	    cnt++;
66	}
67
68
69	for ( int i = 0 ; i < cnt ; i++)
70	{
71	    int mind = 10000;
72	    for ( int j = 0 ; j < cnt ; j++)
73	    {
74		if (i==j) continue;
75		int tmp = p[i].dis(p[j]);
76
77		if (tmp<mind)
78		{
79		    mind = tmp;
80		}
81
82	    }
83		if (mind<10)
84		ans[mind]++;
85
86	}
87	for ( int i = 0 ; i < 10 ; i++)
88	printf("",ans[i]);
89	printf("\n");
90
91
92
93
94
95  #ifndef ONLINE_JUDGE
96  fclose(stdin);
97  #endif
98    return 0;
99}

Related

codeforces #322 div 2 A. Vasya the Hipster(纱布题)

·1 min
A. Vasya the Hipster time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.

uva 489

·2 mins
In ``Hangman Judge,’’ you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follows:

uva 401 Palindromes

·2 mins
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=96&page=show_problem&problem=342 题意:问一个字符串是不是回文串,是不是镜像串。镜像串的意思是。。从镜子里看还一样。。给定了一些存在镜像的字母和数字。。 思路:回文串的判断用c++的string要更容易一些。。直接reverse一下。。判断是否相等就行。。。然后需要注意的是。。如果某个字符补存在镜像那么一定不是镜像串

uva 10420 - List of Conquests

·1 min
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid;=8&page;=show_problem&problem;=1361 题意:给n个带空格的字符串,第一个单词是国家,统计每个国家的字符串的个数。 思路:getline函数。。。find函数。。。substr函数。。。map…..

hdoj 5606 ||bc #68 div 2 B tree

·2 mins
http://acm.hdu.edu.cn/showproblem.php?pid=5606 题意:一棵树,边权为0或者1,问对于每个点,距离它最近的点(包括自身)的个数是多少。输出将所有点的答案异或后的值。 思路:由于包括自身,自己与自己距离为0,那么最近的点一定也距离为0,所以就是找对于每个点与它相连的边权为0 的点的个数**。建图的时候可以不管边权为1的点。。因为这样的点不会对任何点的答案有贡献。**正解貌似是冰茶几。。我就是dfs搞了下。。找到每一个联通快的点数。。然后把某个联通快的所有点的答案都更新成点的个数。。。