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 ...
随机推荐
- Kafka服务不可用(宕机)问题踩坑记
背景 某线上日志收集服务报警,打开域名报502错误码. 收集服务由2台netty HA服务器组成,netty服务器将客户端投递来的protobuf日志解析并发送到kafka,打开其中一个应用的日志,发 ...
- 曹工杂谈:Linux服务器上,Spring Boot 原地修改 jar 包配置文件/替换class文件,免去重复上传的麻烦
一.前言 相信很多同学有这样的需求,现在很多公司都有多地的研发中心,经常需要跨地区部署,比如,博主人在成都,但是服务器是北京的.一般城市间网络都不怎么好,上传一个几十兆的jar包那是真的慢,别说现在微 ...
- 基于 Autojs 的 APP、小程序自动化测试 SDK - 2019年8月3日
原文:https://blog.csdn.net/laobingm/article/details/98317394 autojs sdk基于 Autojs 的 APP.小程序自动化测试 SDK,支持 ...
- 有容云-PPT | 当微服务遇见容器
编者注: 本文为10月29日有容云高级技术顾问龙淼在Docker Live时代线下系列-广州站中演讲的PPT,本次线下沙龙为有容云倾力打造Docker Live时代系列主题线下沙龙,每月一期畅聊容器技 ...
- JS中以一个方法作为参数的写法
一:以方法作为参数 这下来说直接以一个方法来作为参数的写法,直接上代码: -----------这样调用的方法------------- go(function(){ alert("succ ...
- 记录用友T+接口对接的心酸历程
前言:公司的业务主要是对接财务系统做单据传输或者凭证处理的,难免少不了和各大财务软件做数据对接,其中当然是必须通过接口来传递数据了.于是乎,用友T+的版本来了,对接的工作自然是我来做,可没想到就是这样 ...
- C#使用代理IP发送请求
https://www.cnblogs.com/benbenfishfish/p/5830149.html 获取可代理的IP https://www.cnblogs.com/ShalenChe/p ...
- mybatis学习笔记(三)
mybatis增删改 概念: 功能:从应用程序角度出发,软件具有哪些功能: 业务:完成功能时的逻辑,对应service的一个方法: 事务:从数据库角度出发,完成业务时需要执行的SQL集合,统称一个事务 ...
- NAS
NAS, Network Attached Storage, 网络附属存储, 简单来说就是连接在网络上, 可以存储资料的装置.可以用来做私有网盘,同步各种设备的照片.视频.音频和文件. 常见的 NAS ...
- Linux启动之旅
引言 某出租房内,某台电脑的电源键被按下,于是开启了一段Linux启动之旅... BIOS 系统启动,首先进入BIOS. ● BIOS 为 Base Input/Output System(基本输入输 ...