A:Frog Jumping

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int main(){
int T, a, b, c;
scanf("%d", &T);
while(T--){
scanf("%d%d%d", &a, &b, &c);
LL t = a - b;
t = t * (c/);
if(c&) t += a;
printf("%I64d\n", t);
}
return ;
}

B:Disturbed People

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
int a[N];
int main(){
int n;
scanf("%d", &n);
a[] = ; a[n+] = ;
for(int i = ; i <= n; ++i)
scanf("%d", &a[i]);
int ans = ;
for(int i = ; i <= n; ++i){
if(a[i-] == && a[i+] == && a[i] == ){
a[i+] = ;
ans++;
}
}
printf("%d\n", ans);
return ;
}

C:Good Array

题解:模拟, 判断的时候注意 如果是用数组可能会下标越界。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e6 + ;
int a[N];
int vis[N];
vector<int> vc;
int main(){
int n;
scanf("%d", &n);
LL sum = ;
for(int i = ; i <= n; ++i){
scanf("%d", &a[i]);
++vis[a[i]];
sum += a[i];
}
for(int i = ; i <= n; ++i){
sum -= a[i];
--vis[a[i]];
if(sum% == && sum/ < N){
int t = sum/;
//cout << i <<" "<< t << endl;
if(vis[t]) vc.pb(i);
}
sum += a[i];
++vis[a[i]];
}
printf("%d\n", vc.size());
for(auto i : vc){
printf("%d ", i);
}
return ;
}

D:Cutting Out

题解:二分次数,然后输出。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 1e6 + ;
int a[N];
int b[N];
int n, k, m = ;
bool check(int x){
int ret = ;
for(int i = ; i <= m; ++i){
ret += a[b[i]]/x;
}
return ret >= k;
}
int main(){
scanf("%d%d", &n, &k);
for(int i = , t; i <= n; ++i){
scanf("%d", &t);
++a[t];
}
for(int i = ; i < N; ++i){
if(a[i]){
b[++m] = i;
}
}
int l = , r = n;
while(l <= r){
int mid = l+r >> ;
if(check(mid)) l = mid+;
else r = mid-;
}
l--;
for(int i = , c = ; c <= k; ){
if(a[b[i]] >= l){
a[b[i]] -= l;
c++;
printf("%d ", b[i]);
}
else i++;
}
return ;
}

E:Thematic Contests

题解:将每种类型的话题存在一起, 然后sort一下,把小的排前面,然后跑一下背包就好了。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = 2e5 + ;
int a[N];
int b[N];
int dp[N];
int main(){
int n;
scanf("%d", &n);
for(int i = ; i <= n; ++i) scanf("%d", &a[i]);
sort(a+, a++n);
int m = ;
for(int i = ; i <= n; ++i){
if(a[i] == a[i-]) b[m]++;
else b[++m] = ;
}
sort(b+, b++m);
memset(dp, -inf, sizeof(dp));
dp[] = ;
for(int i = ; i <= m; ++i){
for(int j = b[i]; j > ; --j){
dp[j] = max(dp[j], j);
if(j% == ) dp[j] = max(dp[j], dp[j/] + j);
}
}
int ans = ;
for(int i = ; i < N; ++i)
ans = max(ans, dp[i]);
printf("%d\n", ans);
return ;
}

F:Pictures with Kittens

题解:dp[i][u] 表示 处理到i 之后选了u个点, 他的最大价值是多少。

画画图之后就发现发现,  dp[i][u]  可以从 dp[i - x][u-1] 到 dp[i-1][u-1] 转移过来。

所以对于 dp[i][u] 来说我们需要找到 dp[i-x][u-1] 到 dp[i-1][u-1] 里面的最大值。

我一开始是想用线段树搞,写好了之后MLE了......

后来也发现线段树有太多浪费的点了,然后用set, 可能操作太多了, 然后TLE了。。。。。

然后把set改成优先队列就过了,但是跑的太慢了。。。。

