【1148】Werewolf - Simple Version (20分)

简介: 【1148】Werewolf - Simple Version (20分)【1148】Werewolf - Simple Version (20分)
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<algorithm>  
#include<map>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;  
//狼人杀,假设i和j为狼人,  v[k] * a[abs(v[k])] <0即"说谎"
//条件:撒谎数组lie有两人且1狼1人
int main(){   
  int n;
  cin >>n;
  vector<int>v(n+1);
  for(int i=1;i<=n;i++) cin>>v[i];//保存每个人说的话
  for(int i=1;i<=n;i++){
    for(int j=i+1;j<=n;j++){
      vector<int>lie,a(n+1,1);//a都赋值为1
      a[i]=a[j]=-1;//假设i和j两人为狼人
      //a数组表示该人是好人(1)还是狼人(-1)
      for(int k=1;k<=n;k++)
        if(v[k]*a[abs(v[k])] <0) lie.push_back(k);
        //k说的话和真实情况不同,即表示k说谎,将k放入lie数组
      if(lie.size() ==2&&a[lie[0]]+a[lie[1]]==0){
        //说谎人数为2且一人好人一人为狼人即满足条件
        cout<<i<<" "<<j;
        system("pause");
        return 0;
      }
    }
  }
  cout<<"No Solution";
  system("pause");
    return 0;   
}
相关文章
|
6月前
|
Java
JDK version和class file version对应关系
JDK version和class file version对应关系
|
Java 应用服务中间件 Android开发
Description Resource Path LocationType Java compiler level does not match the version of the instal
Description Resource Path LocationType Java compiler level does not match the version of the instal
206 0
Description Resource Path LocationType Java compiler level does not match the version of the instal
|
Java Maven
使用maven构建项目报错Cannot change version of project facet Dynamic Web Module to 3.0解决方案
使用maven构建项目报错Cannot change version of project facet Dynamic Web Module to 3.0解决方案
使用maven构建项目报错Cannot change version of project facet Dynamic Web Module to 3.0解决方案
|
应用服务中间件
Cannot change version of project facet Dynamic Web Module to 3.0
Cannot change version of project facet Dynamic Web Module to 3.0
|
存储
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分)
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分)
85 0
PAT (Advanced Level) Practice - 1148 Werewolf - Simple Version(20 分)
PAT (Advanced Level) Practice - 1148 Werewolf - Simple Version(20 分)
126 0
PAT (Advanced Level) Practice - 1055 The World‘s Richest(25 分)
PAT (Advanced Level) Practice - 1055 The World‘s Richest(25 分)
112 0
|
存储
PAT (Advanced Level) Practice - 1126 Eulerian Path(25 分)
PAT (Advanced Level) Practice - 1126 Eulerian Path(25 分)
140 0
|
存储 测试技术
PAT (Advanced Level) Practice - 1131 Subway Map(30 分)
PAT (Advanced Level) Practice - 1131 Subway Map(30 分)
115 0
PAT (Advanced Level) Practice - 1016 Phone Bills(25 分)
PAT (Advanced Level) Practice - 1016 Phone Bills(25 分)
114 0