getchar

4.9 模拟赛

十年热恋 提交于 2020-01-17 02:29:19
T1 luogu 5070 题目大意: 现在给你一个长度为$n$的序列,有$m$次询问 每次询问一个区间$[l,r]$排序去重后的序列中长度为1到10的条件的区间个数 满足条件的区间满足每项是前一项数+1的极长区间 思路: 发现每个数$x$只对$[x-10,x+10]$这个区间有影响 直接莫队维护一下数的出现次数判一下左右的情况可以获得暴力分(但码内O2可以A掉管老师的数据 1 #pragma GCC optimize("O2") 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cstdlib> 6 #include<cmath> 7 #include<algorithm> 8 #include<queue> 9 #include<vector> 10 #include<map> 11 #include<set> 12 #define ll long long 13 #define db double 14 #define inf 2139062143 15 #define MAXN 2001000 16 #define rep(i,s,t) for(register int i=(s),i##__end=(t);i<=i##__end;++i) 17 #define dwn(i,s,t)

NOIP基本算法

爱⌒轻易说出口 提交于 2020-01-17 01:11:39
NOIP基本算法 1、二分 poj 2018 Best Cow Fences ▪ http://poj.org/problem?id=2018 ▪ 题意:给定一个正整数数列𝐴,求一个平均数最大的长度不小于𝐿 的子段。 ▪ 二分答案(平均值) ▪ 判定是否存在一个长度不小于𝐿 的子段,平均数不小于二分的值𝑚 ▪ 判定方法: ▪ 把数列中每个数都减去平均值,问题变为是否存在长度不小于𝐿 的子段,子段和非负 ▪转化为前缀和相减的形式𝑠𝑢𝑚 𝑖 − min 0≤𝑗≤𝑖−𝐿 𝑠𝑢𝑚 𝑗 ≥ 0 1 #include<iostream> 2 #include<string> 3 #include<cmath> 4 #include<cstring> 5 #include<cstdio> 6 #include<map> 7 #include<stack> 8 #include<queue> 9 #include<algorithm> 10 #define maxn 100005 11 using namespace std; 12 13 inline int read() 14 { 15 char c=getchar(); 16 int res=0,x=1; 17 while(c<'0'||c>'9') 18 { 19 if(c=='-') 20 x=-1; 21 c=getchar(); 22

AMPPZ2014

本秂侑毒 提交于 2020-01-16 14:53:37
[AMPPZ2014]The Lawyer 记录每天结束的最早的会议以及开始的最晚的会议即可。 #include<cstdio> #define N 500010 int n,m,i,d,a[N],b[N],st[21],en[21]; inline void read(int&a){char c;while(!(((c=getchar())>='0')&&(c<='9')));a=c-'0';while(((c=getchar())>='0')&&(c<='9'))(a*=10)+=c-'0';} int main(){ for(read(n),read(m),i=1;i<=n;i++){ read(a[i]),read(b[i]),read(d); if(!en[d]||b[en[d]]>b[i])en[d]=i; if(!st[d]||a[st[d]]<a[i])st[d]=i; } for(i=1;i<=m;i++)if(!st[i]||b[en[i]]>=a[st[i]])puts("NIE");else printf("TAK %d %d\n",en[i],st[i]); return 0; }    [AMPPZ2014]Petrol 一遍spfa求出d[x]表示离x最近的加油站到x的距离。 对于每条边(x,y,w),将边权重置为d[x]+d[y]+w。

【高手训练】动态规划

核能气质少年 提交于 2020-01-16 09:29:43
T1.成绩单 期末考试结束了,班主任 老师要将成绩单分发到每位同学手中。 老师共有份成绩单,按照编号从到的顺序叠放在桌子上,其中编号为的成绩单分数为。 成绩单是按照批次发放的。发放成绩单时,老师会从当前的一叠成绩单中抽取连续的一段,让这些同学来领取自己的成绩单。 当这批同学领取完毕后,老师再从剩余的成绩单中抽取连续的一段,供下一批同学领取。 经过若干批次的领取后,成绩单将被全部发放到同学手中。 然而,分发成绩单是一件令人头痛的事情,一方面要照顾同学们的心理情绪,不能让分数相差太远的同学在同一批领取成绩单; 另一方面要考虑时间成本,尽量减少领取成绩单的批次数。 对于一个分发成绩单的方案,我们定义其代价为: \(a*k+b*\sum_{i=1}^k(max_i-min_i)^2\) 其中,是方案中分发成绩单的批次数,对于第批分发的成绩单,是最高分数,是最低分数。 是给定的评估参数。现在,请你帮助老师找到代价最小的分发成绩单的方案,并将这个最小的代价告诉老师。 当然,分发成绩单的批次数是由你决定的。 一道题面比较真实的题目 需要离散化,设状态 \(f[i][j][l][r]\) 为在[i,j]表示 \([i,j]\) 区间内取到剩余数字值域为区间 \([l,r]\) 的最小代价。特别的,令 \(f[i][j][0][0]\) 表示 \([i,j]\) 区间取完的最小代价。枚举一个中间点

Educational Codeforces Round 80 (Rated for Div. 2) ABCDE 题解

你说的曾经没有我的故事 提交于 2020-01-16 00:41:47
Educational Codeforces Round 80 (Rated for Div. 2) A. Deadline 如果n>=d 直接yes 否则对于公式 \(x+ceil(d/(x+1))<=n\) 两边同时乘以x+1 会得到一个关于x的一元二次方程, 通过求根公式解出较小的那一个根x1, 然后在 \(x1+-3\) 的范围内找到 \(x+ceil(d/(x+1))\) 的最小值与n比较即可。 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <vector> #include <iomanip> #define ALL(x) (x).begin(), (x).end() #define sz(a) int(a.size()) #define rep(i,x,n) for(int i=x;i<n;i++) #define repd(i,x,n) for(int i=x;i<=n;i++) #define pii pair<int,int> #define pll pair<long

C input - getchar()

天大地大妈咪最大 提交于 2020-01-15 08:25:35
问题 It's a basic question.. but had to ask. For a program like this, if the use case is 123^Z, the program doesnt terminate, even though i put an EOF at the end (Ctrl+Z). Why is that so? It's only when I put an EOF after a CR that it works. Any anwers will be appreciated. Thanks. #include < stdio.h> void main() { int i, nc; nc = 0; i = getchar(); while (i != EOF) { nc = nc + 1; i = getchar(); } printf("Number of characters in file = %d\n", nc); } 回答1: In Windows, the Ctrl-Z shortcut will only

print multiple lines by getchar and putchar

别说谁变了你拦得住时间么 提交于 2020-01-14 10:39:40
问题 Im a beginner learning The C Programming language and using Microsoft visual C++ to write and test code. Below program in C from text(section 1.5.1) copy its input to its output through putchar() and getchar(): #include <stdio.h> int main(void) { int c; while ((c = getchar()) != EOF) putchar(c); return 0;} The program print characters entered by keyboard every time pressing ENTER.As a result,I can only enter one line before printing. I can't find a way to enter multi-line text by keyboard

P5715 【深基3.例8】三位数排序 题解

元气小坏坏 提交于 2020-01-14 07:23:04
快读做法 # include <iostream> # include <algorithm> //sort # include <cstdio> using namespace std ; int x [ 5 ] = { } ; inline int _read ( ) { int x = 0 ; char ch = getchar ( ) ; while ( ! isdigit ( ch ) ) ch = getchar ( ) ; while ( isdigit ( ch ) ) x = x * 10 + ch - 48 , ch = getchar ( ) ; return x ; } int main ( ) { x [ 0 ] = _read ( ) ; x [ 1 ] = _read ( ) ; x [ 2 ] = _read ( ) ; sort ( x , x + 3 ) ; for ( int i = 0 ; i <= 2 ; i ++ ) { cout << x [ i ] << ' ' ; } return 0 ; } ps:sort的语法 sort(begin, end, cmp) 其中 begin 指向待 sort() 的数组的第一个元素, end 指向待 sort ()的数组的最后一个元素的下一个位置, cmp 参数为排序准则,如果没有的话

切蛋糕

独自空忆成欢 提交于 2020-01-13 16:33:35
问题描述 一块边长是2L的正方形蛋糕落在坐标轴内,中心在原点上,现在你竖直切了m次,水平切了n次,中间还挖出了一个长度是2P的正方形的洞,洞的中心也在原点上。求最终蛋糕分成了几块。 输入格式 输入cake.in共四行。 第一行一个数L,第二行一个数P 第三行n个数,表示水平切的位置 第四行m个数,表示竖直切的位置 输出格式 一个数,表示最终那个蛋糕的个数 样例输入 5 3 1 -4 1 样例输出 6 数据范围 30% 的数据 L,P≤10,1≤n,m≤2 100%的数据 1≤L,P,1≤n,m≤100 题解 假设中间没有挖掉一个正方形的洞,那么,最终会有(n+1)*(m+1)个蛋糕。 而事实上中间挖掉一个正方形的洞,这对答案会有什么影响呢? 如图, 有几个小蛋糕完全被正方形的洞覆盖了,这些蛋糕不能算入答案的总个数。 假设水平切有px次经过挖掉的洞,竖直切有py次经过挖掉的洞,显然,完全被正方形覆盖的校蛋糕有(px-1)*(py-1)个; 最终答案就是(n+1)*(m+1)减去完全被洞覆盖的蛋糕数。 1 #include <string> 2 #include <cstdio> 3 int L,P,ans,x[105],y[105],xt,yt,px,py; 4 bool visx[200],visy[200],vis; 5 int main() 6 { 7 int res,i,j

GXOI&GZOI

只谈情不闲聊 提交于 2020-01-12 19:18:57
T1 与或和 2s&&512MB 简明题意:求一个矩阵的所有子序列的 \(and\) 和 和 \(or\) 和; 子矩阵的 \(and\) 和就是所有值 \(and\) 起来; \(or\) 类似; 矩阵边长 \(n<=1000\) ,权值 \(<=2^{31}-1\) \(\&\) 和 \(\ |\) 运算没有逆运算,所以无法算前缀和;但这两种运算中 二进制下的每一位是独立运算的,我们考虑将每个数看成 \(30\) 位 \(01\) 串,一位一位分开算; 先看与运算,枚举每一位 \(i\) ,只有当一个子矩阵这一位全是 \(1\) 时,这个矩阵会在这一位上对答案产生贡献; 所以我们就是要找到全 \(1\) 子矩阵个数,对答案 \(ans1\) 产生个数 \(*(1<<i)\) 的贡献;接下来就是每行一个单调栈的过程; 或运算相反,需要求全 \(0\) 矩阵,但每次贡献应该减去,初始 \(ans2\) 应该是所有子矩阵个数 \(*((1<<30)-1)\) \(Code\) #include<bits/stdc++.h> #define ll long long #define mp make_pair using namespace std; inline int read() { int x=0,fl=1;char st=getchar(); while(st<'0'||st>