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读,还是比较难的: 还有就是到最大 ...
随机推荐
- 2017CCPC 哈尔滨 B
这题没有考虑到m这个东西,所以就没有往二分答案的方向想 二分答案 check的时候,我们找的是大于等于x的数有多少个被加入到那个数组中.如果 >= m说明这个数可能是答案,否则就不是. 用尺取来 ...
- SPOJ 7001 VLATTICE【莫比乌斯反演】
题目链接: http://www.spoj.com/problems/VLATTICE/ 题意: 1≤x,y,z≤n,问有多少对(x,y,z)使得gcd(x,y,z)=1 分析: 欧拉搞不了了,我们用 ...
- Light oj 1085 - All Possible Increasing Subsequences (简单dp + 离散化 + BIT)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1085 题意: 问你有多少个上升子序列. 思路: dp[i]表示以第i个数结尾的 ...
- awk在企业中最常用的语句
awk最常用以及面试基本都会被问到的实例: A.统计日志中每个URL被访问的次数 cat access.log http://www.etiantian.org/1.html http://post. ...
- sed理论讲解、实战
1.Sed是操作.过滤和转换文本内容的强大工具,常用功能有增删改查.过滤.取行. options(常用参数): -n:使用安静(silent)模式,在一般 sed 的用法中,所有来自 STDIN 的数 ...
- [CQOI2018] 社交网络
题目背景 当今社会,在社交网络上看朋友的消息已经成为许多人生活的一部分.通常,一个用户在社交网络上发布一条消息(例如微博.状态.Tweet等) 后,他的好友们也可以看见这条消息,并可能转发.转发的消息 ...
- Codeforces 401D Roman and Numbers
题目大意 Description 给定一个数 N(N<1018) , 求有多少个经过 N 重组的数是 M(M≤100) 的倍数. 注意: ①重组不能有前导零; ②重组的数相同, 则只能算一个数. ...
- Codeforces Beta Round #1 A. Theatre Square
从今天開始.就要在Codeforces里有一个新的開始了,貌似任务非常重的说~~ Codeforces专题我将会记录全部通过的题目,事实上仅仅要通过的题目都是水题啊!. 题目大意: 依照要求计算须要多 ...
- spoj 1811 LCS - Longest Common Substring (后缀自己主动机)
spoj 1811 LCS - Longest Common Substring 题意: 给出两个串S, T, 求最长公共子串. 限制: |S|, |T| <= 1e5 思路: dp O(n^2 ...
- ARP协议(1)什么是ARP协议
这是最近在看<TCP/IP具体解释>系列书总结出来的,之后会陆续把其它协议部分分享出来. 我尽量以简单易读.易懂的方式呈现出来,可是,因为文笔和水平有限.有些地方或许存在描写叙述上的不足或 ...