getchar

线段树合并[学习笔记]

♀尐吖头ヾ 提交于 2019-12-06 10:25:33
前置知识: 动态开点线段树/主席树 线段树合并,跟名字一样,就是合并两颗线段树的信息… 合并两颗线段树的方法是 递归下去一直合并两个如果俩节点都有…就新建一个维护当前两个的信息然后取而代之 如果只有一个有 那就返回那一个就够了… 这个blog内借鉴了一些洛谷的题解…因为作者实在菜的可怜 ( 懒 ) 先放个 板子题 吧 求子树几个比他权值大的 inline int Merge(int u , int v) { if(!u || ! v) return u | v ; int t = ++ cnt ; sum[t] = sum[u] + sum[v] ; ls[t] = Merge(ls[u] , ls[v]) ; rs[t] = Merge(rs[u] , rs[v]) ; return t ; } 就像是这样… 然后每次递归到最底层 下属信息合并…然后查询 最后输出,没了。 // luogu-judger-enable-o2 //Isaunoya #include<bits/stdc++.h> using namespace std ; inline int read() { register int x = 0 ; register int f = 1 ; register char c = getchar() ; for( ; ! isdigit(c) ; c =

可持久化[学习笔记]

喜夏-厌秋 提交于 2019-12-06 08:01:02
可持久化应该都知道… 就是可以回退历史版本…以及区间查询一些东西比如说k值…(不过k值还不是主要用处?) 可持久化略解: 就是复制其他的根节点 按照过去版本添加当前版本新建节点…和之前是独立的 但是是共用节点…从而使内存减少了很多… 按照以前的版本新建节点到当前的版本…复制版本就是直接复制根节点 rt[i]=rt[pre]; 可持久化线段树 求静态区间k大… 就是弄个前缀和的东西 l~mid mid+1~r的这段值域中二分没了… #include <cstdio> #include <algorithm> using ll = long long ; using namespace std ; int read() { int x = 0 , f = 1 ; char c = getchar() ; while(c < '0' || c > '9') { if(c == '-') f = -1 ; c = getchar() ; } while(c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c & 15) ; c = getchar() ; } return x * f ; } template < class T > void print(T x , char c = '\n') { static char _st[100]

About storing getchar() returned value inside a char-variable

核能气质少年 提交于 2019-12-06 07:46:35
I know the following code is broken -- getchar() returns an int not a char -- #include <stdio.h> int main(int argc, char* argv[]) { char single_byte = getchar(); while (single_byte != EOF) { single_byte = getchar(); printf("getchar() != EOF is %d.\n", single_byte != EOF); if (single_byte == EOF) printf("EOF is implemented in terms of 0x%x.\n", single_byte); } return 0; } though I would expect that a typical output of it (using /dev/urandom as the input-stream for instance) would have been at last EOF is implemented in terms of 0xff , and not the following $ ./silly < /dev/urandom getchar() !=

穿越栅栏 Overfencing

余生长醉 提交于 2019-12-06 06:29:57
题解区里都是一次性走两步 这里我就说一点 按普通(每次走一步)的来最后 \(+1\) 再除以 \(2\) 就行了 另外输入时加个时间限制 ( \(q++ if(q>=w)break;\) ) /* ID:death_r2 TASK:maze1 LANG:C++ */ #include <queue> #include <cstdio> #include <string> #include <iostream> #include <algorithm> using namespace std; #define reg register int #define isdigit(x) ('0' <= x&&x <= '9') template<typename T> inline T Read(T Type) { T x = 0,f = 1; char a = getchar(); while(!isdigit(a)) {if(a == '-') f = -1;a = getchar();} while(isdigit(a)) {x = (x << 1) + (x << 3) + (a ^ '0');a = getchar();} return x * f; } string mp[210]; bool vis[3][210][210]; int cnt,ans,d[3][210]

CSP-J总结&题解

拥有回忆 提交于 2019-12-06 04:31:25
总结:这一次,最后一次,还是不行啊。 没有FCLOSE,血的教训。 首先一二题没什么好讲的,秒切。但是第三题由于一开始看出来是完全背包,但是好像又不是,去年又有摆渡车阴影,就先跳到了第四题。感觉还不错。但是最后还是翻车了。下来测出来只有两百出头,但是已经没有机会了。只能在提高努力了。fclose。再也不会忘了。 题解 第一题 水题切了。 #include<cstdio> #include<iostream> #include<fstream> #include<algorithm> #include<cstring> using namespace std; int read(){ int res=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ res=res*10+(ch-'0'); ch=getchar(); } return res*f; } char s[9]; int ans; int main(){ for(int i=1;i<=8;++i){ cin>>s[i]; if(s[i]=='1')ans++; } printf("%d",ans); return 0; } View Code 第二题 模拟一下

Codeforces Round #603 (Div. 2)