最后改成了单调栈, 这个东西不带log 就跑到200ms内了,我一开始是想用这个东西,然后忘了怎么写,就搞了这么多奇奇怪怪的东西。

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<LL,int> pll;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL mod = (int)1e9+;
const int N = ;
int a[N];
int n, k, x;
deque<pll> dq[N];
int main(){
scanf("%d%d%d", &n, &k, &x);
for(int i = ; i <= n; ++i)
scanf("%d", &a[i]);
dq[].push_back({,});
LL ans = -;
for(int i = ; i <= n; ++i){
for(int j = x-; j >= ; --j){
while(!dq[j].empty() && dq[j].front().se < i-k) dq[j].pop_front();
if(dq[j].empty()) continue;
LL val = dq[j].front().fi;
val += a[i];
while(!dq[j+].empty() && dq[j+].back().fi <= val) dq[j+].pop_back();
dq[j+].push_back({val,i});
if(j+ == x && i+k > n) ans = max(ans, val);
}
}
printf("%lld\n", ans);
return ;
}

CodeForces Round 521 div3的更多相关文章

  1. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  2. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

  3. CodeForces Round #527 (Div3) B. Teams Forming

    http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...

  4. CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)

    http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...

  5. CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)

    http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...

  6. CodeForces Round #527 (Div3) C. Prefixes and Suffixes

    http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...

  7. CodeForces Round #527 (Div3) A. Uniform String

    http://codeforces.com/contest/1092/problem/A You are given two integers nn and kk. Your task is to c ...

  8. Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】

    任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...

  9. CodeForces Round #521 (Div.3) E. Thematic Contests

    http://codeforces.com/contest/1077/problem/E output standard output Polycarp has prepared nn competi ...

随机推荐

  1. hdoj 4762 Cut the Cake

    题意很简单就不说了. 解题的关键就是这个公式 answer=n/(m^(n-1)); 要用到大数的乘法.然后java水过. import java.util.*; import java.math.* ...

  2. python多线程详解

    目录 python多线程详解 一.线程介绍 什么是线程 为什么要使用多线程 二.线程实现 threading模块 自定义线程 守护线程 主线程等待子线程结束 多线程共享全局变量 互斥锁 递归锁 信号量 ...

  3. 夯实Java基础(三)——面向对象之继承

    1.继承概述 继承是Java面向对象的三大特征之一,是比较重要的一部分,与后面的多态有着直接的关系.继承就是子类继承父类的特征和行为,使得子类对象(实例)具有父类的实例域和方法,或子类从父类继承方法, ...

  4. hive分桶表bucketed table分桶字段选择与个数确定

    为什么分桶 (1)获得更高的查询处理效率.桶为表加上了额外的结构,Hive 在处理有些查询时能利用这个结构.具体而言,连接两个在(包含连接列的)相同列上划分了桶的表,可以使用 Map 端连接 (Map ...

  5. 【算法】【查找】二分法 Bisection

    #include<stdio.h> int main(){ ,,,,,,,,,,,,,,}; ; //长度 ; //要查找到的值 int Bisection(int x,int* a,in ...

  6. 【Java例题】5.4 子串出现的次数

    4. 输入一个字符串s,再输入另一个字符串t,在s中查找t出现的次数. package chapter5; import java.util.Scanner; public class demo4 { ...

  7. ArrayList 的使用方法【摘要】

    ArrayList 的使用方法 1.什么是ArrayList ArrayList就是传说中的动态数组,用MSDN中的说法,就是Array的复杂版本,它提供了如下一些好处: (1)动态的增加和减少元素 ...

  8. Netty学习(四)-TCP粘包和拆包

    我们都知道TCP是基于字节流的传输协议.那么数据在通信层传播其实就像河水一样并没有明显的分界线,而数据具体表示什么意思什么地方有句号什么地方有分号这个对于TCP底层来说并不清楚.应用层向TCP层发送用 ...

  9. Spark1——介绍

    1.Spark是什么 Spark是一个用来实现快速而通用的集群计算的平台. 2.Spark是一个大一统的软件栈 Spark项目包含多个紧密集成的组件.首先Spark的核心是一个对由很多计算任务组成的. ...

  10. Mysql-巧用join来优化sql

    0. 准备相关表来进行接下来的测试 相关建表语句请看:https://github.com/YangBaohust/my_sql user1表,取经组 +----+-----------+------ ...