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;
}
【直流微电网】径向直流微电网的状态空间建模与线性化:一种耦合DC-DC变换器状态空间平均模型的方法 (Matlab代码实现)内容概要:本文介绍了径向直流微电网的状态空间建模与线性化方法,重点提出了一种基于耦合DC-DC变换器状态空间平均模型的建模策略。该方法通过对系统中多个相互耦合的DC-DC变换器进行统一建模,构建出整个微电网的集中状态空间模型,并在此基础上实施线性化处理,便于后续的小信号分析与稳定性研究。文中详细阐述了建模过程中的关键步骤,包括电路拓扑分析、状态变量选取、平均化处理以及雅可比矩阵的推导,最终通过Matlab代码实现模型仿真验证,展示了该方法在动态响应分析和控制器设计中的有效性。; 适合人群:具备电力电子、自动控制理论基础,熟悉Matlab/Simulink仿真工具,从事微电网、新能源系统建模与控制研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①掌握直流微电网中多变换器系统的统一建模方法;②理解状态空间平均法在非线性电力电子系统中的应用;③实现系统线性化并用于稳定性分析与控制器设计;④通过Matlab代码复现和扩展模型,服务于科研仿真与教学实践。; 阅读建议:建议读者结合Matlab代码逐步理解建模流程,重点关注状态变量的选择与平均化处理的数学推导,同时可尝试修改系统参数或拓扑结构以加深对模型通用性和适应性的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值