Codeforces Round #613 (Div. 2) ABC 题解
A. Mezo Playing Zoma
题意:给你一个向右向左的指令,每个指令可以朝那个方向走一个单位,问你可以随意选出子序列来走,那可能到达的点有多少个。
思路:从范围上考虑就秒了。看最左和最右能到哪,然后加上原点就是所有可能的点数
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0',  ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
    ll n = read();
    string s;
    cin>>s;
    int l = 0, r = 0;
    for(int i=0; i<s.size(); i++)
    {
        if(s[i] == 'L') l++;
        else r++;
    }
    cout<<l+r+1<<endl;
    return 0;
}
B. Just Eat It!
题意:给你一个序列,问你所有的和是否严格大于所有子段(不包含[1,n]这个)的和。
思路:其实就是模板题。求一个最大字段和,同时记录开始和结束位置。若存在一个满足限制条件的最大字段和dp[i],则输出NO,反之输出YES。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0',  ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll dp[maxn];
ll a[maxn];
ll s[maxn];
ll t[maxn];
int main()
{
    int kase;
    cin>>kase;
    while(kase--)
    {
        ll n = read();
        rep(i,0,n+1) dp[i] = 0;
        ll sum = 0;
        rep(i,1,n) a[i] = read(), sum += a[i];
        ll st = 1, ed = 1;
        rep(i,1,n)
        {
            if(dp[i-1] + a[i] > a[i])
            {
                dp[i] = dp[i-1] + a[i];
                ed = i;
                s[i] = st, t[i] = ed;
            }
            else
            {
                dp[i] = a[i];
                s[i] = t[i] =  st = ed = i;
            }
        }
        int flag = 0;
        rep(i,1,n) if(dp[i]>=sum&&!(s[i]==1&&t[i]==n)) {flag=1; break;}
        puts(flag?"NO":"YES");
    }
    return 0;
}
C. Fadi and LCM
题意:问你找到一对(a,b),在满足 LCM(a,b) = X 的情况下找出max(a,b)最小的一对。
由于\(LCM(a,b)\) = \(ab\over gcd(a,b)\),所以当\(gcd(a,b)\)=1的时候能把ab限制的最小。所以只需要枚举一遍[1,\(\sqrt{x}\)]找到max(a,b)最小的对即可。
view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0',  ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
int main()
{
    ll x = read();
    ll m = sqrt(x*1.0);
    ll ansx = x, ansy = 1;
    rep(i,1,m)
    {
        if(x%i) continue;
        ll j = x/i;
        if(gcd(i,j)==1&&max(i,j)<max(ansx,ansy)) ansx = i, ansy = j;
    }
    cout<<ansx<<' '<<ansy<<'\n';
    return 0;
}
Codeforces Round #613 (Div. 2) ABC 题解的更多相关文章
- Codeforces Round #312 (Div. 2) ABC题解
		
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...
 - # Codeforces Round #529(Div.3)个人题解
		
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
 - Codeforces Round #557 (Div. 1) 简要题解
		
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
 - Codeforces Round #540 (Div. 3) 部分题解
		
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
 - Codeforces Round #538 (Div. 2) (A-E题解)
		
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
 - Codeforces Round #531 (Div. 3) ABCDEF题解
		
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
 - Codeforces Round #527 (Div. 3) ABCDEF题解
		
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
 - Codeforces Round #499 (Div. 1)部分题解(B,C,D)
		
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
 - Codeforces Round #366 (Div. 2) ABC
		
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
 - Codeforces Round #545 (Div. 1) 简要题解
		
这里没有翻译 Codeforces Round #545 (Div. 1) T1 对于每行每列分别离散化,求出大于这个位置的数字的个数即可. # include <bits/stdc++.h&g ...
 
随机推荐
- B站插入外站链接地址(现已禁用)
			
问题描述: B站中插入链接时,无法插入外站链接,提示[请输入正确的站内链接地址]: 日常文章编写中,经常需要插入外站链接跳转,以便于用户快速定位 分析: B站专栏文章编辑使用的富文本编辑器,应该是支持 ...
 - 在 Go 语言中,构造一个并发安全的 map 集合
			
Map 集合是 Go 中提供的一个 KV 结构的数据类型,对它的操作在实际的开发中应该是非常多的,不过它不是一个线程安全的. 1 .Map 不是线程安全的 编写下面的测试代码: func TestUn ...
 - 2025dsfz集训Day9:树状数组、LCA、RMQ
			
Day8 I:树状数组 \[Designed\ By\ FrankWkd\ -\ Luogu@Lwj54joy,uid=845400 \] \[特别感谢 此次课的主讲.图源侵删 \] 后记:关于本文的 ...
 - Elasticsearch7.6.1配套安装包自取
			
包含Elasticsearch,ik分词器,kibana 7.6.1安装包自取:https://pan.baidu.com/s/1Y6XdDOzqIzI2qerOODQHmg提取码:5nm4
 - Spring基于XML的事务管理器DataSourceTransactionManager
			
Spring基于XML的事务管理器DataSourceTransactionManager 源码 代码测试 pom.xml <?xml version="1.0" encod ...
 - DDD分层设计与异步职责划分:让你的代码不再“异步”混乱
			
title: DDD分层设计与异步职责划分:让你的代码不再"异步"混乱 date: 2025/05/04 00:18:53 updated: 2025/05/04 00:18:53 ...
 - 【HUST】网安|操作系统实验|实验四 设备管理、文件管理
			
文章目录 任务 任务1 编写一个Linux内核模块,并完成安装/卸载等操作. 1. 提示 2. 任务代码 3. 结果及说明 任务2 编写Linux驱动程序并编程应用程序测试. 1. 提示 2. 任务代 ...
 - vue3 基础-补充 ref & provide-inject
			
本篇主要对一些被以前内容(渲染, 传值) 等忽略的几个常用小技巧进行补充说明啦. v-once 即对某个dom节点生效, 其会限定只会渲染一次, 不论数据是如何的变化, 演示如下: <!DOCT ...
 - SQL 月同环比 日期 T+1 自动计算
			
对于离线数据的分析, 数据通常是 T+1 的, 即所有数据更新都是到 "昨天". 对于这样的同环比能自动计算是很需要的. -- 以Mysql为例: -- 今天: 2022/3/1 ...
 - 代码重构(OOP)-小栗子(PyQt5)
			
主要是为了练习下 面向对象, 不断提醒自己代码一定要写成 营销风格, 和优雅. 最近在B站上看一下关于 Python GUI 编程的内容. 恰好呢, 前不久的一个 将本地 Ecxcel 数据 发布到 ...