vis

Educational Codeforces Round 82 (Rated for Div. 2)

守給你的承諾、 提交于 2020-02-13 01:45:31
A 题意: 一串01字符串,求最少删掉几个0,使得1连续 思路: 找1的l,r,数出区间0的个数 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define ll long long 4 #define il inline 5 #define it register int 6 #define inf 0x3f3f3f3f 7 #define lowbit(x) (x)&(-x) 8 #define mem(a,b) memset(a,b,sizeof(a)) 9 #define mod 998244353 10 const int maxn=1e6+10; 11 int n,k; 12 char s[200]; 13 int main(){ 14 scanf("%d",&n); 15 while(n--){ 16 scanf("%s",s); 17 int l1=strlen(s),sum=0,l=-1,r=-1; 18 for(it i=0;i<l1;i++){ 19 if(s[i]=='1' && l==-1){ 20 l=i; 21 } 22 else if(s[i]=='1'){ 23 r=i; 24 } 25 } 26 for(it i=l;i<=r;i++){ 27 if(s[i]=='0'){sum++;}

hdu4289城市与歹徒 网络流

我们两清 提交于 2020-02-12 22:03:37
  题目大意就是要从歹徒要从s点运送货物到t点,警察在一些城市拦截,在每一个城市拦截都有一定的花费,问最小花费是多少可以拦截住歹徒。   呐,在某些点设置障碍,使得整张图不能在联通,我们知道一个类似的问题:割断某些点使得图不能再联通——最小割问题,那么把这些点拆了,点权变为边权,不就是最小割问题了么,我们知道最小割等于最大流,所以这就是一个拆点+网络流的问题。   代码: #include<iostream> #include<cstring> #include<cstdio> #include<queue> using namespace std; const int maxn=2100,maxm=50005; const int inf=2147483647; int n,m; int S,T; int x,y; struct zhw{ int to,last,val; }tu[maxm<<2]; int tot,head[maxn]; void add(int x,int y,int v) { tot++,tu[tot].last=head[x],head[x]=tot,tu[tot].to=y,tu[tot].val=v; tot++,tu[tot].last=head[y],head[y]=tot,tu[tot].to=x,tu[tot].val=0; } int ans

解题报告:luogu P5020(NOIP 2018 D1T2)

