ZOJ - 3954 Seven-Segment Display 【状态标记】
题目链接
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3954
题意
有一块 LED 灯
然后上面有七块灯管
在显示不同数字的时候 由灯管的开关组合 来表现一个数字
给出一个标准表
然后 输入 一个表
求这个表 的 列 是可以交换的
然后 判断能否有一种经过若干次交换后的情况
这个表能够跟 标准表 相同
如果能 就输出 YES
不能 就输出 NO
思路
我们可以用MAP 存下 标准表的列 和 输入的表 的列
然后判断一下 两个MAP 是否完全相同
然后 输入的时候 要用 scanf 用 int 保存 不然会 超时
AC代码
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <stack>
#include <set>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <limits>
#define CLR(a) memset(a, 0, sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair<string, int> psi;
typedef pair<string, string> pss;
const double PI = 3.14159265358979323846264338327;
const double E = exp(1);
const double eps = 1e-30;
const int INF = 0x3f3f3f3f;
const int maxn = 1e4 + 5;
const int MOD = 1e9 + 7;
int G[10][10];
int v[10][10];
struct Node
{
int n;
int v[10];
}q[10];
bool comp(Node x, Node y)
{
return x.n < y.n;
}
void init()
{
CLR(G);
G[1][1] = G[1][4] = G[1][5] = G[1][6] = G[1][7] = 1;
G[2][3] = G[2][6] = 1;
G[3][5] = G[3][6] = 1;
G[4][1] = G[4][4] = G[4][5] = 1;
G[5][2] = G[5][5] = 1;
G[6][2] = 1;
G[7][4] = G[7][5] = G[7][6] = G[7][7] = 1;
G[9][5] = 1;
}
int main()
{
init();
int t;
scanf("%d", &t);
while (t--)
{
CLR(v);
int n;
int arr[9];
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d", &q[i].n);
for (int j = 0; j < 7; j++)
scanf("%1d", &q[i].v[j]);
}
sort(q, q + n, comp);
map <int, int> vis[2];
int num = 0;
for (int i = 0; i < 7; i++)
{
num = 0;
for (int j = 0; j < n; j++)
{
num = num * 2 + q[j].v[i];
}
vis[0][num]++;
}
for (int i = 1; i <= 7; i++)
{
num = 0;
for (int j = 0; j < n; j++)
{
num = num * 2 + G[q[j].n][i];
}
vis[1][num]++;
}
map <int, int>::iterator it;
int flag = 1;
for (it = vis[0].begin(); it != vis[0].end(); it++)
{
if (vis[1][it->first] != it->second)
{
flag = 0;
break;
}
}
if (flag)
printf("YES\n");
else
printf("NO\n");
}
}
ZOJ - 3954 Seven-Segment Display 【状态标记】的更多相关文章
- ZOJ 3962 Seven Segment Display 16进制的八位数加n。求加的过程中所有的花费。显示[0,F]有相应花费。
Seven Segment Display Time Limit: Seconds Memory Limit: KB A seven segment display, or seven segment ...
- ZOJ 3962 Seven Segment Display
Seven Segment Display 思路: 经典数位dp 代码: #include<bits/stdc++.h> using namespace std; #define LL l ...
- zoj 3962 Seven Segment Display 数位dp
非常好的一个题,可以比赛时想到的状态太奇葩,不方便转移,就一直没能AC. 思路:dp(i, j)表示已经考虑了前i位,前i位的和为j的贡献.如果当前的选择一直是最大的选择,那么就必须从0~下一位的最大 ...
- ZOJ 3962 Seven Segment Display(数位DP)题解
题意:给一个16进制8位数,给定每个数字的贡献,问你贡献和. 思路:数位DP,想了很久用什么表示状态,看题解说用和就行,其他的都算是比较正常的数位DP. 代码: #include<iostrea ...
- ZOJ 3962 Seven Segment Display(数位DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目大意: 有t组数据. 给你一个n,和8位的十六进制数s ...
- 2017浙江省赛 E - Seven Segment Display ZOJ - 3962
地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3962 题目: A seven segment display, or ...
- ZOJ 3962 E.Seven Segment Display / The 14th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple E.数位dp
Seven Segment Display Time Limit: 1 Second Memory Limit: 65536 KB A seven segment display, or s ...
- (2017浙江省赛E)Seven Segment Display
Seven Segment Display Time Limit: 2 Seconds Memory Limit: 65536 KB A seven segment display, or ...
- Kattis - pizzahawaii 【状态标记】
Kattis - pizzahawaii [状态标记] Description You are travelling in a foreign country. Although you are al ...
- ZOJ - 3962 - Seven Segment Display-17省赛-数位DP
传送门:Seven Segment Display 题意:求一个给定区间每个数字的消耗值的和: 思路:数位DP,有点区间和的思想,还有就是这个十六进制,可以用%llx读,还是比较难的: 还有就是到最大 ...
随机推荐
- Codeforces 932 B.Recursive Queries-前缀和 (ICM Technex 2018 and Codeforces Round #463 (Div. 1 + Div. 2, combined))
B. Recursive Queries time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces 576D Flights for Regular Customers(矩阵加速DP)
题目链接 Flights for Regular Customers 首先按照$d$的大小升序排序 然后分成$m$个时刻,每条路径一次处理过来. $can[i][j]$表示当前时刻$i$能否走到$j ...
- 洛谷——P2404 自然数的拆分问题
题目背景 任何一个大于1的自然数n,总可以拆分成若干个小于n的自然数之和. 题目描述 任何一个大于1的自然数n,总可以拆分成若干个小于n的自然数之和. 输入输出格式 输入格式: 输入:待拆分的自然数n ...
- Remove Nth Node From End of List(链表,带测试代码)
Given a linked list, remove the nth node from the end of list and return its head. For example, Give ...
- Play框架的用户验证。
最近刚刚参与一个基于Play框架的管理平台的升级工作,其中涉及到了用户的验证工作.第一次接触play框架,直接看已有代码,有点晕.因此,自己实现了一个简单的用户验证功能. 首先,新建一个User类,包 ...
- Java创建和解析Json数据方法(二)——org.json包的使用
(二)org.json包的使用 1.简介 工具包org.json.jar,是一个轻量级的,JAVA下的json构造和解析工具包,它还包含JSON与XML, HTTP headers, Cookie ...
- Interface Builder中的技巧
在我工作中经常会遇到有人吐槽Xcode中的interface builder(以下简称IB)不好用的开发者.在我看来,IB是一个非常棒的可视化开发工具,可以非常快捷的设置UI控件的大部分常用属性.下面 ...
- Android GC 原理探究
导语 想写一篇关于 android GC 的想法来源于追查一个魅族手机图片滑动卡顿问题,由于不断的 GC 导致的丢帧卡顿的问题让我们想了很多方案去解决,所以就打算详细的看看内存分配和 GC 的原理,为 ...
- class文件无论是32位还是64位jdk编译出来的,都可以通用
class文件无论是32位还是64位jdk编译出来的,都可以通用 学习了:https://blog.csdn.net/z3111001358/article/details/53364066 java ...
- Flex4_Tree组件1(添加、删除、展开、关闭、右键菜单)
1.屏蔽系统菜单:工程目录“html-template”文件夹-->“index.template.html”文件中,在var params = {};语句下添加新语句: para ...