- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
嗨,我正在做这个问题https://www.spoj.com/problems/BUGLIFE/在 SPOJ 上,但我得到了 WA,任何人都可以帮忙。这是我的代码。
我正在尝试使用集合来解决这个问题。我听说过使用二分图来解决这个问题,但我认为使用这种方法应该足够了,除非我的方法有问题。我已经尝试了很多测试用例,但我不知道我的代码在哪里失败了。
任何愿意提供帮助的人的额外测试用例:-
http://spojtoolkit.com/history/BUGLIFE
测试用例的预期输出
:- http://spojtoolkit.com/test/BUGLIFE
示例输入:-
2
3 3
1 2
2 3
1 3
4 2
1 2
3 4
示例输出:-
场景 #1:
发现可疑错误!
场景#2:
没有发现可疑的错误!
我的代码输出与预期输出相同。
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
for(int s = 0 ; s < t ; s++ ){
int bugs , inter; // Bugs and Interactions
cin >> bugs >> inter;
map<int,int> isDiscovered , male , female;
int bug1 , bug2;
vector<pair<int , int> > b; //stores pair of interactions
for(int i = 0 ; i < inter ; i++){
cin >> bug1 >> bug2;
b.push_back(make_pair(bug1,bug2));
}
sort(b.begin() , b.end());
bool ans = true;
for(int i = 0 ; i < b.size() ; i++){
bug1 = b[i].first;
bug2 = b[i].second;
//both not classified
if(isDiscovered.find(bug1) == isDiscovered.end() && isDiscovered.find(bug2) == isDiscovered.end()){
isDiscovered[bug1]++;
isDiscovered[bug2]++;
male[bug1]++;
female[bug2]++;
}
//one classified
if(isDiscovered.find(bug1) != isDiscovered.end() || isDiscovered.find(bug2) != isDiscovered.end()){
if(isDiscovered.find(bug1) == isDiscovered.end()){
//bug1 does not exist
isDiscovered[bug1]++;
if(male.find(bug2) == male.end()){
//bug2 is female
male[bug1]++;
}
else{
//bug2 is male
female[bug1]++;
}
}
else{
//bug2 does not exist
isDiscovered[bug2]++;
if(male.find(bug1) == male.end()){
//bug1 is female
male[bug2]++;
}else{
female[bug2]++;
}
}
}
//both classified
if(isDiscovered.find(bug1) != isDiscovered.end() && isDiscovered.find(bug2) != isDiscovered.end()){
if(male.find(bug1) != male.end() && male.find(bug2) != male.end()){
//both males
ans = false;
}
else if(female.find(bug1) != female.end() && female.find(bug2) != female.end()){
//both females
ans = false;
}
}
if(ans == false){
break;
}
}
cout << "Scenario #" << s+1 << ":" << endl;
if(ans == false){
cout << "Suspicious bugs found!" << endl;
}
else{
cout << "No suspicious bugs found!" << endl;
}
}
return 0;
}
最佳答案
如果两个 bug 都是新的,你无条件说第一个是雄性的,第二个是雌性的。不一定如此。我们只能假设他们是不同的性别,但还没有根据来指定性别。尝试
4 2
2 1
3 4
(与情况 2 相同,交换了第二对)。
关于c++ - 为什么我在 spoj 上获得 BUGLIFE 的 WA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54685649/
我的插件中有用于 BufWritePost 的 autocmd。 (我在此自动命令中更新整个项目的标签,这是插件 Indexer.tar.gz ) 有时我需要保存很多文件(我做 ":wa")。而且,当
我正在尝试解决 http://www.spoj.pl/problems/SCUBADIV/ spoj.com 上的这个问题,但我得到了 WA。我写了一个递归解决方案并使用了内存。谁能帮我找出我的错误?
此代码中出现错误,即使它通过了基本测试用例。但是,它仍然给出了错误的答案。 找不到失败的测试用例,Codechef 最大问题计数的解决方案。我认为部分代码导致某些测试用例失败。 谁能帮我找出这段代码中
我目前正在使用以下映射,基本上通过执行脚本将我的 dev env 中编写的任何文件复制到我的本地服务器。它适用于单个文件。但是,我有做 :wa 来保存所有打开的缓冲区的习惯: au BufWriteP
有谁知道合适或推荐的方法来制作 Whatsapp 重定向链接,例如 wa.me/PhoneNumber ..是否使用 javascript 重定向到链接?或者仅使用自定义域的 URL 重定向,然后重定
我正在尝试解决 SPOJ 问题 GSS1 (你能回答我的这些问题吗)使用 segment tree .我正在使用“init”方法初始化一棵树,并使用“query”方法在 [i,j] 范围内获得最大值。
这是SPOJ的问题 小费鲁达很喜欢玩。如你所知,他只玩数字。所以他得到了n个数字。现在尝试将数字分组到不相交的集合中,每个集合包含两个数字。他可以形成包含两个数的集合当且仅当集合中的小数恰好是大数的一
在我们使用 Windows Identity Foundation 的项目上工作。在测试注销解决方案时,我发现以下调用 http://rp/?wa=wsignoutcleanup1.0不会删除 RP
前段时间我写了一个类似 Wa-Tor 的元胞自动机 (see Wikipedia),但有更多的物种和更聪明的物种。除了为获得稳定的系统而进行的大量微调外,它非常简单并且运行良好。然而,从那时起,我就在
正如标题所示,我正在尝试使用 d3 制作交互式区域统计图。我发现了一个有趣的例子,我正在尝试将其复制到另一个位置。具体来说,我正在尝试在邮政编码级别绘制华盛顿州。 我添加了 code我目前有可能进行编
我有一个 BufWritePre 钩子(Hook),不幸的是,它不适用于 :wa,只能用于 :w(还有 :wq). 我怎样才能让它与 :wa 一起工作? 这是我在 .vimrc 中的一个钩子(Hook
我在使用一个表中的属性与另一个表中的属性相同的条件时遇到循环问题。为了更好地解释,我将通过代码。不是什么难事,但我不明白我在哪里犯了错误。 LOOP AT gt_spfli INTO wa_spfli
我无法理解/想到我的代码无法给出正确输出的情况。问题链接:http://www.spoj.pl/problems/MKBUDGET/ 问题显然有 DP 解决方案。我在下面发布我的解决方案: #incl
我卡在 this question 上了得到WA。 我见过很多关于这个问题的自下而上的实现。我的自上而下的实现不适用于内存,但没有它也能正常工作。我该如何纠正它? #include #include
我正在尝试解决这个问题,我想我已经找到了正确答案,但我不断收到法官的 WA(错误答案)回复。 http://uva.onlinejudge.org/index.php?option=onlinejud
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 9
有时我切换 Git 分支而不关闭当前分支独有的文件的 VIM 缓冲区。这些缓冲区将被隐藏,我将在拆分中打开新缓冲区并开始对新分支进行更改。而不是 :w单独使用这些新缓冲区,我想 :wa ,但这会写入所
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
嗨,我正在做这个问题https://www.spoj.com/problems/BUGLIFE/在 SPOJ 上,但我得到了 WA,任何人都可以帮忙。这是我的代码。 我正在尝试使用集合来解决这个问题。
我正在尝试这个问题:http://www.spoj.com/problems/ANDROUND 我的算法由 32 行和 N 列的二维数组构成(32 是因为在 31 轮之后,数组没有改变)。然后,它通过
我是一名优秀的程序员,十分优秀!