久未见 提交于 2020-02-12 21:38:52
题目链接: P5020 货币系统 \(NOIP\) 的题挺精华啊。 开始感觉自己有隐约的思路,但感觉太暴力,连数据范围都没看,就去看题解了(不会啊)。 听说是 \(dp\) 又是一惊,直接弃疗。 其实只是个简单的筛法吧,和线性筛啥的有异曲同工之处,类似模拟打表,把能表示的都筛一遍就好了,大概是 \(O(n\;max(a_i)\) 的复杂度,可以通过本题。 \(Code\) : #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> using namespace std; int t,n,a[20005]; int vis[25005]={0}; int main() { scanf("%d",&t); while(t--) { scanf("%d",&n); int maxn=-1; memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) scanf("%d",&a[i]),maxn=max(maxn,a[i]); sort(a+1,a+n+1); int ans=0; for(int i=1;i<=n;i++) { if(vis[a[i]]) continue; else ans++,vis[a[i]]=1;

2018-2019 ACM-ICPC, Asia Seoul Regional Contest

£可爱£侵袭症+ 提交于 2020-02-12 20:28:44
ProblemA Circuits Solved. 题意: 有$n$个矩形,可以放两条平行与$x$轴的线,求怎么放置两条无线长的平行于$x$轴的线,使得他们与矩形相交个数最多 如果一个矩形同时与两条线相交,只算一次。 思路: 离散化后枚举一根线,另一根线用线段树维护,扫描线思想 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define N 400010 5 int n; 6 int b[N]; 7 int x[N], y[N]; 8 vector <int> in[N], out[N]; 9 int ans[N]; 10 11 namespace SEG 12 { 13 struct node 14 { 15 int Max, lazy; 16 node () {} 17 node (int Max, int lazy) : Max(Max), lazy(lazy) {} 18 void init() { Max = lazy = 0; } 19 void add(int x) 20 { 21 Max += x; 22 lazy += x; 23 } 24 node operator + (const node &other) const 25 { 26 node res; res.init(); 27 res

POJ1094 Sorting It All Out

不羁岁月 提交于 2020-02-12 18:07:25
An ascending sorted sequence of distinct values is one in which some form of a less-than operator is used to order the elements from smallest to largest. For example, the sorted sequence A, B, C, D implies that A < B, B < C and C < D. in this problem, we will give you a set of relations of the form A < B and ask you to determine whether a sorted order has been specified or not. Input Input consists of multiple problem instances. Each instance starts with a line containing two positive integers n and m. the first value indicated the number of objects to sort, where 2 <= n <= 26. The objects to

hdu 1716 排列2(DFS搜索)

我的未来我决定 提交于 2020-02-12 03:08:51
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1716 排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5692 Accepted Submission(s): 2178 Problem Description Ray又对数字的列产生了兴趣: 现有四张卡片,用这四张卡片能排列出很多不同的4位数,要求按从小到大的顺序输出这些4位数。 Input 每组数据占一行,代表四张卡片上的数字(0<=数字<=9),如果四张卡片都是0,则输入结束。 Output 对每组卡片按从小到大的顺序输出所有能由这四张卡片组成的4位数,千位数字相同的在同一行,同一行中每个四位数间用空格分隔。 每组输出数据间空一行,最后一组数据后面没有空行。 Sample Input 1 2 3 4 1 1 2 3 0 1 2 3 0 0 0 0 Sample Output 1234 1243 1324 1342 1423 1432 2134 2143 2314 2341 2413 2431 3124 3142 3214 3241 3412 3421 4123 4132 4213 4231 4312 4321

树的重心 学习笔记

不打扰是莪最后的温柔 提交于 2020-02-12 00:09:07
第一版 关于 树的重心 有配图 有文字讲解 关于 Godfather 有AC代码 文字说明 关于 centroid 本人蒟蒻这晚上只写了55pts(以后会有AC代码的) 手把手教你分析时间复杂度 考场写暴力得省一心得 有了树的重心的性质拓展 树的重心 在树的问题中,会遇到一些题目。时问你树的重心的, 不会就凉了 , 就像CSP-S2019 定义 度娘的定义是这样的 : 找到一个点,其所有的子树中最大的子树节点数最少,那么这个点就是这棵树的重心,删去重心后,生成的多棵树尽可能平衡。 性质 树中所有点到某个点的距离和中,到重心的距离和是最小的,如果有两个重心,他们的距离和一样。 把两棵树通过一条边相连,新的树的重心在原来两棵树重心的连线上。 一棵树添加或者删除一个节点,树的重心最多只移动一条边的位置。 一棵树最多有两个重心,且相邻。 事实上,有个性质度娘没说,在 centroid 中提到了 Godfather 原题链接 这道题 我们可以用树形dp来解决这个问题令 \(d_i\) 表示你把他转为有根树之后以 \(i\) 为根的子树所包含节点个数 采用邻接表存边,我们能可以十分简单的解决此问题 我们判断一个点是否树的重心的方法是去掉这个点所有子树的最大连通块最小 事实上,这些连通块就是,这个节点上面的部分和以这个点所有儿子为根的子树的最大值 这是AC代码 #include

Luogu2040 | 打开所有的灯 (广搜+状压)

ε祈祈猫儿з 提交于 2020-02-11 14:27:57
题目背景 pmshz在玩一个益(ruo)智(zhi)的小游戏,目的是打开九盏灯所有的灯,这样的游戏难倒了pmshz。。。 题目描述 这个灯很奇(fan)怪(ren),点一下就会将这个灯和其周围四盏灯的开关状态全部改变。现在你的任务就是就是告诉pmshz要全部打开这些灯。 例如: 0 1 1 1 0 0 1 0 1 点一下最中间的灯 \([2,2]\) 就变成了 0 0 1 0 1 1 1 1 1 再点一下左上角的灯 \([1,1]\) 就变成了 1 1 1 1 1 1 1 1 1 达成目标。最少需要 \(2\) 步。 输出 \(2\) 即可。 输入格式 九个数字, \(3*3\) 的格式输入,每两个数字中间只有一个空格,表示灯初始的开关状态。( \(0\) 表示关, \(1\) 表示开) 输出格式 一个整数,表示最少打开所有灯所需要的步数。 输入输出样例 输入 #1 0 1 1 1 0 0 1 0 1 输出 #1 2 —————————————————————————————————————— 想了一会没有什么特别好的方法,所以直接搜索了,时间很充裕~ 用二进制数表示九盏灯的开关状态, \(2^9 = 512\) 状态数允许完全被记录。 用 \(way\) 数组储存按下某栈灯时候会发生变化的灯的编号。 之后就是常规的广搜, \(vis\)

[POI2006] SZK-Schools - 费用流

老子叫甜甜 提交于 2020-02-11 09:29:21
差不多就是个二分图带权匹配?(我还是敲费用流吧) 每个点向着自己能到的学校连边,费用按题意设定 跑最小费用最大流即可 #include <bits/stdc++.h> using namespace std; // Init: init() // Input: make(u,v,cap,cost) // Solver: solve(s,t) // Output: ans, cost namespace flow { const int N = 100005; const int M = 1000005; const int inf = 1e+9; struct Edge { int p, c, w, nxt = -1; } e[N]; int s, t, tans, ans, cost, ind, bus[N], qhead = 0, qtail = -1, qu[M],vis[N], dist[N]; void graph_link(int p, int q, int c, int w) { e[ind].p = q; e[ind].c = c; e[ind].w = w; e[ind].nxt = bus[p]; bus[p] = ind; ++ind; } void make(int p, int q, int c, int w) { graph_link(p, q, c,

POJ - 3278 - Catch That Cow 【bfs】

荒凉一梦 提交于 2020-02-11 06:51:10
题意 人位置在n 牛位置在k 人可以两种方式行动,而牛不动 左右移动一格 乘以两倍移动 思路 标准bfs,具体看代码 code # include <iostream> # include <queue> # include <cstring> # define endl '\n' using namespace std ; const int maxn = 2e5 + 10 ; int n , k ; bool vis [ maxn ] ; struct node { int x , step ; } now , nex ; int dx [ ] = { 1 , - 1 } ; int bfs ( ) { memset ( vis , false , sizeof ( vis ) ) ; now . x = n , now . step = 0 ; queue < node > q ; q . push ( now ) ; while ( ! q . empty ( ) ) { now = q . front ( ) ; q . pop ( ) ; if ( now . x == k ) return now . step ; for ( int i = 0 ; i < 2 ; i ++ ) { nex . x = now . x + dx [ i ] ; nex . step