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 ...
随机推荐
- Bean Validation完结篇:你必须关注的边边角角(约束级联、自定义约束、自定义校验器、国际化失败消息...)
每篇一句 没有任何技术方案会是一种银弹,任何东西都是有利弊的 相关阅读 [小家Java]深入了解数据校验:Java Bean Validation 2.0(JSR303.JSR349.JSR380)H ...
- MySQL5.7运行CPU达百分之400处理方案
用户在使用 MySQL 实例时,会遇到 CPU 使用率过高甚至达到 100% 的情况.本文将介绍造成该状况的常见原因以及解决方法,并通过 CPU 使用率为 100% 的典型场景,来分析引起该状况的原因 ...
- 搭建nexus私服
一.安装 1.从网上下载nexus软件https://www.sonatype.com/download-oss-sonatype 下载Nexus Repository Manager OSS软件包 ...
- xml的四种解析方式(转载)
众所周知,现在解析XML的方法越来越多,但主流的方法也就四种,即:DOM.SAX.JDOM和DOM4J 下面首先给出这四种方法的jar包下载地址 DOM:在现在的Java JDK里都自带了,在xml- ...
- Power Designer导出模型的sql加注释-Oracle语句
第一步:Database-->Edit Current DBMS 第二步: 然后分别将 Script-->Objects-->Table-->TableComment Scri ...
- 【Java例题】7.1 线程题1-时间显示线程
1.时间显示线程.设计一个示线程子类,每秒钟显示一次当前时间:然后编写主类,在主函数中定义一个线程对象,并启动这个线程 package chapter7; import java.text.Simpl ...
- [NUnit] discover test finished: 0 found issue
%Temp%\VisualStudioTestExplorerExtensions & restart visual studio
- ccf 201903-5 317号子任务(60分)
看到这题,第一印象,用dijkstra算法求n次单源最短路,时间复杂度O(n^3),超时30分妥妥的. 于是用优先队列优化,O(n*mlogm),快很多,但依然30. 那么不妨换一种思路,题目要求的是 ...
- android——SQLite数据库存储(操作)
public class MyDatabaseHelper extends SQLiteOpenHelper { //把定义SQL建表语句成字符串常量 //图书的详细信息 //ID.作者.价格.页数. ...
- SpringBoot操作ES进行各种高级查询
SpringBoot整合ES 创建SpringBoot项目,导入 ES 6.2.1 的 RestClient 依赖和 ES 依赖.在项目中直接引用 es-starter 的话会报容器初始化异常错误,导 ...