Codeforces 868C Qualification Rounds

探讨如何从大量问题中挑选合适的问题组合,确保参赛队伍已知问题不超过一半,通过高效的算法策略实现快速匹配。

time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Snark and Philip are preparing the problemset for the upcoming pre-qualification round for semi-quarter-finals. They have a bank of n problems, and they want to select any non-empty subset of it as a problemset.

k experienced teams are participating in the contest. Some of these teams already know some of the problems. To make the contest interesting for them, each of the teams should know at most half of the selected problems.

Determine if Snark and Philip can make an interesting problemset!

Input
The first line contains two integers n, k (1n105,1k4) — the number of problems and the number of experienced teams.

Each of the next n lines contains k integers, each equal to 0 or 1. The j-th number in the i-th line is 1 if j-th team knows i-th problem and 0 otherwise.

Output
Print “YES” (quotes for clarity), if it is possible to make an interesting problemset, and “NO” otherwise.

You can print each character either upper- or lowercase (“YeS” and “yes” are valid when the answer is “YES”).

Examples
input
5 3
1 0 1
1 1 0
1 0 0
1 0 0
1 0 0
output
NO

input
3 2
1 0
1 1
0 1
output
YES

Note
In the first example you can’t make any interesting problemset, because the first team knows all problems.

In the second example you can choose the first and the third problems.


初看很复杂,其实答案简单到让人怀疑人生。
这么说吧,因为1.是subset,2.对subset的大小没有要求,3.要求所有队都最多只会一半的题,那么就挑所有队要么都不会,要么只会其中一题的两题就好了。由于最多只会有4个队,于是每一题的情况最多只有16种:没有人会,只有第一个队会,只有第二个队会,只有第一和第二个队会,只有第三个队会,只有第一和第三个队会,etc……换言之就是0000 0001 0010 0011 0100 0101 etc……那么这样的两题(假设分别为a和b)必须有a^b==0,但是不可能直接两层for的,因为那是O(n2),n最大可以有105,这样会TLE。
于是便有了这样的策略:只要有0000,那么再来一题(无论是怎样的一题)就好;只要有0001,那么再来一题0010/0100/0110/1000/1010/1100/1110就好;etc。将题目情况转换为数字的操作,记录题目的有无都可以在输入的时候顺带进行;剩下的就O(1)了。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include <iterator>
#include<set>
using namespace std;
typedef long long ll;

int n,k;
int solved[100005];
bool has[16];
int nthbit[4] = {1,2,4,8};
bool nohas(){
    for(int i=1;i<16;i++){
        if(has[i])return false;
    }
    return true;
}
int main(){
    scanf("%d%d",&n,&k);
    int A = nthbit[k]-1;
    bool flag=false;
    for(int i=0;i<n;i++){
        for(int j=0;j<k;j++){
            int a; scanf("%d",&a);
            if(a==1)solved[i]|=nthbit[j];
        }
        has[solved[i]]=true;
    }
//     for(int i=0;i<n;i++)printf("%d ",solved[i]);printf("\n");
    if(
        has[0]&&(has[1]||has[2]||has[3]||has[4]||has[5]||has[6]||has[7]||has[8]||has[9]||has[10]||has[11]||has[12]||has[13]||has[14]||has[15])
        ||
        has[1]&&(has[2]||has[4]||has[6]||has[8]||has[10]||has[12]||has[14])
        ||
        has[2]&&(has[1]||has[4]||has[8]||has[5]||has[9]||has[12]||has[13])
        ||
        has[3]&&(has[4]||has[8]||has[12])
        ||
        has[4]&&(has[1]||has[2]||has[3]||has[8]||has[9]||has[10]||has[11])
        ||
        has[5]&&(has[2]||has[8]||has[10])
        ||
        has[6]&&(has[1]||has[8]||has[9])
        ||
        has[7]&&(has[8])
        ||
        has[8]&&(has[1]||has[2]||has[3]||has[4]||has[5]||has[6]||has[7])
        ||
        has[9]&&(has[2]||has[4]||has[6])
        ||
        has[10]&&(has[1]||has[4]||has[5])
        ||
        has[11]&&(has[4])
        ||
        has[12]&&(has[1]||has[2]||has[3])
        ||
        has[13]&&(has[2])
        ||
        has[14]&&(has[1])
        ||
        nohas()
    ) {flag=true;}
    printf((flag?"YES\n":"NO\n"));
    return 0;
}
内容概要:本文详细介绍了“秒杀商城”微服务架构的设计与实战全过程,涵盖系统从需求分析、服务拆分、技术选型到核心功能开发、分布式事务处理、容器化部署及监控链路追踪的完整流程。重点解决了高并发场景下的超卖问题,采用Redis预减库存、消息队列削峰、数据库乐观锁等手段保障数据一致性,并通过Nacos实现服务注册发现与配置管理,利用Seata处理跨服务分布式事务,结合RabbitMQ实现异步下单,提升系统吞吐能力。同时,项目支持Docker Compose快速部署和Kubernetes生产级编排,集成Sleuth+Zipkin链路追踪与Prometheus+Grafana监控体系,构建可观测性强的微服务系统。; 适合人群:具备Java基础和Spring Boot开发经验,熟悉微服务基本概念的中高级研发人员,尤其是希望深入理解高并发系统设计、分布式事务、服务治理等核心技术的开发者;适合工作2-5年、有志于转型微服务或提升架构能力的工程师; 使用场景及目标:①学习如何基于Spring Cloud Alibaba构建完整的微服务项目;②掌握秒杀场景下高并发、超卖控制、异步化、削峰填谷等关键技术方案;③实践分布式事务(Seata)、服务熔断降级、链路追踪、统一配置中心等企业级中间件的应用;④完成从本地开发到容器化部署的全流程落地; 阅读建议:建议按照文档提供的七个阶段循序渐进地动手实践,重点关注秒杀流程设计、服务间通信机制、分布式事务实现和系统性能优化部分,结合代码调试与监控工具深入理解各组件协作原理,真正掌握高并发微服务系统的构建能力。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值