CF#803 A. Maximal Binary Matrix(贪心)

本篇介绍如何在给定的n*n零矩阵中填充k个1,使之成为关于主对角线对称且字典序最大的矩阵。文章包含输入输出样例及解决思路。
A. Maximal Binary Matrix
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.

One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.

If there exists no such matrix then output -1.

Input

The first line consists of two numbers n and k (1 ≤ n ≤ 1000 ≤ k ≤ 106).

Output

If the answer exists then output resulting matrix. Otherwise output -1.

Examples
input
2 1
output
1 0 
0 0 
input
3 2
output
1 0 0 
0 1 0 
0 0 0 
input
2 5
output

-1


题意:给出一个 n * n 的0矩阵,添加 k 个 1使其变为对称矩阵


#include <bits/stdc++.h>
using namespace std;

const int N = 100 + 10;
int a[N][N];

int main()
{
    int n, k;
    while(scanf("%d%d", &n, &k) == 2)
    {
        memset(a, 0, sizeof(a));
        if(n * n < k)
        {
            printf("-1\n");
            continue ;
        }
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < n; j++)
            {
                if(!a[i][j])
                {
                    if(k && i == j) k--, a[i][j] = 1;
                    else if(k >= 2) k -= 2, a[i][j] = a[j][i] = 1;
                }
                printf("%d%c", a[i][j], j < n - 1 ? ' ' : '\n');
            }
        }
    }
}


在 Postfix 邮件服务器中,`main.cf` 是主配置文件,用于定义全局参数和运行时行为。了解其关键配置项对于正确部署和管理邮件服务至关重要。 ### 主要配置参数 #### 1. 基本设置 - `myhostname`:指定邮件服务器的主机名,通常应与 DNS 中的 A 记录和 PTR 记录一致。 - `mydomain`:指定本地域名,通常为 `myhostname` 的域名部分。 - `myorigin`:定义邮件发送时使用的源地址,默认值可以是 `$myhostname` 或 `$mydomain`。 - `inet_interfaces`:定义监听的网络接口,可设置为 `all` 或 `loopback-only`。 - `mydestination`:定义本地接收邮件的目标域列表,包含 `$myhostname`、`localhost.$mydomain` 等。 #### 2. 客户端访问控制 - `mynetworks`:定义哪些网络或 IP 地址可以无认证地通过该服务器发送邮件。例如:`192.168.0.0/24, 127.0.0.0/8`。 - `smtpd_client_restrictions`:定义客户端连接限制规则,如 `permit_mynetworks`, `reject_unknown_client_hostname` 等。 #### 3. 身份验证与安全 - `smtpd_sasl_type`:定义 SASL 认证类型,常用值为 `dovecot`。 - `smtpd_sasl_path`:SASL 认证路径,例如:`private/auth`。 - `smtpd_sasl_auth_enable`:启用 SASL 认证,设置为 `yes`。 - `broken_sasl_auth_clients`:兼容旧版客户端,建议设置为 `yes`。 - `smtpd_recipient_restrictions`:定义收件人限制规则,如 `permit_sasl_authenticated`, `permit_mynetworks`, `reject_unauth_destination` 等。 #### 4. TLS 加密设置 - `smtpd_tls_cert_file` 和 `smtpd_tls_key_file`:分别指定 TLS 证书和私钥的路径。 - `smtpd_use_tls`:启用 TLS 加密,设置为 `yes`。 - `smtpd_tls_security_level`:定义 TLS 安全级别,如 `may` 或 `encrypt`。 - `smtp_tls_security_level`:定义对外发送邮件时的 TLS 安全策略。 #### 5. 虚拟用户与数据库支持 - `virtual_mailbox_domains`:定义虚拟邮箱域,例如使用 MySQL 数据库存储信息:`mysql:/etc/postfix/mysql_virtual_domains_maps.cf`。 - `virtual_mailbox_maps`:定义虚拟邮箱映射,如 `mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf`。 - `virtual_alias_maps`:定义虚拟别名映射,如 `mysql:/etc/postfix/mysql_virtual_alias_maps.cf`。 - `smtpd_sender_login_maps`:定义发件人登录映射,可用于限制用户只能使用特定邮箱地址发送邮件,如 `mysql:/etc/postfix/mysql_virtual_sender_maps.cf`[^4]。 #### 6. 日志与调试 - `debug_peer_level`:定义对等节点的调试日志详细程度,默认值为 `2`。 - `debugger_command`:定义调试命令路径,适用于高级调试场景。 - `command_directory`:Postfix 命令工具的安装目录,默认为 `/usr/sbin`。 - `daemon_directory`:Postfix 守护进程的安装目录,默认为 `/usr/libexec/postfix/`[^3]。 #### 7. 队列与性能优化 - `queue_directory`:定义邮件队列的存储目录,默认为 `/var/spool/postfix`。 - `maximal_queue_lifetime`:定义邮件在队列中的最大存活时间,默认为 `4d`(四天)。 - `bounce_notice_recipient`:定义退信通知的收件人地址。 - `delay_warning_time`:定义延迟警告的时间阈值,默认为 `0h`(不发送延迟警告)。 #### 8. 其他重要参数 - `alias_database` 和 `alias_maps`:定义系统别名数据库,通常指向 `/etc/aliases` 文件,并通过 `newaliases` 命令更新。 - `transport_maps`:定义邮件传输路由,如将特定域的邮件转发到外部 SMTP 服务器。 - `relayhost`:定义默认的邮件中继服务器,适用于需要通过外部 SMTP 发送邮件的场景。 - `header_checks`:定义邮件头检查规则,可用于过滤垃圾邮件或修改邮件内容。 ### 配置更改后的操作 当对 `main.cf` 进行更改后,必须手动执行 `postfix reload` 命令以重新加载配置。这是因为 `master(8)` 服务器不会自动检测配置文件的变化。此外,可以通过 `postconf -n` 查看当前生效的配置参数,确保更改已正确应用[^2]。 ### 示例代码片段 以下是一个简单的 `main.cf` 配置示例: ```bash # 基础设置 myhostname = mail.example.com mydomain = example.com myorigin = $mydomain inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost # 网络与访问控制 mynetworks = 192.168.0.0/24, 127.0.0.0/8 smtpd_client_restrictions = permit_mynetworks, reject_unknown_client_hostname # SASL 认证 smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes broken_sasl_auth_clients = yes smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination # TLS 设置 smtpd_tls_cert_file = /etc/pki/tls/certs/mail.example.com.crt smtpd_tls_key_file = /etc/pki/tls/private/mail.example.com.key smtpd_use_tls = yes smtpd_tls_security_level = may smtp_tls_security_level = encrypt # 虚拟用户支持 virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf smtpd_sender_login_maps = mysql:/etc/postfix/mysql_virtual_sender_maps.cf # 别名与队列 alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases queue_directory = /var/spool/postfix ``` ### 调试与问题排查 如果需要更详细的日志输出,可以在启动 Postfix 程序时添加 `-V` 参数来提高日志的详细程度。此外,`-D` 参数可用于生成调试信息,以便配合调试器进行分析。关于更深入的调试方法,可参考 Postfix 包附带的 `DEBUG_README` 文档[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值