有关bug's life的问题

pvagabond 2011-08-13 04:04:01
这个是POJ 2492 A bug's life:

我写了如下的代码,自己感觉还满正确的,但是却总是通过不了,不知道为什么,求各位大牛能不能帮忙一下。。在下感激涕零。。

#include <iostream>
using namespace std;

const int UP_LIMIT = 2001;
int num[UP_LIMIT] = {0};
int prev[UP_LIMIT] = {0};
int opp[UP_LIMIT] = {0};

void Make_Set(int x)
{
num[x] = 1;
prev[x] = x;
}

int Find_Set(int x)
{
if(x != prev[x])
prev[x] = Find_Set(prev[x]);
return prev[x];
}

void Union_Set(int x, int y)
{
x = Find_Set(x);
y = Find_Set(y);
if(x != y)
{
num[x] += num[y];
prev[y] = x;
}
}

void Make_Opposite(int x, int y)
{
if(opp[x] != 0)
Union_Set(y,opp[x]);
if(opp[y] != 0)
Union_Set(x,opp[y]);
opp[x] = Find_Set(y);
opp[y] = Find_Set(x);
}

int main()
{
int n, m; //n: # of bugs, m: # of interactions
int l = 0, tempA, tempB = 0, count = 0, button =0;
cin>>count;
while(l++<count)
{
button = 0; //reset
cin>>n>>m;
//make sets
for(int i=1;i<=n;i++)
Make_Set(i); // summing up to n sets
for(int i=0;i<m;i++)
{
cin>>tempA>>tempB;
if(Find_Set(tempA) != Find_Set(tempB))
Make_Opposite(tempA, tempB);
else
button = 1;
}
cout<<"Scenario #"<<l<<":"<<endl;
if(button)
cout<<"Suspicious bugs found!"<<endl<<endl;
else
cout<<"No suspicious bugs found!"<<endl<<endl;
}

}
...全文
70 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
至善者善之敌 2011-08-13
  • 打赏
  • 举报
回复
for(int j=0;j<m;j++) //这里换成j试试
{
cin>>tempA>>tempB;
if(Find_Set(tempA) != Find_Set(tempB))
Make_Opposite(tempA, tempB);
else
button = 1;
}
AlanBruce 2011-08-13
  • 打赏
  • 举报
回复
看看。。
pvagabond 2011-08-13
  • 打赏
  • 举报
回复
题目在此。http://poj.org/problem?id=2492

Background
Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and their interactions were easy to identify, because numbers were printed on their backs.
Problem
Given a list of bug interactions, decide whether the experiment supports his assumption of two genders with no homosexual bugs or if it contains some bug interactions that falsify it.
Input

The first line of the input contains the number of scenarios. Each scenario starts with one line giving the number of bugs (at least one, and up to 2000) and the number of interactions (up to 1000000) separated by a single space. In the following lines, each interaction is given in the form of two distinct bug numbers separated by a single space. Bugs are numbered consecutively starting from one.
Output

The output for every scenario is a line containing "Scenario #i:", where i is the number of the scenario starting at 1, followed by one line saying either "No suspicious bugs found!" if the experiment is consistent with his assumption about the bugs' sexual behavior, or "Suspicious bugs found!" if Professor Hopper's assumption is definitely wrong.
Sample Input

2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
Sample Output

Scenario #1:
Suspicious bugs found!

Scenario #2:
No suspicious bugs found!
Hint

Huge input,scanf is recommended.
pvagabond 2011-08-13
  • 打赏
  • 举报
回复
i 和 j 没有任何区别吧, 而且我试了,也不行。。
[Quote=引用 3 楼 babilife 的回复:]

for(int j=0;j<m;j++) //这里换成j试试
{
cin>>tempA>>tempB;
if(Find_Set(tempA) != Find_Set(tempB))
Make_Opposite(tempA, tempB);
else
button = 1;
}
[/Quote]
PhantOm V1.25 修正 [PhantOm plugin 1.25 ] by Hellsp @ wn & Archer / / spring aggravation: / / IHA! PEOPLE WITH ALL DAY! SPRING WALKS! BEER begins! GULYAYTE DEVUSHKAMI X! / / ZHIVITE FULL LIFE! | Privety fly to: | Bronco, kioresk, RSI, lord_Phoenix, HoBleen, Grim Fandango, | Guru.eXe, vad8787, PE_Kill. ————————————————– ————————— The plug to hide OllyDbg (with driver). Helps detection of the following methods: / / driver - extremehide.sys [+] NtQueryInformationProcess. [+] SetUnhandledExceptionFilter. [+] OpenProcess. [+] Invalid Handle. [+] NtSetInformationThread. [+] RDTSC. [+] NtYieldExecution. [+] NtQueryObject. [+] NtQuerySystemInformation. [+] Windows hide. [+] GetProcessTimes. [+] NtSetContextThread. / / plug - PhantOm.dll [+] PEB BeingDebugged. [+] PEB NtGlobalFlag. [+] GetStartupInfo. [+] Process Heaps. [+] GetTickCount. [!] Protect DRx. [!] Hide DRx. [!] Fake Windows version. [!] Custom Handler. [+] BlockInput What’s New - 1.25 You may now ask the very name services HIDENAME and RDTSCNAME. Some minor bugs. Fixed bug with memory breakpoints. What’s New - 1.20 Added own processing exceptions (C0000005). Added the title change of the main window. Added own processing exceptions (OUTPUT_DEBUG_STRING_EVENT). int 3 at EP correctly removed if the stop at the point of the system failed. Added BlockInput interception. (WinXP only) Added own processing exceptions (C0000094). Added hide from GetStartupInfo. Fixed bug with the settings plug. Added protection from detection drivers. What’s New - 1.15 Several bugs. What’s New - 1.10 hook GetProcessTimes - moved to the driver. hook NtSetContextThread - moved to the driver. The bug and removing the “EP break.” Several bugs related to downloading options. In ini added “DELTARDTSC which will regulate the spread RDTSC. What’s New - 1.04 Fixed bsod while loading drivers. What’s New - 1.03 Fixed bug with windows. What’s New - 1.01 Fixed bug in the driver. What’s New - 1.00 Added protection OllyDbg windows. Now OllyDbg patchitsya regardless of ImageBase. What’s New - 0.60 Added own processing exceptions (C000001E, 80000001, C000001D). Added removal int3 with EntryPoint. Fixed bug with GetTickCount. Added methods in anti-detekta driver. What’s New - 0.58 Fixed bug with Hide from peb on some systems. What’s New - 0.57 Fixed bug with the attachment to the process. Added protection from GetProcessTimes. [-] Removed option Fake Windows version (at the time). What’s New - 0.55 Improved imulyatsiya GetTickCount. Added emulation RDTSC. Fixed bug with not zeroing ServicePack. A bit optimized code. What’s New - 0.53 Now the driver is in resources. NtSetInformationThread added protection. Fixed bug with Fake Windows version. What’s New - 0.51 Fixed bug in the GetTickCount Fixed bug with a patch PEB ‘and / / Notes: – if you have changed the settings in the plug, but you open any file in OllyDbg, necessarily have to restart it (Ctrl-F2) program. – plug-in displays debug messages Log (Alt + L), so the first run advised to put all the options and examine the Log for errors. – tested only on Windows 2000 SP4, XP SP2. – with the plug, it is recommended to turn off programs that can prevent loading drivers (Antivirus, PC). – incorrect in the work are encouraged to try to plug the “native” OllyDbg, without extraneous plugins.

64,644

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