A. Stone Game

思路:总共3种情况,都从最左端被拿走,都从最右端被拿走,左侧的从最左端被拿走且右侧的从最右端被拿走,取最小值即可

代码:

//CF-725.A
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec; #define INF 0x3f3f3f3f
const double EPS = 1e-18;
const int MOD = 1e9 + 7;
const int maxn = 8e4 + 1; int T;
int N, A[maxn]; void solve()
{
int maxi = -1, mini = -1, maxa = -1, mina = INF;
for (int i = 0; i < N; i++)
{
if (A[i] < mina)
{
mina = A[i];
mini = i;
}
if (A[i] > maxa)
{
maxa = A[i];
maxi = i;
}
}
if (mini < maxi)
{
int ans[3];
ans[0] = mini + 1 + N - maxi;
ans[1] = max(mini, maxi) + 1;
ans[2] = N - min(mini, maxi);
int res = INF;
for (int i = 0; i < 3; i++)
res = min(res, ans[i]);
cout << res << endl;
return;
}
else
{
int ans[3];
ans[0] = maxi + 1 + N - mini;
ans[1] = max(mini, maxi) + 1;
ans[2] = N - min(mini, maxi);
int res = INF;
for (int i = 0; i < 3; i++)
res = min(res, ans[i]);
cout << res << endl;
return;
} } int main()
{
IOS;
cin >> T;
while (T--)
{
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
solve();
} return 0;
}

B. Friends and Candies

思路:只能是从糖多的人那里把糖分给糖少的,所以只要求出糖数大于平均的人数即可,当糖数不能被人数整除时输出-1。

代码:

//CF-725.B
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec; #define INF 0x3f3f3f3f
const double EPS = 1e-18;
const int MOD = 1e9 + 7;
const int maxn = 2e5 + 1; int T;
ll N, A[maxn];
void solve()
{
int sum = 0, ans = 0;
int avg;
for (int i = 0; i < N; i++)
sum += A[i];
if (sum % N)
{
cout << -1 << endl;
return;
}
avg = sum / N;
for (int i = 0; i < N; i++)
{
if (A[i] > avg)
ans++;
}
cout << ans << endl;
} int main()
{
IOS;
cin >> T;
while (T--)
{
cin >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
solve();
} return 0;
}

C. Number of Pairs

又是因为没开longlongWA了半天。。。

思路:分治法,不断将数列分为左右两个数列,完全在其中一个数列中的数对数量可以递归求得。合并的同时将数列排序,对于跨两个数列的数对,只需枚举左边数列中的数,在右边找加上它之后处于区间内的数的个数即可。

代码:

//CF-725.C
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec; #define INF 0x3f3f3f3f
const double EPS = 1e-18;
const int MOD = 1e9 + 7;
const int maxn = 1e9 + 1; int T;
ll n, l, r;
vec A; ll merge_solve(vec& a)
{
ll ans = 0;
ll d = a.size();
if (d <= 1)
return 0;
vec b(a.begin(), a.begin() + d / 2);
vec c(a.begin() + d / 2, a.end());
ans += merge_solve(b);
ans += merge_solve(c); ll ai = 0, bi = 0, ci = 0;
while (ai < d)
{
if (bi < b.size() && (ci == c.size() || b[bi] < c[ci]))
{
if (b[bi] <= r)//只有小于右边界才可能可以
{
int hi = r - b[bi], lo = l - b[bi] - 1;
ans += upper_bound(c.begin(), c.end(), hi) - upper_bound(c.begin(), c.end(), lo);
}
a[ai++] = b[bi++];
}
else
a[ai++] = c[ci++];
} return ans;
} void solve()
{
cout << merge_solve(A) << endl;
} int main()
{
IOS;
cin >> T;
while (T--)
{
A.clear();
cin >> n >> l >> r;
for (int i = 0; i < n; i++)
{
int num;
cin >> num;
A.push_back(num);
}
solve();
} return 0;
}

D. Another Problem About Dividing Numbers

