CF - 359 - A. Table(贪心)

本文提供了一道 CodeForces 上的经典题目 359A 的解题思路与代码实现。该题目标是在一个 n*m 的矩阵中,通过特定规则将所有格子涂色,讨论了不同情况下所需的最小涂色步骤。

题意:n * m的格子,每次取标记为1的点与一个角的矩形区域涂色,问最少需要多少步将这n*m个格子涂完(3 ≤ n, m ≤ 50,4个角不会出现1)。

题目链接:http://codeforces.com/problemset/problem/359/A

——>>如果边上有1,那么只要2次,如果边上没1,要4次。

#include <cstdio>

using namespace std;

int main()
{
    int n, m, c;
    while(scanf("%d%d", &n, &m) == 2) {
        bool ok = 0;
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) {
                scanf("%d", &c);
                if((i == 1 || i == n || j == 1 || j == m) && c == 1) ok = 1;
            }
        ok ? puts("2") : puts("4");
    }
    return 0;
}


2025-11-27 11:45:42:270-----------任务执行开始,任务id 1032,执行id:0a66ef8fb57c4daa936601176f8cf4e8 ------------- 2025-11-27 11:46:10:234-构建输入组件开始 2025-11-27 11:46:10:235-构建databasemeta结束 2025-11-27 11:46:10:236-抽取的sql select TRANSACTION_ID, PRO_NAME, BLAST, MAT_CODE, MAT_NAME, AMOUNT, UNITE, TL_DATE, CREATED_BY_CODE, CREATED_BY_NAME, CREATION_DATE, SG_SIGN from cux_hbis_qmys_touliao_date_v 2025-11-27 11:46:10:237-构建输入组件结束 2025-11-27 11:46:10:241-outputStep:csv output-1032 2025-11-27 11:46:10:241-最后的步骤:table input-1032 2025/11/27 11:46:10 - table input-1032.0 - ERROR (version 7.1.0.0-12, build 1 from 2017-05-16 17.18.02 by buildguy) : Unexpected error 2025/11/27 11:46:10 - table input-1032.0 - ERROR (version 7.1.0.0-12, build 1 from 2017-05-16 17.18.02 by buildguy) : org.pentaho.di.core.exception.KettleDatabaseException: 2025/11/27 11:46:10 - table input-1032.0 - An error occurred executing SQL: 2025/11/27 11:46:10 - table input-1032.0 - select 2025/11/27 11:46:10 - table input-1032.0 - TRANSACTION_ID, 2025/11/27 11:46:10 - table input-1032.0 - PRO_NAME, 2025/11/27 11:46:10 - table input-1032.0 - BLAST, 2025/11/27 11:46:10 - table input-1032.0 - MAT_CODE, 2025/11/27 11:46:10 - table input-1032.0 - MAT_NAME, 2025/11/27 11:46:10 - table input-1032.0 - AMOUNT, 2025/11/27 11:46:10 - table input-1032.0 - UNITE, 2025/11/27 11:46:10 - table input-1032.0 - TL_DATE, 2025/11/27 11:46:10 - table input-1032.0 - CREATED_BY_CODE, 2025/11/27 11:46:10 - table input-1032.0 - CREATED_BY_NAME, 2025/11/27 11:46:10 - table input-1032.0 - CREATION_DATE, 2025/11/27 11:46:10 - table input-1032.0 - SG_SIGN 2025/11/27 11:46:10 - table input-1032.0 - 2025/11/27 11:46:10 - table input-1032.0 - from cux_hbis_qmys_touliao_date_v 2025/11/27 11:46:10 - table input-1032.0 - ORA-00904: "SG_SIGN": invalid identifier 2025/11/27 11:46:10 - table input-1032.0 - 2025/11/27 11:46:10 - table input-1032.0 - 2025/11/27 11:46:10 - table input-1032.0 - at org.pentaho.di.core.database.Database.openQuery(Database.java:1778) 2025/11/27 11:46:10 - table input-1032.0 - at org.pentaho.di.trans.steps.tableinput.TableInput.doQuery(TableInput.java:236) 2025/11/27 11:46:10 - table input-1032.0 - at org.pentaho.di.trans.steps.tableinput.TableInput.processRow(TableInput.java:140) 2025/11/27 11:46:10 - table input-1032.0 - at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62) 2025/11/27 11:46:10 - table input-1032.0 - at java.lang.Thread.run(Thread.java:748) 2025/11/27 11:46:10 - table input-1032.0 - Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "SG_SIGN": invalid identifier 2025/11/27 11:46:10 - table input-1032.0 - 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:193) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:873) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1491) 2025/11/27 11:46:10 - table input-1032.0 - at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:406) 2025/11/27 11:46:10 - table input-1032.0 - at org.pentaho.di.core.database.Database.openQuery(Database.java:1767) 2025/11/27 11:46:10 - table input-1032.0 - ... 4 more 2025/11/27 11:46:10 - table input-1032.0 - Finished reading query, closing connection. 2025/11/27 11:46:10 - table input-1032.0 - 完成处理 (I=0, O=0, R=0, W=0, U=0, E=1) 2025/11/27 11:46:10 - ERROR (version 7.1.0.0-12, build 1 from 2017-05-16 17.18.02 by buildguy) : 错误被检测到! 2025/11/27 11:46:10 - 转换被检测 2025/11/27 11:46:10 - 转换正在杀死其他步骤! 2025/11/27 11:46:11 - ERROR (version 7.1.0.0-12, build 1 from 2017-05-16 17.18.02 by buildguy) : 错误被检测到! 2025-11-27 11:46:11:470------------任务底层逻辑执行完毕,任务id:1032 --------- 2025-11-27 11:46:11:470-------任务运行失败,任务id:1032 --------- 2025-11-27 11:46:11:479-task fail id=1032 delete localfile csvPath=task-monitor/template/csvOutput/17821.csv delete result=true 2025-11-27 11:46:11:481-任务:1032 运行结束,结果为:fail
最新发布
11-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值