H - Bulbs

点击打开链接


Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?

If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.

Input

The first line of the input contains integers n and m (1 ≤ n, m ≤ 100) — the number of buttons and the number of bulbs respectively.

Each of the next n lines contains xi (0 ≤ xi ≤ m) — the number of bulbs that are turned on by the i-th button, and then xi numbers yij (1 ≤ yij ≤ m) — the numbers of these bulbs.

Output

If it's possible to turn on all m bulbs print "YES", otherwise print "NO".

Example
Input
3 4
2 1 4
3 1 3 1
1 2
Output
YES
Input
3 3
1 1
1 2
1 1
Output
NO
Note

In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp



分析:

保证后面的数字是不是1-n全有;(交的时候老是排列中,应该是对了)


代码:


#include<stdio.h>
#include<algorithm>
using namespace std;
int p[1000],a[1000],b[1000];
int main()
{int n,m,xi,l=0,k=0,i,j,flag,q=0;
scanf("%d%d",&n,&m);
for(i=0;i<n;i++)
{
scanf("%d",&xi);
for(int j=0;j<xi;j++)
scanf("%d",&a[l++]);
}
for(int i=0;i<l;i++)
{
flag=1;
for(int j=0;j<i;j++)
if(b[j]==a[i])
flag=0;
if(flag)
b[k++]=a[i];
}
if(k<m)
printf("NO");
else printf("YES");

return 0;
}