我的未来我决定 提交于 2019-12-06 04:22:46
A. Sweet Problem 题目大意:你有不同数量的红绿蓝三种颜色的糖果,每天想吃两颗颜色不同的糖果,问能吃多少天。 2019ICPC沈阳赛区flowers的弱化题qwqflowers是有n种花选m种不同种类的一朵花组成一束花问最多能组成多少束。 是否可行具有单调性,二分天数,只要选的糖果数小于等于天数,就一定存在某种方案,不会出现某一天吃两只同样的糖果。 1 #include <bits/stdc++.h> 2 #define MIN(a,b) ((((a)<(b)?(a):(b)))) 3 #define MAX(a,b) ((((a)>(b)?(a):(b)))) 4 #define ABS(a) ((((a)>0?(a):-(a)))) 5 using namespace std; 6 7 template <typename T> 8 void read(T &x) { 9 int s = 0, c = getchar(); 10 x = 0; 11 while (isspace(c)) c = getchar(); 12 if (c == 45) s = 1, c = getchar(); 13 while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); 14 if (s) x =

模板 - 算法基础 - 输入输出

对着背影说爱祢 提交于 2019-12-06 02:27:09
template<typename T> void Scanf(T &x) { x = 0; char c = getchar(); while(!isdigit(c)) c = getchar(); while(isdigit(c)) { x = x * 10 + (c - '0'); c = getchar(); } } template<typename T1, typename T2> void Scanf(T1 &x1, T2 &x2) { Scanf(x1); Scanf(x2); } template<typename T1, typename T2, typename T3> void Scanf(T1 &x1, T2 &x2, T3 &x3) { Scanf(x1); Scanf(x2); Scanf(x3); } template<typename T1, typename T2, typename T3, typename T4> void Scanf(T1 &x1, T2 &x2, T3 &x3, T4 &x4) { Scanf(x1); Scanf(x2); Scanf(x3); Scanf(x4); } template<typename T> void Scanf(T* a, int n) { for(int i = 1; i <= n; ++i)

网络流学习笔记

落花浮王杯 提交于 2019-12-06 01:55:10
目录 网络流学习笔记 网络流资料 最大流dinic 费用流dinic 无源汇有上下界可行流 有源汇有上下界可行流 (最大流/最小流) 最大流 最小流 最大权闭合子图 证明(proof) 例题 最大密度子图 二分图的最小点权覆盖集和最大点权独立集 网络流24题中的思想与解题方案 网络流学习笔记 网络流资料 最大流dinic #include<iostream> #include<cstdio> #include<cstring> #include<queue> using namespace std; const int INF = 1e9; const int N = 10005; const int M = 200005; int to[M], ne[M]; int w[M], h[N], tot = -1; inline void add(int x,int y,int z) { ne[++tot] = h[x], h[x] = tot; to[tot] = y, w[tot] = z; } template <typename T> void read(T &x) { x = 0; int f = 0; char c = getchar(); for (;!isdigit(c);c=getchar()) if (c=='-') f=1; for (;isdigit(c);c

codeforces #602 div2 ABCD

跟風遠走 提交于 2019-12-06 00:19:27
A. Math Problem Description 给出n个区间,求一个最短区间使得这个区间与n个区间都有交集 Solution 对$l,r$排序,求出$l_{max}-r_{min}$即可。 做题时被这个卡,真的憨憨。 1 #include <algorithm> 2 #include <cctype> 3 #include <cmath> 4 #include <cstdio> 5 #include <cstdlib> 6 #include <cstring> 7 #include <iostream> 8 #include <map> 9 #include <numeric> 10 #include <queue> 11 #include <set> 12 #include <stack> 13 #if __cplusplus >= 201103L 14 #include <unordered_map> 15 #include <unordered_set> 16 #endif 17 #include <vector> 18 #define lson rt << 1, l, mid 19 #define rson rt << 1 | 1, mid + 1, r 20 #define LONG_LONG_MAX 9223372036854775807LL 21

C指针的运算

感情迁移 提交于 2019-12-05 23:34:00
指针的运算在数组中才有意义 int *p; p++,一定是在一片连续的区域才有意义,当然越界也会带来诸多问题。 void main() { int num = 10; int *p = &num;//这根本无界可言 p++; printf("%d\n",*p); getchar(); } 输出结果: #include<stdio.h> #include<stdlib.h> #include<Windows.h> void main() { int num[10] = {1,2,3,4,5,6,7,8,9,10}; int *a = num; for (int *p =num+9; p>=a;p--) { printf("%d\n", *p); } getchar(); } #include<stdio.h> #include<stdlib.h> #include<Windows.h> void main() { int num[10] = {1,2,3,4,5,6,7,8,9,10}; int *a = num; a = a + 3;//后移3个元素,到元素4 printf("%d\n",*a);//4 a = a - 2;//从元素4前移2个单位到元素2 printf("%d\n", *a);//2 getchar(); } 输出结果: 指针可以比大小,所谓大的地址上比较靠后