思路:当K==1时,如果A和B不相等并且其中一个能整除另外一个时才YES,否则NO。当K!=1时,计算操作次数的上限,当把每个数都除到1的时候操作次数最多,所以直接统计每个数的质因数个数即可,两个数质因数的和M就是允许操作的最大次数。小于这个次数的操作显然都可以完成。如果K<=M,就YES,否则NO。

代码:

//CF-725.D
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec; #define Y "YES"
#define N "NO"
#define INF 0x3f3f3f3f
const double EPS = 1e-18;
const int MOD = 1e9 + 7;
const int maxn = 1e9 + 1; int T, A, B, K;
vec prime; bool isprime(int n)
{
if (n == 0 || n == 1)
return false;
for (int i = 2; i <= sqrt(n); i++)
{
if (!(n % i))
return false;
} return true;
} void solve()
{
int numa = 0, numb = 0, index = 0;
if (K == 1)
{
if ((A != B) && (A % B == 0 || B % A == 0))
{
cout << Y << endl;
return;
}
else
cout << N << endl;
}
else
{
while (A != 1 && index < prime.size())
{
if (!(A % prime[index]))
{
A /= prime[index];
numa++;
}
else
index++;
}
if (A != 1)
numa++;
index = 0;
while (B != 1 && index < prime.size())
{
if (!(B % prime[index]))
{
B /= prime[index];
numb++;
}
else
index++;
}
if (B != 1)
numb++;
int times = numa + numb;
cout << (times >= K ? Y : N) << endl;
}
} int main()
{
IOS;
for (int i = 0; i <= 1e5 + 7; i++)
{
if (isprime(i))
prime.push_back(i);
}
cin >> T;
while (T--)
{
cin >> A >> B >> K;
solve();
} return 0;
}

F. Interesting Function

没想到F题居然这么简单,快结束的时候看见一堆人过了才赶紧去做的。。。

思路:每加1就会有1个数字改变,如果进位了,每进1位就额外有1个数字改变,对于从a加到b,可以看作是从1加到b再减去从1加到a,进位的次数直接分别除以10,100……即可。

代码:

//CF-725.F
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec; #define Y "YES"
#define N "NO"
#define INF 0x3f3f3f3f
const double EPS = 1e-18;
const int MOD = 1e9 + 7;
const int maxn = 1e9 + 1; ll T, L, R;
ll A[10] = { 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000 }; void solve()
{
ll ansr = 0, ansl = 0;
for (int i = 0; i < 10; i++)
{
ansr += R / A[i];
ansl += L / A[i];
}
cout << ansr - ansl << endl;
} int main()
{
IOS;
cin >> T;
while (T--)
{
cin >> L >> R;
solve();
} return 0;
}

Codeforces Round #725 (Div. 3) A-D,F题解的更多相关文章

  1. 刷题记录:Codeforces Round #725 (Div. 3)

    Codeforces Round #725 (Div. 3) 20210704.网址:https://codeforces.com/contest/1538. 感觉这个比上一个要难. A 有一个n个数 ...

  2. Codeforces Round #609 (Div. 2)前五题题解

    Codeforces Round #609 (Div. 2)前五题题解 补题补题…… C题写挂了好几个次,最后一题看了好久题解才懂……我太迟钝了…… 然后因为longlong调了半个小时…… A.Eq ...

  3. Codeforces Round #376 (Div. 2) C D F

    在十五楼做的cf..一会一断...比赛的时候做出了ABCF 就没有时间了 之后没看题解写出了D..E是个神奇的博弈(递推或者dp?)看了题解也没有理解..先写了CDF.. C 有n个袜子 每个袜子都有 ...

  4. Codeforces Round#402(Div.1)掉分记+题解

    哎,今天第一次打div1 感觉头脑很不清醒... 看到第一题就蒙了,想了好久,怎么乱dp,倒过来插之类的...突然发现不就是一道sb二分吗.....sb二分看了二十分钟........ 然后第二题看了 ...

  5. Codeforces Round #556 (Div. 2) D. Three Religions 题解 动态规划

    题目链接:http://codeforces.com/contest/1150/problem/D 题目大意: 你有一个参考串 s 和三个装载字符串的容器 vec[0..2] ,然后还有 q 次操作, ...

  6. Codeforces Round #604 (Div. 2) E. Beautiful Mirrors 题解 组合数学

    题目链接:https://codeforces.com/contest/1265/problem/E 题目大意: 有 \(n\) 个步骤,第 \(i\) 个步骤成功的概率是 \(P_i\) ,每一步只 ...

  7. Codeforces Round #635 (Div. 2)部分(A~E)题解

    虽然打的是div1,但最后半小时完全处于挂机状态,不会做1C,只有个 \(O(n^3)\) 的想法,水了水论坛,甚至看了一下div2的AB,所以干脆顺便写个div2的题解吧,内容看上去还丰富一些(X) ...

  8. Codeforces Round #676 (Div. 2) A - D个人题解(E题待补)

    1421A. XORwice 题目链接:Click Here // Author : RioTian // Time : 20/10/18 #include <bits/stdc++.h> ...

  9. Codeforces Round #677 (Div. 3) E、G题解

    E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞 ...

