Codeforces Edu Round 47 A-E
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可以随意活动。 0和2唯独相互遇上不可交换,也就是说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的更多相关文章
- codeforces水题100道 第三题 Codeforces Beta Round #47 A. Domino piling (math)
题目链接:http://www.codeforces.com/problemset/problem/50/A题意:一个NxM的举行中最多能放多少个1x2的矩形.C++代码: #include < ...
- Codeforces Beta Round #44 (Div. 2)
Codeforces Beta Round #44 (Div. 2) http://codeforces.com/contest/47 A #include<bits/stdc++.h> ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- 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]中有多少个数 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #13 C. Sequence (DP)
题目大意 给一个数列,长度不超过 5000,每次可以将其中的一个数加 1 或者减 1,问,最少需要多少次操作,才能使得这个数列单调不降 数列中每个数为 -109-109 中的一个数 做法分析 先这样考 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 - D. Jongmah(动态规划)
Problem Codeforces Global Round 1 - D. Jongmah Time Limit: 3000 mSec Problem Description Input Out ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
随机推荐
- 菜鸟试做GUI简单数据库查询界面 python+tkinter+mysql
一.准备工作: 1.安装mysql3.7,创建一个test数据库,创建student表,创建列:(列名看代码),创建几条数据 (以上工作直接用navicat for mysql工具完成) 二.代码: ...
- spring boot和spring cloud版本选择
SpringBoot版本介绍 官网链接:https://spring.io/projects/spring-boot#learn Spring Boot的版本以数字表示.例如:Spring Boot ...
- [web安全原理]PHP命令执行漏洞基础
前言 PHP命令执行漏洞 应用程序的某些功能功能需要调用可以执行系统命令的函数,如果这些函数或者函数的参数被用户控制,就有可能通过命令连接符将恶意命令拼接到正常的函数中,从而随意执行系统命令,这就是命 ...
- springboot项目启动报错Communications link failure
环境情况,MySQL版本如下: 报错情况如下(看上去是和数据库有关): com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communi ...
- 在FL Studio中有序地处理人声的混音轨道
关于人声处理的技巧,我们在以前也有讲到很多,当然在以后也会有新的人声处理技巧课程,这是在音乐后期制作中无法避免的一个环节,在制作许多流行音乐时都会用到,今天先为大家讲解一下在FL Studio中更有序 ...
- 加密PDF文件,提高文件安全性
PDF文件的一大优点是可以设置文件的安全性,不仅可以通过证书加密的形式加密文件,还可以通过pdfFactory来设置密码的形式加密文件. 我们可以通过两种方式开启"PDF加密"来为 ...
- And Or IN Not操作符
再sql中And比or运算符优先级要更高,比如说 条件1 Or 条件2 And 条件3 如果先执行or,就是1or2 再and3 但是实际上是 2and3 再or 1,所以如果想要 1 ...
- 网络管理监视很重要!学编程的你知道哪些不错的网络监控工具?2020 最好的Linux网络监控工具分享给你
以下文章来源于新钛云服 翻译:侯明明 前言 虽然这个清单包含开源的和闭源的产品,但它着重于介绍基于 Linux 的网络监控工具, 少数常用工具只能在 Windows,Pandora 或其他系统上运行, ...
- python应用(6):函数
在流程很简单的时候,或者流程不简单但我们不需要考虑开发维护成本的时候,平面地组织你的代码就够了,不用费脑子,不需要考虑层次或重用的东西.当事情变得越来越复杂时,当同行对代码质量要求越来越高时,有一些重 ...
- git的使用以及git和码云的连接
什么是git? Git是一个开源的分布式版本控制系统,可以有效.高速地处理从很小到非常大的项目版本管理.可以保存许多的历史版本,并且可以多人同时进行开发. 分布式版本控制系统 每个人拥有该项目 ...