A. Game Shopping

按照题意模拟既可。

#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1010;
int n, m, c[N], a[N], ans = 0;
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) scanf("%d", c + i);
for(int i = 1; i <= m; i++) scanf("%d", a + i); for(int i = 1, j = 1; i <= n; i++)
if(c[i] <= a[j]) ans ++, j++; printf("%d", ans);
return 0;
}

B. Minimum Ternary String

  • 邻项交换的特性决定了1可以随意活动。
  • 02唯独相互遇上不可交换,也就是说0和2的相对位置保持不变。

依据特性,将1尽量靠前放置既可。

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
string str;
int main(){
cin >> str;
int cnt = 0;
for(int i = 0; i < str.size(); i++)
if(str[i] == '1') cnt ++ ; for(int i = 0; i < str.size(); i++){
if(str[i] == '1') continue;
else if(str[i] == '2' && cnt){
for(int j = 0; j < cnt; j++) printf("1"); cnt = 0;
}
printf("%c", str[i]);
}
if(cnt)for(int j = 0; j < cnt; j++) printf("1");
return 0;
}

C. Annoying Present

要使平均值最大,只需让总和最大即可。

\(x * d\) 的贡献是定值,只关注 \(\sum\limits_{i=1}^n\ d * |i - j|\) 既可。

  • 若 \(d > 0\),则令 \(\sum\limits_{i=1}^n\ |i - j|\) 最大。显然 \(i\) 取 \(0\) 或 \(n\) 时,值最大。
  • 若 \(d < 0\) ,则令 \(\sum\limits_{i=1}^n\ |i - j|\) 最小。显然 \(i\) 取 n 中位数 $ \lfloor (n + 1) / 2\rfloor$时,值最小。
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 100010;
typedef long long LL;
int n, m, x, d;
LL sum = 0, MAX = 0, MIN = 0;
int main(){
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++){
MAX += abs(i - 1);
MIN += abs(i - (n + 1) / 2);
}
for(int i = 1; i <= m; i++){
int x, d; scanf("%d%d", &x, &d);
if(d > 0) sum += x * n + d * MAX;
else sum += x * n + d * MIN;
}
printf("%.15f", double(sum) / n);
return 0;
}

D. Relatively Prime Graph

暴力可行。

任取两个正整数,他们互素的概率为\(6/π^2\)。参考

维基百科: In a sense that can be made precise, the probability that two randomly chosen integers are coprime is \(6/π^2\) (see pi), which is > about 61%. See below.

则我们最多只需筛选 \(100000 / 6/π^2 \approx 100000 / 61\% < 200000\) 的数,不会超时。

#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
const int N = 100010;
int n, m, tot = 0;
int gcd(int a, int b){
return b ? gcd(b, a % b) : a;
}
vector<int> G[N]; void gcd_prework(){
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
if(gcd(i, j) == 1){
++tot; G[i].push_back(j);
if(tot >= m) return;
}
}
}
} int main(){
scanf("%d%d", &n, &m); if(m < n - 1)
puts("Impossible");
else{
gcd_prework();
if(tot < m) puts("Impossible");
else{
puts("Possible");
for(int i = 1; i <= n; i++)
for(int j = 0; j < G[i].size(); j++)
printf("%d %d\n", i, G[i][j]);
}
}
return 0;
}

E - Intercity Travelling

退了半天式子自闭了,找规律题,从前一步推向后一步既可。把图画出来可能好理解一点。

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
const int N = 1000010, Mod = 998244353;
int n, a[N], s, g;
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", a + i);
for(int i = 1; i <= n; i++){
s = ((LL)s * 2 + a[i] + a[i - 1] + g * 2) % Mod;
g = ((LL)g * 2 + a[i - 1]) % Mod;
}
cout << s;
return 0;
}

Codeforces Edu Round 47 A-E的更多相关文章

  1. codeforces水题100道 第三题 Codeforces Beta Round #47 A. Domino piling (math)

    题目链接:http://www.codeforces.com/problemset/problem/50/A题意:一个NxM的举行中最多能放多少个1x2的矩形.C++代码: #include < ...

  2. Codeforces Beta Round #44 (Div. 2)

    Codeforces Beta Round #44 (Div. 2) http://codeforces.com/contest/47 A #include<bits/stdc++.h> ...

  3. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  4. Codeforces Beta Round #62 题解【ABCD】

    Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...

  5. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  6. Codeforces Beta Round #13 C. Sequence (DP)

    题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...

  7. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  8. Codeforces Global Round 1 - D. Jongmah(动态规划)

    Problem   Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...

  9. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

随机推荐

  1. python之路《九》 迭代器与生成器

    1.生成器 通过列表生成式,我们可以直接创建一个列表.但是,受到内存限制,列表容量肯定是有限的.而且,创建一个包含100万个元素的列表,不仅占用很大的存储空间,如果我们仅仅需要访问前面几个元素,那后面 ...

  2. phpmyadmin 4.8.1任意文件包含(CVE-2018-12613)

    简介 环境复现:https://gitee.com/xiaohua1998/hctf_2018_warmup 考察知识点:文件包含漏洞(phpmyadmin 4.8.1任意文件包含) 线上平台:榆林学 ...

  3. python-基础入门-序

    安装,直接百度Python就行,我是2.7的版本. 我的资料先是<笨办法学Python>,作为简单的入门它写的很有趣. 我有简单的c语言的基础,把它过完后上核心编程,当然,一切都是为了ct ...

  4. Hadoop分布式平台搭建

    环境:CentOS 7.4 (1708  DVD) 工具:MobaXterm 一. 安装 1. 将hadoop安装包上传到/usr/local目录下,将其解压并重命名. 2. 配置hadoop的环境变 ...

  5. Linux Command Line_1_Shell基础

      引言 图形用户界面(GUI)让简单的任务更容易完成,命令行界面(CLI)使完成复杂的任务成为可能. 第一部分:Shell 本部分包括命令行基本语言,命令组成结构,文件系统浏览.编写命令行.查找命令 ...

  6. 快来,Boom 3D广播功能还能这样用

    Boom 3D不仅为用户提供了包括3D立体音效.古典音乐音效在内的多种音效增强功能,而且还为用户提供了广播功能.该广播功能不仅涵盖了国内广播节目,而且还涵盖了国际广播节目. Boom 3D的广播功能还 ...

  7. 怎么用iMindMap思维导图做自我介绍

    相信大家在工作生活当中对于自我介绍这件事情都很是头疼的.太简单的介绍重点不突出,太冗长的介绍又会让人没印象.这一切都跟我们大脑水平.散乱的思维模式有关,因此想要自我介绍在众人中脱颖而出,让人印象深刻, ...

  8. word选择+快捷键

    统一修改红色章节标题字体:将鼠标放置在章节标题中,前提是各章节标题采用的格式是一样的,单击"选择"-"选择格式相似的文本"即可全部选中进行设置 如下图,章节标题 ...

  9. git操作之四:git branch(本地仓库)

    前面,介绍了git init/add/commit/restore/reset等git命令,今天介绍下git branch,这个命令是和分支相关的.首先要理解什么是分支,简单来说在协作开发中,每个人开 ...

  10. leetcode 56合并区间 java

    //先排序,将左区间小的放在前面,然后如果前一个的右区间大于下一个的左区间,则可以合并,分别用两个下标指向当前的大区间和将要考察的小区间 class Solution {    public int[ ...