当前位置: 首页 > news >正文

AtCoder Beginner Contest 125 解题报告

 

那天晚上刚好有事就咕了。

最近的那一场E题还不会写。F题全场又只过了三个?留坑吧...

 

A - Biscuit Generator

#include <cstdio>
using namespace std;

inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

int main() {
    int a = read(), b = read(), t = read();   
    printf("%d\n", t / a * b);
    return 0;    
}
View Code

 

B - Resale

#include <cstdio>
#include <algorithm>
using namespace std;


inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

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

int main() {
    int sum = 0;
    int n = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    for (int i = 1, x; i <= n; i++) {x = read(), a[i] -= x; if (a[i] > 0) sum += a[i]; }
    printf("%d\n", sum);
    return 0;  
}
View Code

 

C - GCD on Blackboard

题意:给一个序列,能把其中一个数变成任意数,要求之后所有数字的GCD最大

思路:刚开始把所有质因子都求出来,然后 >= n - 1 的质因子相乘,可惜第三组样例就不过了。因为有的质因子不止一个。这种情况就比较麻烦了。

由于$C^{n-1}_{n} = n$ 题目相当于让你求任意$n - 1$个数中的GCD最大的那一组,所以所有答案的情况只有$n$种

开两个数组,$g1[i]$表示从1到$i$的GCD $g2[i]$表示$i$到$n$的GCD $ans=\max \left( \gcd \left( g_{1}\left[ i-1\right] ,g2\left[ i+1\right] \right) \right)$

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


inline int read() {
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

const int N = 1e5 + 10;
int g1[N], g2[N], a[N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    int n = read();
    for (int i = 1; i <= n; i++) a[i] = read();  
    g1[1] = a[1]; g2[n] = a[n];
    for (int i = 2, j = n - 1; i <= n; i++, j--) g1[i] = gcd(a[i], g1[i-1]), g2[j] = gcd(a[j], g2[j+1]);
   // for (int i = 1; i <= n; i++) printf("%d %d\n" , g1[i], g2[i]);
    int ans = max(g1[n], max(g1[n-1], g2[2]));
    for (int i = 2; i <= n; i++) {
        ans = max(gcd(g1[i-1], g2[i+1]), ans);
    }
    printf("%d\n", ans);
    return 0;
}
View Code

 

D - Flipping Signs

题意:一个序列,能进行$n$次操作,每次对$a_{i}$和$a_{i+1}$都乘上-1,求最后序列和最大

思路:首先从1开始往后,如果这一位小于0,那么对它和它后面的数乘上-1,这样到$n-1$位置,最后序列至多有一个为负,即$a_{n}$,如果$a_{n}$为负,就肯定可以把这个负号传递给绝对值最小的那个数字,如果为正就直接是答案了。

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

inline ll real() {
    ll x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
    return x * f;
}

const int N = 1e5 + 10;
ll a[N];

int main() {
    ll ans = 0;
    ll n = real();
    for (int i = 1; i <= n; i++) a[i] = real();
    for (int i = 1; i <= n - 1; i++) {
        if (a[i] < 0) a[i+1] *= -1, a[i] *= -1;
        ans += a[i];
    }     
    ans += a[n];
    ll temp = *min_element(a + 1, a + n);
    if (a[n] < 0) ans = max(ans, ans - 2 * a[n] - 2 * temp);
    printf("%lld\n", ans);
    return 0;
}            
View Code

 

转载于:https://www.cnblogs.com/Mrzdtz220/p/10884588.html

相关文章:

  • Kodi ‘Leia’ 18.2 最终版发布
  • 科略教育—企业管理运营八大基本法
  • 关于CSS
  • elasticsearch授权访问
  • Leetcode 12 - Integer to Roman
  • yum常用命令
  • AJPFX分享JAVA修饰符详解
  • 华华教奕奕写几何
  • 《零基础入门学习Python》【第一版】视频课后答案第001讲
  • Zabbix“专家坐诊”第10期问答汇总
  • LinkedList源码阅读分析
  • Spring全家桶视频教程
  • 【重点】米尔发布Zynq UltraScale MPSoC核心板
  • iOS QQ 登录
  • java版spring cloud+spring boot+redis多租户社交电子商务平台 (六)分布式配置中心(Spring Cloud Config)...
  • Angular4 模板式表单用法以及验证
  • es6要点
  • JavaScript 是如何工作的:WebRTC 和对等网络的机制!
  • JS+CSS实现数字滚动
  • Shadow DOM 内部构造及如何构建独立组件
  • SpiderData 2019年2月13日 DApp数据排行榜
  • 初探 Vue 生命周期和钩子函数
  • 从重复到重用
  • 函数式编程与面向对象编程[4]:Scala的类型关联Type Alias
  • 技术:超级实用的电脑小技巧
  • 前端面试之闭包
  • 前嗅ForeSpider教程:创建模板
  • 如何在GitHub上创建个人博客
  • 入职第二天:使用koa搭建node server是种怎样的体验
  • 算法之不定期更新(一)(2018-04-12)
  • 在GitHub多个账号上使用不同的SSH的配置方法
  • #include<初见C语言之指针(5)>
  • (14)Hive调优——合并小文件
  • (2)nginx 安装、启停
  • (C语言)fgets与fputs函数详解
  • (六)软件测试分工
  • (七)Knockout 创建自定义绑定
  • (学习日记)2024.04.10:UCOSIII第三十八节:事件实验
  • (原創) 未来三学期想要修的课 (日記)
  • ./indexer: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object fil
  • .net framwork4.6操作MySQL报错Character set ‘utf8mb3‘ is not supported 解决方法
  • .NET I/O 学习笔记:对文件和目录进行解压缩操作
  • .NET 中选择合适的文件打开模式(CreateNew, Create, Open, OpenOrCreate, Truncate, Append)
  • .net解析传过来的xml_DOM4J解析XML文件
  • /var/spool/postfix/maildrop 下有大量文件
  • @Bean有哪些属性
  • @EnableConfigurationProperties注解使用
  • @Transactional 竟也能解决分布式事务?
  • [2016.7 Day.4] T1 游戏 [正解:二分图 偏解:奇葩贪心+模拟?(不知如何称呼不过居然比std还快)]
  • [BT]小迪安全2023学习笔记(第15天:PHP开发-登录验证)
  • [C++基础]-初识模板
  • [Docker]十二.Docker consul集群搭建、微服务部署,Consul集群+Swarm集群部署微服务实战
  • [iOS]Win8下iTunes无法连接iPhone版本的解决方法
  • [Java基础]—JDBC
  • [JS入门到进阶] 前端开发不能写undefined?这是误区!