CodeForces Round 521 div3
代码:
#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 ;
}
代码:
#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 ;
}
题解:模拟, 判断的时候注意 如果是用数组可能会下标越界。
代码:
#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 ;
}
题解:二分次数,然后输出。
代码:
#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 ;
}
题解:将每种类型的话题存在一起, 然后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 ;
}
题解: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的更多相关文章
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- CodeForces Round #521 (Div.3) E. Thematic Contests
http://codeforces.com/contest/1077/problem/E output standard output Polycarp has prepared nn competi ...
随机推荐
- 章节十五、6-log4 2-用默认的配置
一.实例演示 package log4jtutorial; import org.apache.logging.log4j.LogManager; import org.apache.logging. ...
- ajax具体实现学习记录
记录自己对ajax\的理解, 首先要明白ajax是为了解决什么问题,简单来讲就是为了局部刷新页面,而不刷新整个界面.就比如现在有一个实时热度的显示,它是不断变化的,所以你肯定要不停的从数据库当中获取热 ...
- 自定义 Button 选择器
极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android 本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以 ...
- spring-boot项目的docker集成化部署(一)
目录 spring-boot项目的docker集成化部署 前言 基本思路与方案 基本步骤 准备源码 服务器和基础环境 结语 1. 本文总结: 2. 后期优化: spring-boot项目的docker ...
- 使用 Docker 生成 Let’s Encrypt 证书
概念 什么是 Container ? https://www.docker.com/resources/what-container https://www.docker.com/why-docker ...
- c++随笔之编译器编译原理
/* C++编译器原理:1)首先明白声明与定义是两个不同的概念 extern int i;是声明,int i;是定义 函数就更简单了2)编译分为: 预编译:将宏替换,include等代码拷贝过来 编译 ...
- Django:在OS X环境下连接MySQL数据库
正常的安装只需要执行以下2条命令: $ brew install mysql-connector-c $ pip3 install mysqlclient 但在执行 pip3 install mysq ...
- 转载 | SVG向下兼容优雅降级方法
本文引自:http://www.zhangxinxu.com/wordpress/2013/09/svg-fallbacks/ 1.svg image标签降级技术 <svg width=&quo ...
- resolv.conf文件配置相关的案例
引言 操作系统中/etc/resolv.conf配置文件中的内容一般为空,如果该文件配置不正确,将导致ssh.route.netstat命令响应慢的问题. 在/etc/resolv.conf添加错误地 ...
- Python连载30-多线程之进程&线程&线程使用举例
一.多线程 1.我们的环境 (1)xubuntu 16.04(2)anaconda(3)pycharm(4)python 3.6 2.程序:一堆代码以文本的形式存入一个文档 3.进程:程序运行的一个状 ...