[11.6] 日常模拟
来源:互联网 发布:9377战无不胜进阶数据 编辑:程序博客网 时间:2024/05/22 04:33
//100 + 40 + 0
洗澡
【问题描述】
你是能看到第一题的 friends 呢。
——hja
洗澡的地方,有一段括号序列,将一个括号修改一次需要1的代价(将左括
号变成右括号或者相反),求最小代价使得括号序列合法。
【输入格式】
一行一个括号序列。
【输出格式】
一行一个整数代表答案。
【样例输入】
())(
【样例输出】
2
【数据范围与规定】
50%的数据,括号序列长度不超过100。
对于100%的数据,括号序列长度不超过10 5 且一定为偶数,只包含小括
号。
//水题
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn = 100000 + 100;char a[maxn];int zuo = 0,ans = 0;int main() { freopen("shower.in","r",stdin); freopen("shower.out","w",stdout); cin>>a; int l = strlen(a); for(int i = 0; i < l; i++) { if(a[i] == '(') zuo++; if(a[i] == ')') { if(zuo == 0) { ans++; zuo++; } else { zuo--; } } } cout<<ans + (zuo / 2 )<<endl; return 0;}
日记
【问题描述】
你是能看到第二题的 friends 呢。
——laekov
日记之中,写满了质数,两个质数之间如果没有其他质数,那么则称为相
邻的质数。给定N,l,询问不超过N的数中能够表示成连续l个质数之和的最大
的数是多少。
【输入格式】
第一行一个整数T代表数据组数。
对于每组数据,一行行两个整数N,l。
【输出格式】
对于每组数据,一行一个整数代表答案。如果不存在,则输出−1。
【样例输入】
3
20 2
20 3
20 4
【样例输出】
18
15
17
//continue 打成 break了,崩溃 100 -> 40
筛素数表+前缀和
#include<iostream>#include<cstdio>#include<cstring>using namespace std;#define deg(i) cout<<'#'<<i<<endl#define ll long longconst int maxn = 1000000 + 100;const int inf = 1000000;int T,n,k;int read() { int x = 0, f = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } return x * f;}int vis[maxn],prime[maxn],cnt = 0;ll sum[maxn];void init_prime() { for(int i = 2; i <= inf; i++) { if(!vis[i]) prime[++cnt] = i; for(int j = 1; j <= cnt && i * prime[j] <= inf; j++) { vis[i * prime[j]] = 1; if(i % prime[j] == 0) break; } } prime[++cnt] = 1<<29; for(int i = 1; i <= cnt; i++) { sum[i] = sum[i-1] + (ll)prime[i]; }}int main() { freopen("diary.in","r",stdin); freopen("diary.out","w",stdout); T = read(); init_prime(); while(T--) { n = read(), k = read(); if(sum[k] > n ) { cout<<-1<<endl; continue; } for(int i = k + 1; i <= cnt; i++) { if(sum[i] - sum[i - k] > n) { printf("%lld\n",sum[i - 1] - sum[i - k - 1]); break; } } } return 0;}
阅读全文
1 0
- [11.6] 日常模拟
- [11.1]日常模拟.1
- [11.2]日常模拟.2
- [11.3]日常模拟.3
- 日常
- 日常
- 【日常】...
- 日常
- 。。。。。日常
- 日常
- 日常
- 日常
- 日常
- 日常
- 日常
- 日常
- 日常
- 日常
- UVALive 4683(鸽巢原理 O(n))
- linux .ko的编译与测试
- Sublime配置
- 基于netty的文件上传下载组件
- PHPExcel导出类(列数超过Z,导出图片)
- [11.6] 日常模拟
- kong api可视化管理工具konga安装使用教程
- 解决未能加载文件或程序集“Office,Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c”或它的某一个依赖项
- Windows下查找文件或文件夹被哪个进程占用
- AR大屏互动自己整合基础框架
- mysql中文乱码
- python 中的 re.compile 函数
- (原) react native 获取view宽高
- android—ijkplayer的编译