Beauty of Array(模拟)
Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
SAT was the first known NP-complete problem. The problem remains NP-complete even if all expressions are written in conjunctive normal form with 3 variables per clause (3-CNF), yielding the 3-SAT problem. A K-SATproblem can be described as follows:
There are n persons, and m objects. Each person makes K wishes, for each of these wishes either he wants to take an object or he wants to reject an object. You have to take a subset of the objects such that every person is happy. A person is happy if at least one of his K wishes is kept. For example, there are 3 persons, 4 objects, and K = 2, and
Person 1 says, "take object 1 or reject 2."
Person 2 says, "take object 3 or 4."
Person 3 says, "reject object 3 or 1."
So, if we take object 1 2 3, then it is not a valid solution, since person 3 becomes unhappy. But if we take 1 2 4 then everyone becomes happy. If we take only 4, it's also a valid solution. Now you are given the information about the persons' wishes and the solution we are currently thinking. You have to say whether the solution is correct or not.
Input
Input starts with an integer T (≤ 100), denoting the number of test cases.
Each case starts with a line containing three integers n, m, K (1 ≤ n, m, K ≤ 30). Each of the next nlines contains K space separated integers where the ith line denotes the wishes of the ith person. Each of the integers in a line will be either positive or negative. Positive means the person wants the object in the solution; negative means the person doesn't want that in the solution. You can assume that the absolute value of each of the integers will lie between 1 and m.
The next line contains an integer p (0 ≤ p ≤ m) denoting the number of integers in the solution, followed byp space separated integers each between 1 and m, denoting the solution. That means the objects we have taken as solution set.
Output
For each case, print the case number and 'Yes' if the solution is valid or 'No' otherwise.
Sample Input
2
3 4 2
+1 -2
+3 +4
-3 -1
1 4
1 5 3
+1 -2 +4
2 2 5
Sample Output
Case 1: Yes
Case 2: No
题解:n个人找对象,对象从1--m,负数代表不要,正数代表要;现在给一组数,问是否满足所有人的意愿;
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
int mp[][]; int vis[];
int p;
int n, m, k;
set<int>st;
bool js(){
for(int i = ; i <= n; i++){
int flot = ;
for(int j = ; j <= k; j++){
if(st.count(mp[i][j])){
flot = ;
break;
}
}
if(!flot)return false;
}
return true;
}
int main(){
int T, kase = ;
scanf("%d", &T);
while(T--){
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i <= n; i++){
for(int j = ; j <= k; j++){
scanf("%d", &mp[i][j]);
}
}
scanf("%d", &p);
st.clear();
memset(vis, , sizeof(vis));
int x;
for(int i = ; i <= p; i++){
scanf("%d", &x);
st.insert(x);
vis[x] = ;
}
for(int i = ; i<= m; i++){
if(!vis[i])st.insert(-i);
}
if(js())printf("Case %d: Yes\n", ++kase);
else
printf("Case %d: No\n", ++kase);
}
return ;
}
Beauty of Array(模拟)的更多相关文章
- DP ZOJ 3872 Beauty of Array
题目传送门 /* DP:dp 表示当前输入的x前的包含x的子序列的和, 求和方法是找到之前出现x的位置(a[x])的区间内的子序列: sum 表示当前输入x前的所有和: a[x] 表示id: 详细解释 ...
- zoj The 12th Zhejiang Provincial Collegiate Programming Contest Beauty of Array
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5496 The 12th Zhejiang Provincial ...
- 第十二届浙江省大学生程序设计大赛-Beauty of Array 分类: 比赛 2015-06-26 14:27 12人阅读 评论(0) 收藏
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...
- ZOJ 3872 Beauty of Array
/** Author: Oliver ProblemId: ZOJ 3872 Beauty of Array */ /* 需求: 求beauty sum,所谓的beauty要求如下: 1·给你一个集合 ...
- Beauty of Array(思维)
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integ ...
- 2015 浙江省赛 Beauty of Array (思维题)
Beauty of Array Edward has an array A with N integers. He defines the beauty of an array as the summ ...
- ZOJ 3872: Beauty of Array(思维)
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integers. ...
- PHP用Array模拟枚举
C#中枚举Enum的写法: /// <summary> /// 公开类型 2-好友可见 1-公开 0-不公开 /// </summary> public enum OpenSt ...
- Beauty of Array
Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...
随机推荐
- Oracle通过指令创建用户
Oracle作为世界上使用最广泛的关系数据库,对于客户很多每天海量数据的公司是首要选择.我们公司在双十一期间,曾发生过每网点每天1G多的扫描数据量,全国有六千多个网点,每天每时不停读写数据库,而数据库 ...
- 2014 (多校)1011 ZCC Loves Codefires
自从做了多校,整个人都不好了,老是被高中生就算了,题老是都不懂=-=原谅我是个菜鸟,原谅我智力不行.唯一的水题. Problem Description Though ZCC has many Fan ...
- Servlet实现Session
(1)首先看一下项目的结构 是在tomcat--webaps下的myWebSites项目 在myWebSites下有仅仅有WEB-INF目录 在WEB-INF目录中有 一下目录(在classes目录 ...
- Timer.3 - Binding arguments to a handler
In this tutorial we will modify the program from tutorial Timer.2 so that the timer fires once a sec ...
- windows下用vs2008和boost结合编译程序
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://co63oc.blog.51cto.com/904636/504469 win ...
- animation与transition
animation 动画,无法直接决定开始时间 demo1 @-webkit-keyframes demo-animation1{ 0% { -webkit-transform:translate3d ...
- AngularJs学习(1)
以下是学习过程中的笔记,有些是网上摘录 <!DOCTYPE HTML> <html lang="zh-cn"> <head> <meta ...
- C#中静态类、静态方法和静态变量的简单说明
静态方法与静态变量一样,属于类本身,而不属于哪个类的一个对象.调用一个被定义为static的方法,只有通过在它前面加上这个类的名称.一般定义里说是可以通过实例调用的.其他语言我还没测试,但是在C#中是 ...
- C#创建文件夹、文件
private void CheckCatcheDirectory()//创建文件夹 { if (!Directory.Exists(xmlFilePath))//xmlF ...
- C++中const
[const] 0.普通const对象定义在栈空间中 { ; ; cout << &a << ' ' << &b; } Result: 0x22ab ...