每日两题day59

今天你AC了吗?

每日两题day59


一、基础题

题目:P1421 小玉买文具 - 洛谷

思路:

涉及多种进制的题目都可以全部拆成最小的单位再处理。

代码:

cpp 复制代码
#include <bits/stdc++.h>
int main() {
    int a, b, sum = 0;
    std::cin >> a >> b;
    sum = a * 10 + b;
    std::cout << (sum / 19);
    return 0;
}

二、提高题

题目:P2615 NOIP 2015 提高组 神奇的幻方 - 洛谷

思路:

纯模拟,按题目来的写判别函数就好了

代码:

cpp 复制代码
#include <bits/stdc++.h>

int n = 40, i = 1;
std::vector<std::vector<int>> a(n, std::vector<int>(n));

std::pair<int, int> next(std::pair<int, int> b) {
    if (b.first == 0 && b.second != n - 1) {
        return {n - 1, b.second + 1};
    }
    if (b.second == n - 1 && b.first != 0) {
        return {b.first - 1, 0};
    }
    if (b.first == 0 && b.second == n - 1) {
        return {1, n - 1};
    }
    if (b.first - 1 >= 0 && b.second + 1 < n && a[b.first - 1][b.second + 1] == 0) {
        return {b.first - 1, b.second + 1};
    } else {
        return {b.first + 1, b.second};
    }
}

int main() {
    std::pair<int, int> before;
    std::cin >> n;

    a[0][n / 2] = 1;
    before = {0, n / 2};
    while (++i <= n * n) {
        before = next(before);
        a[before.first][before.second] = i;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            std::cout << a[i][j] << " ";
        }
        std::cout << "\n";
    }
    return 0;
}
相关推荐
m0_639906946 小时前
Redis入门|五种数据结构、使用场景、持久化RDB&AOF
数据结构·数据库·redis
Sakura_j_h_7 小时前
EasyEDA PCB 快速设计Skills
c++·python·github
ZhengEnCi7 小时前
Agent 架构怎么选:从单 Agent 到多 Agent 编排的选型决策指南
算法·架构
程序喵大人7 小时前
【C++入门】内存模型与资源管理 - 09 shared_ptr 和 weak_ptr 解决共享,也带来代价
开发语言·c++·资源管理·智能指针·内存模型
秋天的怀念_David8 小时前
第二十二夜 · 数字迷雾
java·程序人生·算法
Pniubi8 小时前
力扣283移动零(双指针法)
算法·leetcode·职场和发展
hhb_6188 小时前
大模型落地三重优化实战
人工智能·算法·机器学习
云和数据.ChenGuang8 小时前
光哥说Python RAG 系统需要哪些评估指标:从检索到生成的全链路评测指南
网络·人工智能·python·算法·langchain
jimy19 小时前
C++ 中的 `T&&`:右值引用与转发引用
开发语言·c++
2601_9707038310 小时前
工业除湿机租赁:把一份租金合同拆开看
大数据·数据结构·算法·数据库架构·推荐算法