首页 > ACM题库 > HDU-杭电 > HDU 3857-Who pat the head of itself?[解题报告]HOJ
2015
04-13

HDU 3857-Who pat the head of itself?[解题报告]HOJ

Who pat the head of itself?

问题描述 :

Let me tell you a long long story.
In BBS, if someone created a topic, then there would follow several user reply the topic and discuss it. As you know, the first one replied the topic we called it Sofa. Why? One explanation is that Sofa is a transliteration from English "SO FAST" terms appear in the network, commonly used in the first posted with the blog posts to respond quickly, that fast, quick response, that first step occupied NO.1 seat. "Take the Sofa away" is a clear sense of the verb word, first step into the occupation quickly caught the Sofa, and then comfortably told their friends, called all the users, people came to watch, very enjoyable. Another interpretation is: second floor refers Forum Replies’ second floor, take the first two letters of the word "SF", is followed into a Sofa.
As the Sofa is very conspicuous, has a lot of people are willing to take a Sofa away even if he did not read the article. However, only a Sofa, a lot of people think they take the Sofa away, but in fact they just take the 3 or more rearward floor. If you hurry to solve with this problem, please ignore paragraph 1 before and after 2, and the some of the input and output sentences. If you are not in a hurry, you can just take a look this problem description to to kill time.
Return to our "Sofa" story. As the war of "Take the Sofa away" became more and more popular, and many of the 3rd-floors envied the Sofas because their click speed were not so fast as the Sofas, so they cursed the Sofas or laughed at the Sofas with the sentences like "I come just for patting SF’s dog head" so on. Also, when someone had taken a Sofa away they would feel good about themselves, ridicule the 3rd-floor with "3rd-floor onec thought he had taken the Sofa away".
However, things do not turn out the way you want. Once you thought you would be Sofa and you submit "3rd-floor onec thought he had taken the Sofa away" but it turned out that you got the 3rd-floor. The similar situation would happen when you said "I come just for patting SF’s dog head" and you noticed that you were exactly the Sofa. A famous story about abusing himself is happened on one called "Brother 47". Once, he was very eager to get the Sofa and pretend himself the Sofa so that he always abused the 3rd-floor, and always the 3rd-floor he was. It made he feel angry about the Sofa and he decide to abuse the Sofa with "I come just for patting SF’s dog head", and after that he always took the Sofa away.
Everytime people saw those kinds of replies, the topic would be ignored and people came to crowd the bright "Brother 47". So much fun the "Brother 47" gave us. Now we define the "Brother 47": those who think they were not the floor of the number they said but they exactly were. There could be many "Brothers 47" or none.

输入:

There were several cases, end with EOF.
For each case, the first line contain one integer N (0<N<=10000), indicate the number of the replies; the second line contains N integers, indicate the floor number they said.

输出:

There were several cases, end with EOF.
For each case, the first line contain one integer N (0<N<=10000), indicate the number of the replies; the second line contains N integers, indicate the floor number they said.

样例输入:

9
9 8 7 6 5 4 3 2 1

样例输出:

5

冗长的题目 = =。巨水= =。。

输出数字和位置相同的数。如果没有输出No Mistake。

#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")

using namespace std;

const int MAX = 10010;
int a[MAX];
queue<int> q;
int main()
{
	int n,a;
	
	while( cin >> n )
	{
		while( !q.empty() ) q.pop();
		for(int i=1; i<=n; i++)
		{
			scanf("%d",&a);
			if( a == i ) q.push(a);
		}
		if( q.empty() )
		{
			printf("No Mistake\n");
			continue;
		}
		while( !q.empty() )
		{
			cout << q.front();
			q.pop();
			if( q.empty() )
				cout << endl;
			else
				cout << ' ' ;
		}
	}

return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/zxy_snow/article/details/6665426


  1. 第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。

  2. 你的理解应该是:即使主持人拿走一个箱子对结果没有影响。这样想,主持人拿走的箱子只是没有影响到你初始选择的那个箱子中有奖品的概率,但是改变了其余两个箱子的概率分布。由 1/3,1/3 变成了 0, 2/3

  3. 站长,你好!
    你创办的的网站非常好,为我们学习算法练习编程提供了一个很好的平台,我想给你提个小建议,就是要能把每道题目的难度标出来就好了,这样我们学习起来会有一个循序渐进的过程!

  4. 漂亮。佩服。
    P.S. unsigned 应该去掉。换行符是n 不是/n
    还可以稍微优化一下,
    int main() {
    int m,n,ai,aj,bi,bj,ak,bk;
    while (scanf("%d%d",&m,&n)!=EOF) {
    ai = sqrt(m-1);
    bi = sqrt(n-1);
    aj = (m-ai*ai-1)>>1;
    bj = (n-bi*bi-1)>>1;
    ak = ((ai+1)*(ai+1)-m)>>1;
    bk = ((bi+1)*(bi+1)-n)>>1;
    printf("%dn",abs(ai-bi)+abs(aj-bj)+abs(ak-bk));
    }
    }