A. K-th Largest Value

思路:操作就是0变1,1变0。那么只用统计1有多少个就知道第x大是谁了。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll a[maxn]; int main()
{
ll n = read(), q = read();
ll zeros = 0, ones = 0;
rep(i,1,n) a[i] = read();
rep(i,1,n)
{
if(a[i]==1) ones++;
else zeros++;
}
rep(i,1,q)
{
ll t = read();
if(t==1)
{
ll x = read();
if(a[x]==1) ones--, zeros++, a[x] = 0;
else ones++, zeros--, a[x] = 1;
}
else
{
ll k = read();
if(ones>=k) cout<<1<<endl;
else cout<<0<<endl;
}
}
return 0;
}

B. Minimal Cost

思路:手动模拟几个数据就能找到规律了。要把路封死不得不移动障碍物就两种情况:

1.一列纵向排列,这个时候要把其中一个右移或左移后,再横向或纵向移动一次,选\(min(u+v,v*2)\)。

2.分散排列,但每两个之间的间距都不超过1,(如一条斜线),这种就要将其中一个纵向或横向移动, 选\(min(u,v)\)。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll a[maxn]; int main()
{
int kase;
cin>>kase;
while(kase--)
{
ll n = read(), u = read(), v = read();
rep(i,1,n) a[i] = read();
ll ma = 0;
rep(i,2,n) ma = max(abs(a[i] - a[i-1]) ,ma);
ll ans = 0;
if(ma==1) ans = min(u,v);
else if(ma==0)
{
ans = min(u+v,v*2);
}
cout<<ans<<endl;
}
return 0;
}

C. Pekora and Trampoline

思路:其实贪心的核心很简单:在不得不以第i个蹦床当起跳点的时候,我想它已经尽可能地多次从前面跳过来过了。

那么就从前往后遍历,每次先看看当前已经被跳过来多少次,如果还需要跳(>1),那说明[i+2,i+left]的位置都是以它为起点需要跳的(注意若前面跳过来的次数比a[i]还大的话多出来的还会跳到i+1)。这个时候将前面过来的次数和自己当起点的次数继续传递下去即可。

注意一下细节,这题可能很多人迷之wa2和TL。

view code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(long long i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} }; ll a[maxn];
ll cnt[maxn]; int main()
{
int kase;
scanf("%d",&kase);
while(kase--)
{
ll n = read();
rep(i,0,n+1) cnt[i] = 0;
rep(i,1,n) a[i] = read();
ll ans = 0;
rep(i,1,n)
{
ll Left = max(1LL, a[i]-cnt[i]);
ll final = Left + i;
rep(j,1,cnt[i])
{
ll to = max(i + a[i] - cnt[i] + j , i+1);
if(to>n) break;
if(to==i+1)
{
ll num = min(cnt[i] - a[i] + 1 - j + 1, cnt[i] - j + 1);
cnt[to] += num;
j = cnt[i] - a[i] + 1;
continue;
}
cnt[to] ++;
}
ll need = Left - 1;
if(need)
{
rep(j,1,need)
{
if(j+i+1>n) break;
cnt[j+i+1]++;
}
ans += need;
}
}
cout<<ans<<endl;
}
return 0;
}

Codeforces Global Round 13 ABC题解的更多相关文章

  1. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  2. Codeforces Global Round 11 个人题解(B题)

    Codeforces Global Round 11 1427A. Avoiding Zero 题目链接:click here 待补 1427B. Chess Cheater 题目链接:click h ...

  3. Codeforces Global Round 2部分题解

    传送门 好难受啊掉\(rating\)了-- \(A\ Ilya\ and\ a\ Colorful\ Walk\) 找到最后一个与第一个颜色不同的,比一下距离,然后再找到最左边和最右边与第一个颜色不 ...

  4. Codeforces Global Round 2 部分题解

    F.Niyaz and Small Degrees 挺sb的一题,为什么比赛时只过了4个呢 考虑当\(x\)固定的时候怎么做.显然可以树形DP:设\(f_{u,i=0/1}\)表示只考虑\(u\)子树 ...

  5. Codeforces Global Round 13

    比赛地址 A(水题) 题目链接 题目: 给出一个\(01\)序列,有2种操作:1.将某个位置取反:2.询问\(01\)序列中第\(k\)大的数 解析: 显然维护1的数目即可 #include<b ...

  6. Codeforces Global Round 2 题解

    Codeforces Global Round 2 题目链接:https://codeforces.com/contest/1119 A. Ilya and a Colorful Walk 题意: 给 ...

  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 Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

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

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

随机推荐

  1. 自动驾驶仿真全攻略:基于CARLA+YOLOv5的自主导航实战

    引言:自动驾驶仿真的战略价值 在自动驾驶技术落地的前夜,仿真测试正在成为连接算法研发与实际路测的关键桥梁.据统计,自动驾驶系统每1万公里的接管次数需从仿真测试的百万公里级数据中优化,这使得CARLA. ...

  2. 如何在 MySQL 中实现读写分离?

    如何在 MySQL 中实现读写分离? 在 MySQL 中实现读写分离主要目的是为了提升数据库的性能和扩展性,将读请求和写请求分配到不同的服务器上,减轻主数据库的压力.通常,写请求会发送到主库,而读请求 ...

  3. Java 中常见的垃圾收集器有哪些?

    Java 中常见的垃圾收集器 Java 提供了多种垃圾收集器(Garbage Collector, GC),每种收集器针对不同的应用场景和需求进行了优化.以下是常见的垃圾收集器及其特点. 1. Ser ...

  4. win自带的远程桌面内网也能用简直太香了,mstsc配置方法以及解决由于没有远程桌面授权服务器可以提供许可证

    以前都是用mstsc命令远程连接控制有公网ip的服务器,最近内网设置了下也能用简直太香了,终于不用担心某desk限时长限次数了: 配置方法: 右键 计算机 选择属性,点击远程设置,在远程协助框中勾选 ...

  5. 鸿蒙动画与交互设计:ArkUI 3D变换与手势事件详解

    大家好,我是 V 哥. 在鸿蒙 NEXT 开发中,ArkUI 提供了丰富的 3D 变换和手势事件功能,可用于创建生动且交互性强的用户界面.下面详细介绍 ArkUI 的 3D 变换和手势事件,并给出相应 ...

  6. HTML5和CSS3基础

    HTML元素 空元素 不是所有元素都拥有开始标签.内容和结束标签.一些元素只有一个标签,通常用来在此元素所在位置插入/嵌入一些东西.这些元素被称为空元素例如:元素 `` 是用来在页面插入一张指定的图片 ...

  7. gfast工作流2.0发布

    Gfast 是基于 GF (Go Frame) 的后台管理系统,此次为丰富 Gfast 生态而增加工作流,经过长时间的精心研发和严格测试,全新 Gfast 工作流版本现已正式发布! 流程亮点: 1.支 ...

  8. java代码中启动exe程序最简单的方法

    使用awt的Desktop类的open方法: public static void startExe(String exePath){ try { if(StringUtils.isNotBlank( ...

  9. Vue技术之“关于sortable排序的使用”

    Vue关于sortable排序的使用 方案1 在使用sortable后要注意给el-table-column中加入prop="overdueDays"参数,不然会找不到需要排序的数 ...

  10. C#实现MergeSort算法

    public class MergeSortLearn { /// <summary> /// 分治递归 /// </summary> /// <param name=& ...