#!/usr/bin/env python3 # -*- coding: utf-8 -*- import time import logging import sys from os import path import xml.etree.ElementTree as ET from typing import List from concurrent.futures import ThreadPoolExecutor, as_completed import datetime, os # ========== 基础模块 ========== from VigiIpcControl import VigiIpcControl from HKIpcControl import HKIpcControl from DHIpcControl import DHIpcControl from SmartBulbBatchCtrl import SmartBulbBatchCtrl from CarSerialCtrl import CarSerialCtrl from VigiVideo import VigiVideo from log_config import Log import xlrd # --------------------- 日志 ------------------- timestamp = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") log_filename = f"{timestamp}_diff_Lux.log" logger = Log(name=log_filename, log_level=logging.INFO) # ----------- 灯泡配置 ----------- bulb_config_path = r'E:\dcc\实验室资料\ControlScript\Light_Contrl\BulbConfigArea1.xls' bulb_config_table = 'config' nic_ip = '192.168.0.11' # 读取智能灯泡配置表格 workbook = xlrd.open_workbook(bulb_config_path) table = workbook.sheet_by_name(bulb_config_table) # 创建列值索引map row0_value = table.row_values(0) column_index_map = {} index = 0 for item in row0_value: column_index_map[item] = index index = index+1 # 创建智能灯泡配置map bulb_config_map = {} bulb_index_map = {} rowc = table.nrows for row in range(1, rowc): row_value = table.row_values(row) bulb_config_map[row_value[column_index_map['location']]] = {'ip':row_value[column_index_map['ip']], \ 'type':row_value[column_index_map['type']], \ 'username':row_value[column_index_map['username']], \ 'password':row_value[column_index_map['password']]} bulb_index_map[row_value[column_index_map['location']]] = int(row_value[column_index_map['index']]) def build_rows(start: int, end: int, j_start: int = 1, j_end: int = 5): """生成 ['i_j', ...] 列表,i∈[start,end), j∈[j_start,j_end)""" return ['%d_%d' % (i, j) for i in range(start, end) for j in range(j_start, j_end)] # 形成灯泡字典 def get_bulb_conf_list(bulb_loc_list=[], bulb_config_map=None): bulb_conf_list = [] for loc in bulb_loc_list: bulb_conf_list.append(bulb_config_map[loc]) return bulb_conf_list def _init_one(ctrl_list=None, nic_ip=nic_ip, brightness=None, color_temp=None, on_off=None, max_fail=6): """ 批量控制灯泡(亮度/色温/开关),直到全部成功或某设备连续失败 max_fail 次被永久跳过。 :param ctrl_list: 初始灯泡列表 [{'ip': 'x.x.x.x', ...}, ...] :param nic_ip: 本地网卡 IP :param brightness: 亮度 0-100 :param color_temp: 色温 2700-6500 :param on_off: 开关 0/1 :param max_fail: 单个 IP 最大允许连续失败次数 """ if ctrl_list is None: ctrl_list = [] # 1) 记录每个 IP 连续失败次数 fail_counter = {item['ip']: 0 for item in ctrl_list} for rnd in range(10): print(f'round {rnd} ctrl_list={ctrl_list}') if not ctrl_list: # 全部成功或被跳过 break try: # 2) 本轮批量控制 bulb_control = SmartBulbBatchCtrl.SmartBulbBatchCtrl(bulb_list=ctrl_list, nic_ip=nic_ip) batch_ctrl = bulb_control.batch_ctrl_bulbs(brightness=brightness, color_temp=color_temp, on_off=on_off) success_ip_set = set(batch_ctrl["batch_ctrl_success_list"]) except Exception as e: logger.warning(f"灯泡控制异常/超时,本轮当全部失败: {e}") success_ip_set = set() # 空集 = 全部失败 # 3) 更新失败计数 & 剔除永远失败的设备 new_ctrl_list = [] for item in ctrl_list: ip = item['ip'] if ip in success_ip_set: fail_counter[ip] = 0 # 成功清零 else: fail_counter[ip] += 1 if fail_counter[ip] < max_fail: new_ctrl_list.append(item) else: logger.warning(f'[SKIP] {ip} 连续失败 {max_fail} 次,永久跳过') ctrl_list = new_ctrl_list def _init_one_close(ctrl_list=None, nic_ip=nic_ip, max_fail=6): """ 批量关灯,直到全部成功或某设备连续失败 max_fail 次被永久跳过。 :param ctrl_list: 初始灯泡列表 [{'ip': 'x.x.x.x', ...}, ...] :param nic_ip: 本地网卡 IP :param max_fail: 单个 IP 最大允许连续失败次数 """ if ctrl_list is None: ctrl_list = [] # 1) 记录每个 IP 连续失败次数 fail_counter = {item['ip']: 0 for item in ctrl_list} for rnd in range(10): print(f'round {rnd} ctrl_list={ctrl_list}') try: # 2) 本轮批量关灯 bulb_control = SmartBulbBatchCtrl(bulb_list=ctrl_list, nic_ip=nic_ip) batch_ctrl = bulb_control.batch_ctrl_bulbs(on_off=0) success_ip_set = set(batch_ctrl["batch_ctrl_success_list"]) except Exception as e: logger.warning(f"灯泡控制异常/超时,本轮当全部失败: {e}") success_ip_set = set() # 空集 = 全部失败 # 3) 更新失败计数 & 剔除永远失败的设备 new_ctrl_list = [] for item in ctrl_list: ip = item['ip'] if ip in success_ip_set: fail_counter[ip] = 0 # 成功就清零 new_ctrl_list.append(item) # 成功后一般就不再需要继续关了,这里保留仅作演示 else: fail_counter[ip] += 1 if fail_counter[ip] < max_fail: new_ctrl_list.append(item) else: logger.info(f'[SKIP] {ip} 连续失败 {max_fail} 次,永久跳过') ctrl_list = new_ctrl_list if not ctrl_list: # 全部成功或被跳过 break # --------------------------- 初始化IPC配置信息 ----------------------------------- # 读取设备配置文件,返回配置信息+py路径信息字典 def start_test_get_config(): logging.debug('加载配置文件.........') element_dict = {} if hasattr(sys, 'frozen'): py_path = path.dirname(sys.executable) else: py_path = path.dirname(__file__) # 添加py文件或exe文件所在路径 element_dict["py_path"] = py_path # 读取配置文件 xml_path = path.join(py_path, 'ipc_test_info.xml') info_tree = ET.parse(xml_path) root = info_tree.getroot() # 加载根节点 element_name = root.iter() # 遍历根节点所有后代 for e in element_name: if e.attrib and e.attrib["load"] == "False": logging.debug(f"节点{e.tag}:{e.text}属性为False,不加载") else: element_dict[e.tag] = e.text logging.debug('加载配置文件结束......') return element_dict config =start_test_get_config() # 初始化小车 car = CarSerialCtrl.CarControl(logger=logger, port="COM5") # 初始化设备 vigi_ipc = VigiIpcControl.VigiIpcControl(config) vigi_video = VigiVideo.VigiVideo(config) hk_ipc = HKIpcControl.HKIpcControl(config) hk_ipc.hk_start_test_web() dh_ipc = DHIpcControl.DHIpcControl(config) dh_ipc.dh_start_test_web() # # 初始化窗帘 # cur4 = SmartCurtainsCtrl.CurtainsCtrl(4, 'com2') # cur2 = SmartCurtainsCtrl.CurtainsCtrl(2, 'com2') # 登录设备,初始化 vigi_ipc.vigi_start_test_tdcp() vigi_ipc.image_restore() # 关闭补光灯,防止环境过暗导致补光灯打开 vigi_ipc.close_light() time.sleep(2) hk_ipc.day_mode() time.sleep(2) hk_ipc.close_white() dh_ipc.off_supplement(mode="Off", light_type="IR") # ---------------- 工具函数 ---------------- def open_ir(): try: vigi_ipc.open_ir() hk_ipc.night_mode() hk_ipc.close_ir() dh_ipc.day_night_mode(mdoe='IR') dh_ipc.off_supplement() except Exception as e: logger.warning("打开补光灯时出现异常%s" % e) def close_ir(): try: vigi_ipc.close_light() hk_ipc.day_mode() hk_ipc.close_ir() dh_ipc.day_night_mode(mode='Color') dh_ipc.off_supplement() except Exception as e: logger.warning("关闭补光灯时出现异常%s" %e) # 截图函数 def ipc_capture(filename): try: vigi_video.capture(custom_name=filename) hk_ipc.capture() dh_ipc.capture() except Exception as e: logger.warning("截图过程中发生异常{e},请检查图片") # 录像开始 def ipc_record_start(filename): try: vigi_video.record_start(output_file=filename) hk_ipc.record_start() dh_ipc.record_start() except Exception as e: logger.warning("启动录像过程中发生异常{e},请检查录像") # 录像停止 def ipc_record_stop(): try: vigi_video.record_stop() hk_ipc.record_stop() dh_ipc.record_stop() except Exception as e: logger.warning("结束录像过程中发生异常{e},请检查录像") def stop_test(): dh_ipc.close_web() hk_ipc.close_web() # 小车归位 def car_move_to_home(): car.go_to_site(1) # 小车停止 def car_stop(): car.stop() #小车运动 def car_video_track(): cur = car.get_car_status()['current_site'] if cur == 0: car.set_current_site(1) for i in range(2): car.set_speed(100) car.go_to_site(1) time.sleep(2) car.go_to_site(4) time.sleep(2) car.go_to_site(1) car.go_to_site(1) time.sleep(1) def main(): logger.info("---------------------------------------IPC day_mode_illumin_change测试---------------------------------------") ipc_capture('ir_mode_illumin_change') ipc_record_start('ir_mode_illumin_change') time.sleep(15) open_ir() #将第一排灯光持续调整至低亮并关闭 lx_2 = build_rows(1,2, 1,9) lx_list2 = get_bulb_conf_list(bulb_loc_list=lx_2, bulb_config_map=bulb_config_map) _init_one(ctrl_list=lx_list2, brightness=10, color_temp=6500, on_off=1, max_fail=2) _init_one(ctrl_list=lx_list2, brightness=1, color_temp=6500, on_off=1, max_fail=2) _init_one(ctrl_list=lx_list2, brightness=1, color_temp=6500, on_off=0) #再次开启第一排灯光,随后关闭灯光 _init_one(ctrl_list=lx_list2, brightness=50, color_temp=6500, on_off=1, max_fail=5) _init_one(ctrl_list=lx_list2, brightness=50, color_temp=6500, on_off=0, max_fail=5) ipc_record_stop() logger.info("------------------红外模式下的曝光收敛测试完成------------------") if __name__ == "__main__": try: main() except KeyboardInterrupt: logging.debug("用户中断,退出") finally: stop_test() all_bulb_list = build_rows(1,13, 1,9) all_bulb = get_bulb_conf_list(bulb_loc_list=all_bulb_list, bulb_config_map=bulb_config_map) _init_one_close(ctrl_list=all_bulb) car_move_to_home() car.stop() 我有如上的代码,现在我想对它进行优化,主要是是为了能够争对hk_ipc和dh_ipc的控制做优化,我会从config =start_test_get_config()中读出多个大华摄像头IP和海康IP,现在我想要能够保证后续的对海康大华的这些样机做同样的操作,如截图、录像等,该如何优化
12-10
The ICPC world finals will be held in a luxurious hotel with a big ballroom. A buffet meal will be served in this ballroom, and organizers decided to decorate its walls with pictures of past champion teams. In order to avoid criticism about favouring some of those teams over others, the organizing commitee wants to make sure that all pictures are appropiately illuminated. The only direct way they’ve found for doing this is ensuring each picture has at least one lightbulb that directly illuminates it. In this way, the perimeter of the ballroom wall can be divided into illuminated parts (in which pictures may be placed) and dark parts (which are not suitable for placing the pictures). The ballroom has the shape of a box and contains several lightbulbs. Each lightbulb emits light in all directions, but this light can be blocked by columns. All columns in the ballroom have cylindrical shape and go from the floor to the ceiling, so light cannot pass over or above them. Columns are of course placed so that its circular section is parallel to the ballroom floor. Any given point p on the perimeter wall is said to be illuminated if there exists a line segment (a light ray) which starts on a lightbulb, ends in p and does not touch or pass through any column. Your task as a helper of the ICPC organization is to examine the blueprints of the ballroom and determine the total length of illuminated sections of the perimeter wall. The blueprint consist of a rectangle indicating a top view of the ballroom, with the lightbulbs and columns marked in it. 输入 Each test case will consist on several lines. The first line will contain four integers: L, the number of lightbulbs, C, the number of columns, X, the size of the ballroom on the x coordinate and Y , the size of the ballroom on the y coordinate. The lower-left corner of the ballroom is at (0, 0) while the upper-right corner is at (X, Y ). The next L lines will contain two integers each representing the x and y coordinate of each lightbulb. The last C lines of the test case will contain three integers each, representing the x and y coordinates of the center of a column and its radius, in that order. You can assume that 1 <= L,C <= 103 and 4 <= X, Y <= 106. Also, for all pairs of coordinates (x,y), 0 < x < X and 0 < y < Y , both for lightbulbs and column center locations. All radii of the columns will be positive. Finally, no two columns will overlap, although they may touch, and no column will touch or intersect with the border of the ballroom. No lightbulb will be inside a column or in its boundary and no two lightbulbs will be in the same place. Input is terminated with L = C = X = Y = 0. 输出 For each test case, output a single line with the total length of the illuminated parts of the perimeter wall. The result must be printed as a real number with exactly four decimal figures, with the lowest-order decimal figure rounded up. 样例输入 2 1 8 8 6 6 2 6 4 4 2 1 4 7 7 3 3 2 4 1 4 2 1 2 2 1 4 4 1 2 2 9 7 1 2 5 5 3 3 2 7 5 1 0 0 0 0 ⧉ 样例输出 28.0000 0.0000 25.8214 ⧉ 题目来源 用巧思
11-01
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值