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 ...
随机推荐
- IDEA自学
使用Eclipse很长时间了,想换个IDE用,都说IDEA好用,今天试试 百度了一下IDEA,了解到IDEA社区版免费,上百度,下载个社区版(exe,zip两种)懒人选择exe 手动安装别怕安错,只管 ...
- MySQL 之 Explain 输出分析
MySQL 之 Explain 输出分析 背景 前面的文章写过 MySQL 的事务和锁,这篇文章我们来聊聊 MySQL 的 Explain,估计大家在工作或者面试中多多少少都会接触过这个.可能工作中 ...
- RGW 学习 前言
对于CEPH的学习已经有一段的时间了,最近的一段时间都是集中在RGW网关这一方面,所以准备将学习的过程以及源代码的分析,将以随笔的形式记录下来. 每天更新一章.
- tp5css和js引入问题
由于以前用的是tp3.2,现在转用tp5开啊个人博客,在引入CSS和JS的时候遇到了一些坑 在3.2时期需要在路径中添加public,而在tp5中则直接引入static即可. 在config.php下 ...
- 转载 | CSS图片下面产生间隙的 6种解决方案
在进行页面的DIV+CSS排版时,遇到IE6(当然有时Firefox下也会偶遇)浏览器中的图片元素img下出现多余空白的问题绝对是常见的对於 该问题的解决方法也是「见机行事」,根据原因的不同要用不同的 ...
- 搞定java String校招面试题
今天大致的阅读了String类的源码,并刷了常见的面试题,在此做个笔记. 面试题一:判断下列程序运行结果 package String_test; public class test_1 { publ ...
- [转载]ActiveMQ实现负载均衡+高可用部署方案
转载于 http://www.open-open.com/lib/view/open1400126457817.html 一.架构和技术介绍 1.简介 ActiveMQ 是Apache出品,最流行的, ...
- struts与springmvc有何区别
Struts2与SpringMVC有何区别? (1)SpringMVC的核心控制器是基于servlet技术,而Struts2是基于filter. (2)Struts2是类级别的拦截, 一个类对应一个r ...
- Sublime Text3激活及个性化配置
[TOC] 在我们的开发过程中,选择正确的开发工具会让我们事半功倍.作为后端开发我们熟悉的myeclipse和itellij idea这些工具我也介绍曾介绍过关于他们的安装及破解.但是我们并不能仅仅使 ...
- Zabbix-设置自动发现规则实例
一.前文 此篇文章,主要针对自动发现规则中使用snmpv2类型发现 zabbix官方解读,可当参考: https://www.zabbix.com/documentation/4.0/zh/man ...