Codeforces Round #740 Div. 2
A. Simply Strange Sort
题意
定义一个函数\(f_{i}\) : 如果\(a_i \ge a_{i+1}\) swap(\(a_i\) \(a_{i+1}\))
定义一个操作:
第奇数次是 执行 \(f_1\) \(f_3\)... \(f_{n-2}\)
第偶数次是 执行 \(f_2\) \(f_4\)... \(f_{n-1}\)
求出进行多少次操作可以使原数组变得有序
思路
模拟上述操作即可 判断符合条件也可以用 is_sorted函数
AC_CODE
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define debug(x) cout<<#x" ----> "<<x<<endl
#define rep(i, b, s) for(int i = (b); i <= (s); ++i)
#define pre(i, b, s) for(int i = (b); i >= (s); --i)
//#define int long long
#define endl '\n'
#define ios ios::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII ;
typedef pair<double, double> PDD ;
typedef long long LL;
const int INF = INT_MAX;
const int mod = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
int lowbit(int x){return x&-x;}
int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}
LL ksm(LL a, LL b) {if (b == 0) return 1; LL ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
void solve() {
int n; read(n);
vector<int> a(n + 1), b(n + 1);
for(int i = 1; i <= n; i ++ ) {
read(a[i]);
b[i] = i;
}
int cnt = 0;
for(int i = 1; i <= n; i ++ ) {
if(a == b) {
break;
}
//// if(is_sorted(all(a))) break;
if(i & 1) {
for(int j = 1; j <= n - 2; j += 2)
if(a[j] > a[j + 1]) swap(a[j], a[j + 1]);
}
else {
for(int j = 2; j <= n - 1; j += 2)
if(a[j] > a[j + 1]) swap(a[j], a[j + 1]);
}
cnt ++;
}
printf("%d\n", cnt);
}
signed main()
{
int T = 1; scanf("%d",&T);
while(T -- ) {
solve();
}
return 0;
}
B. Charmed by the Game
题意
题目背景: 乒乓球比赛
规定乒乓球发球为两方选手交替发球
如果本场A选手发球
- A赢了 被称为 A hold
- B赢了 被称为 B break
如果本场B选手发球
- B赢了 被称为 B hold
- A赢了 被称为 A break
给出 A 和 B 赢得次数
求出有多少种 break
思路
我们可以发现赢得场次是固定的, 因此我们只需要枚举A在发球场次赢得个数 就可以的到全部的break
reason 我们枚举了A在发球场次赢得个数 因此我们可以得到另外三种情况,就可以求出所有的break
注意: 第一场发球可能是A 也可能是B 因此 我们只需要求出A先发球 所有的break
然后用a+b-i 就是B先发球的break
AC_CODE
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mk make_pair
#define debug(x) cout<<#x" ----> "<<x<<endl
#define rep(i, b, s) for(int i = (b); i <= (s); ++i)
#define pre(i, b, s) for(int i = (b); i >= (s); --i)
//#define int long long
#define endl '\n'
#define ios ios::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII ;
typedef pair<double, double> PDD ;
typedef long long LL;
const int INF = INT_MAX;
const int mod = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
int lowbit(int x){return x&-x;}
int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}
LL ksm(LL a, LL b) {if (b == 0) return 1; LL ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
const int N = 2e5 + 10;
bool num[N];
int cnt, mid, px;
void solve() {
int a, b;
read(a); read(b);
px = a + b;
for(int i = 0; i <= px + 5; i ++ ) num[i] = false;
if(a < b) swap(a, b);
mid = (px + 1) / 2;
for(int i = mid; i >= mid - b; i -- ) { //i是A在他发球的场次赢得次数
cnt = mid - i + a - i;
num[cnt] = true;
num[px - cnt] = true;
}
vector<int> ans;
for(int i = 0; i <= px; i ++ )
if(num[i])
ans.pb(i);
printf("%d\n", ans.size());
for(int p : ans) printf("%d ", p);
puts("");
}
signed main()
{
int T = 1; scanf("%d",&T);
while(T -- ) {
solve();
}
return 0;
}
C - Deep Down Below
题意
略
思路
按照通过每个关卡所需要的最小力量排序, 然后按照这个顺序枚举即可
AC_CODE
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define debug(x) cout<<#x" ----> "<<x<<endl
#define debug2(x) cout<<#x" ----> "<<x<< ' '
#define rep(i, b, s) for(int i = (b); i <= (s); ++i)
#define pre(i, b, s) for(int i = (b); i >= (s); --i)
//#define int long long
#define endl '\n'
#define ios ios::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef unsigned long long ULL;
typedef pair<int, int> PII ;
typedef pair<double, double> PDD ;
typedef long long LL;
const int INF = INT_MAX;
const int mod = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1.0);
int lowbit(int x){return x&-x;}
int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}
LL ksm(LL a, LL b) {if (b == 0) return 1; LL ns = ksm(a, b >> 1); ns = ns * ns % mod; if (b & 1) ns = ns * a % mod; return ns;}
LL lcm(LL a, LL b) {return a / gcd(a, b) * b;}
template < typename T >
inline void read(T &x)
{
x = 0; bool f = 0; char ch = getchar();
while(!isdigit(ch)){f ^= !(ch ^ 45);ch=getchar();}
while(isdigit(ch)) x= (x<<1)+(x<<3)+(ch&15),ch=getchar();
x = f ? -x : x;
}
const int N = 1e5 + 10;
vector<int> a[N];
PII num[N];
int need[N];
int t, n, rr;
inline void solve() {
scanf("%d", &t);
rep(i, 0, t - 1) {
a[i].clear();
scanf("%d", &n);
rep(j, 1, n) {
scanf("%d", &rr);
a[i].pb(rr);
}
int res = 0;
int st = 0;
int cnt = 0;
rep(j, 0, n - 1) {
if(a[i][j] >= res) {
st = a[i][j] + 1 - cnt;
res = a[i][j] + 2;
}
else {
res ++;
}
cnt ++;
}
need[i] = st;
num[i].fi = st;
num[i].se = i;
}
sort(num, num + t);
int st = 0, res = 0, cnt = 0;
for(int i = 0; i < t; i ++ ) {
int idx = num[i].se;
for(int j = 0; j < a[idx].size(); j ++ ) {
if(a[idx][j] >= res) {
st = a[idx][j] + 1 - cnt;
res = a[idx][j] + 2;
}
else {
res ++;
}
cnt ++;
}
}
printf("%d\n", st);
}
signed main()
{
int T = 1; scanf("%d",&T);
while(T -- ) {
solve();
}
return 0;
}
D1. Up the Strip (simplified version)
整除分块
我们枚举 \(l\) 因此\(i/l\) 可以由\(i\) 除以 (l ---> i/(i/l)) 这个区间内的数字得到
这就是整除分块, 因此我们可以通过这个转移方程求出通过除法转移过来的
减法通过求后缀和可以O(1) 求出
AC_CODE
#include <bits/stdc++.h>
using namespace std;
#define int long long
int mod;
int x[1010000];
int getmax(int n,int l)
{
return n/(n/l);
}
signed main()
{
int n;
scanf("%lld%lld",&n,&mod);
x[n] = 1;
int sum = 0;
for(int i = n;i>=2;i--)
{
x[i] = (x[i] + sum) % mod;
for(int l = 2,r;l<=i;l=r+1)
{
r = getmax(i,l);
x[i/l] = (x[i/l] + (r-l+1) * x[i]) % mod;
}
sum = (sum + x[i]) %mod;
}
printf("%lld",(x[1] + sum)%mod);
return 0;
}
D2. Up the Strip
枚举倍数
对于每个\(i\) 只有\([i \times j, (i+1) \times j)\)区间内的数字才可以通过除以\(j\) 得到 (j是枚举出的每个被除数0)
对于减法 我们加上后缀和即可
AC_CODE
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N = 4e6 + 10;
LL n, m;
LL dp[N];
LL s[N];
LL sum(int l, int r) {
return (s[l] - s[r + 1] + m) % m;
}
int main() {
scanf("%lld%lld", &n, &m);
dp[n] = 1;
s[n] = 1;
for(int i = n - 1; i; i --) {
dp[i] = s[i + 1];
for(int j = 2; j <= n / i; j ++ ) {
int l = i * j, r = min(n, (LL)j * (i + 1) - 1);
dp[i] = dp[i] + sum(l, r);
dp[i] %= m;
}
s[i] = s[i + 1] + dp[i];
s[i] %= m;
}
printf("%lld", (dp[1] + m) % m);
return 0;
}
Codeforces Round #740 Div. 2的更多相关文章
- 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 #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- centos 与虚拟机
一 创建虚拟机 1. 下载 centos7 和 vmware .centos的下载地址:见上一篇. 2.安装vmware ,具体安装过程,自行百度(一路点击确定) 3.打开vmware ,点击创建新的 ...
- 如何把 MySQL 备份验证性能提升 10 倍
JuiceFS 非常适合用来做 MySQL 物理备份,具体使用参考我们的官方文档.最近有个客户在测试时反馈,备份验证的数据准备(xtrabackup --prepare)过程非常慢.我们借助 Juic ...
- static,final,volatile
static 静态修饰关键字,可以修饰 变量,程序块,类的方法:[被 static 修饰的方法和属性只属于类不属于类的任何对象.] 当你定义一个static的变量的时候jvm会将将其分配在内存堆上, ...
- CS5211替代CH7511B|DP转LVDS控制板|替代CH7511B设计电路方案
CS5211性能和参数可以替代CH7511B,PS8622,PS8625,LT7211等方案,用于设计DP转LVDS转换器,DP转LVDS控制板,DP转LVDS转接板等产品设计. CS5211是一个e ...
- 编写Java程序,实现字符串统计和处理
返回本章节 返回作业目录 需求说明: 在控制台输入纯字符的字符串,输出当前字符串的长度. 统计出该字符串中出现相同字母次数最多的字母(不考虑不同字母出现次数相同的情况). 将出现最多次数的字母字母替换 ...
- java并发系列——底层CPU
java并发有诸多难点,实际上并非java语言本身的问题,本质上说一部分是因为并发操作本身的问题,另外一部分是因为计算机体系结构带来的.为了更好地理解java并发过程中的问题,我们应该对CPU有一些基 ...
- 在pycharm中创建py文件——创建你的第一个项目
开启编程第一步 创建一个项目 创建项目了xdm,敲黑板了哈 首先打开你的pycharm,点击New Project新建项目 就会进入到配置你这个项目所要用到的环境,这里我们用python列举 在L ...
- [特别篇] 记JZ冬令营(Finished)
1.16 走错班了, 去了全是大佬的1班, 然后灰溜溜滚回2班了. 去参加开营仪式. 然而昏昏欲睡... 实在太累了澡也没洗.. 群英云集, 多是感慨. 当时依依惜别和铮铮誓言, 在重逢中无语凝噎. ...
- rsync配置文件讲解
1.安装rysnc 一般在安装系统时rsync是安装上(yum安装) 2. vim /etc/xinetd.d/rsync 在这个路径下有配置文件 service rsync { disabl ...
- 互联网医疗行业PEST分析实践
前言 今年开始逐步切入产品与数据工作,完全脱离了原来的舒适区,确实有一些挑战.开始以为只做数仓建设的事情,就仓促的学习了一些数仓相关的知识,但没搞多久,还要负责公司BI的工作,又开始补习数分相关的知识 ...