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 ...
随机推荐
- handsontable的单元格操作方法
1.为handsontable添加钩子方法 addHook(key,callback):key为钩子方法名 <span style="font-size:18px;"> ...
- 【问题备注】VS2012不能输入代码,文字…
第一次遇到,非常奇怪,一个项目,VS2012能正常打开,但是不能输入代码. 对比分析发现,其他项目能正常work.在于一个问题就是,VS2012 右下角有个INS一直在转一直analyzing,而正常 ...
- Entity Framework数据库迁移
1.启用数据迁移: enable-Migrations2.增加一条数据库迁移指令:add-Migrations 必须带上一个版本名称,比如AddUsernamePassword完整的指令:add-Mi ...
- OC——UIlabel text的常规应用
UILabel *downloader = [[UILabel alloc]init]; NSString *downloadCount = [[LibraryArr objectAtIndex:in ...
- 使用Win32 API 查找文件
头文件:#include <windows.h> //FindFirstFile() 获得指定目录的第一个文件 HANDLE FindFirstFile( LPCTSTR lpFileNa ...
- mysql列名不能输入中文 解决办法
以前安装了mysql,今天下午做了个练习,每次列名为中文时总是报错.查资料显示说需要修改配置文件my.ini 我的路径是:C:\Program Files\MySQL\MySQL Server 5.5 ...
- memcmp()直接比较两个数组的大小
两个字符数组可以用strcmp()比较大小.两个整数数组也有个函数memcmp()可以比较大小,和strcmp()的返回值一样的. 头文件#include<cstring> / #incl ...
- php 出现 500 Internal Server Error错误问题解决
set_time_limit(0); //设置超时时间 chmod 777 filename //设置文件权限 问题根本不在这,读取数据太多,数组是很站内存的. 内存设置大些就ok了 ini_set( ...
- c#POST请求和接收post请求
c# post请求发送数据 /// <summary> /// POST请求 /// </summary> /// <param name="url" ...
- 开心菜鸟系列学习笔记------javascript(4)
一.全局上下文中的变量对象: 1)全局对象(Global object) 是在进入任何执行上下文之前就已经创建了的对象:这个对象只存在一份,它的属性在程序中任何地方都可以访问,全局对象的 ...