首页 > 其他分享 >2.18杂

2.18杂

时间:2023-02-18 09:34:04浏览次数:49  
标签:答辩会 int char while 2.18 getchar

先写一道题CF5E

#include <bits/stdc++.h>
#define maxn 1000005
using namespace std;
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while (c < '0' || c > '9') { if (c == '-') f = -1; char c = getchar(); }
    while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    return x * f;
}
int n, p, m;
int a[maxn], h[maxn], s[maxn], cnt[maxn]; 
signed main() {
	n = read();
	int ma = 0;
	//1 2 4 5 3
	for (int i = 1; i <= n; i++) {
		a[i] = read();
		if (ma < a[i]) ma = a[i], p = i;
	}
	for (int i = p + 1; i <= n; i++) h[++m] = a[i];
	for (int i = 1; i < p; i++) h[++m] = a[i];
	//h: 3 1 2 4
	//for (int i = 1; i <= m; i++) cout << h[i] << " ";
	cout << endl;
	int top = 0, ans = n - 1;
    for (int i = 1; i <= m; i++) {
        while (s[top] < h[i] && top) ans += cnt[top--];
        //cout << s[top] << " ";
        if (s[top] != h[i]) s[++top] = h[i], cnt[top] = 0;
        //cout << cnt[top] << " ";
		ans += cnt[top]++;
		//cout << ans << endl;
    }
    while (top > 1) ans += cnt[top--]; 
	cout << ans;
}

DP+单调栈即可,递推一下。

然后去开了场答辩会,听why说答辩。

就两周了,能讲个寄吧课,文化课都快学不懂了。

image

只能说6……

标签:答辩会,int,char,while,2.18,getchar
From: https://www.cnblogs.com/djc01/p/17131973.html

相关文章

  • 2023.02.18琐记
    敬畏自然柔以生命然后漠视世界毕竟是人类无法完全从感性中抽离只是在虚伪的表演中逃亡排斥那些烦人的矫揉造作心本自由从来我可以热爱这个世界也随时可以离开......
  • 2022.12.18 ~ 2022.12.24 一周学习记录
    2022.12.18模拟退火学习模拟退火是一种常用的随机化算法,当答案是一个连续的函数时,我们就可以考虑用模拟退火进行求解。注意调参数(看rp)伪代码:voidSA()//模拟退火{......
  • 上周热点回顾(12.12-12.18)
    热点随笔:· 瞧瞧别人家的API接口,那叫一个优雅 (苏三说技术)· 我做了第一个ChatGPT.netapi聊天库 (BruceNeter)· 用Flutter写了个博客园APP (xiaoyaocz)· 玩C......
  • 周末总结12.18
    目录django路由层django请求生命周期流程图(*****)1.路由匹配2.正则匹配3.正则匹配的无名有名分组反向解析基本使用动态路由的反向解析路由分发视图层必会三板斧JsonRespons......
  • 闲话 22.12.18
    闲话?本来想颓一整天的不知不觉就到现在了呢不是很理解jijidawang数个月前莫比乌斯反演就爆踩我了%%%%最近闲话的阅读量忽高忽低欸不懂不懂溜了溜了\(\text{Min_25......
  • 解决centos7.6找不到GLIBC_2.18
    问题原因:启动node服务,报错GLIBC_2.18nofound,同时也报错 /lib64/libstdc++.so.6versionCXXABI_1.3.9nofound查看系统GLIBC版本:[root@VM_0_7_centoslib64]#stri......