随机推荐

  1. 前端禁止使用F12、禁止右键

    打开控制台直接跳转页面 //debug调试时跳转页面 var element = new Image(); Object.defineProperty(element,'id',{get:functi ...

  2. Mac系统U盘制作教程

    您可以将外置驱动器或备用宗卷用作安装 Mac 操作系统的启动磁盘. 以下高级步骤主要适用于系统管理员以及熟悉命令行的其他人员.升级 macOS 或重新安装 macOS 不需要可引导安装器,但如果您要在 ...

  3. Android Compose的Window Insets

    Android Compose的Window Insets 除了app的内容区域外, 还有一些其他的固定元素会显示在手机屏幕上, 顶部的状态栏, 刘海, 底部的导航栏, 还有输入法键盘, 它们都是系统 ...

  4. Linux 集群 和免秘钥登录的方法。

    /* 1.1.什么是集群? 很多台服务器(计算机)做相同的事,就称之为集群 服务器和服务器之间必须要处于联通状态(linux01和linux02可以相互访问并且传输数据) 服务器的配置和常见的计算机没 ...

  5. 测试开发实战[提测平台]20-图表G2Plot在项目的实践实录

    微信搜索[大奇测试开],关注这个坚持分享测试开发干货的家伙. G2Plot项目应用 上一篇<提测平台19-Echarts图表在项目的实践>讲解了Echarts的图表应用,此篇来看下开箱即用 ...

  6. 【然天一】随机读写(4k)百盘天梯

    随机读写适用于大量小文件的读写,是最贴近办公和编程的使用场景.现在很多硬盘厂商只宣传它们的连续读写(Seq),但除了游戏和视频剪辑场景之外并没有什么卵用. 总结一下: 傲腾秒杀全部 NAND SLC ...

  7. CTF入门学习5-> 前端JavaScript基础

    Web安全基础 JavaScript的实现包括以下3个部分: 1)核心语法:描述了JS的语法和基本对象. 2)文档对象模型 (DOM):处理网页内容的方法和接口 3)浏览器对象模型(BOM):与浏览器 ...

  8. react-motion 动画案例介绍

    第一个案例:Motion组件 import React,{Component} from 'react'; import {Motion,spring,presets} from 'react-mot ...

  9. vue中router与route区别

    1.$route对象 $route对象表示当前的路由信息,包含了当前 URL 解析得到的信息.包含当前的路径,参数,query对象等. 1.    $route.path      字符串,对应当前路 ...

  10. IDE添加自定义注释

    前言:最近在找IDE自定义模板注释时,十分不愉快,找了很久,才找到适合自己的,故记录一下 一.IDE自定义类注释:       1:打开自定义模板界面,并添加自定义内容: 2:新建类,效果如下 备注: ...