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. (1)puppet安装

    简介: 基于C/S架构的Puppet更新方式一般有两种,一种是Agent端设置同步时间主动去PuppetMaster端拉取配置,另一种是通过PuppetMaster端使用puppet kick命令或者 ...

  2. ApacheCN Vue 译文集 20211115 更新

    使用 GraphQL 构建 VueJS 应用 零.前言 一.数据绑定.事件和计算属性 二.组件.混合器和功能组件 三.设置我们的聊天应用--AWS Amplify 环境和 GraphQL 四.创建自定 ...

  3. Programiz 中文系列教程·翻译完成

    原文:Programiz 协议:CC BY-NC-SA 4.0 欢迎任何人参与和完善:一个人可以走的很快,但是一群人却可以走的更远. 在线阅读 ApacheCN 学习资源 目录 Programiz C ...

  4. bom案例5-简单动画

      <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&q ...

  5. JAVA类加载器二 通过类加载器读取资源文件

    感谢原文作者:不将就! 原文链接:https://www.cnblogs.com/byron0918/p/5770684.html 一.getResourceAsStream方法 getResourc ...

  6. 常用获取inflate的写法

    1.             //context:上下文, resource:要转换成view对象的layout的id, root:将layout用root(ViewGroup)包一层作为codify ...

  7. Kubernetes实战之部署ELK Stack收集平台日志

    主要内容 1 ELK概念 2 K8S需要收集哪些日志 3 ELK Stack日志方案 4 容器中的日志怎么收集 5 K8S平台中应用日志收集 准备环境 一套正常运行的k8s集群,kubeadm安装部署 ...

  8. linux内核可以接受的参数 | Linux kernel启动参数 | 通过grub给内核传递参数

    在Linux中,给kernel传递参数以控制其行为总共有三种方法: 1.build kernel之时的各个configuration选项. 2.当kernel启动之时,可以参数在kernel被GRUB ...

  9. elasticsearch搜索引擎的常用方法

    1.term和termsterm和terms等查询,不会对查询对字段进行分词处理,适合于date.num.id等确切数据进行搜索 如果需要查询keywords,则查询等keywords必须是查询字段中 ...

  10. 带你十天轻松搞定 Go 微服务系列(九、链路追踪)

    序言 我们通过一个系列文章跟大家详细展示一个 go-zero 微服务示例,整个系列分十篇文章,目录结构如下: 环境搭建 服务拆分 用户服务 产品服务 订单服务 支付服务 RPC 服务 Auth 验证 ...