vis

模拟(所有边权)

左心房为你撑大大i 提交于 2019-12-06 04:24:36
https://acm.ecnu.edu.cn/contest/231/problem/D/ 题意:给你n个点,且给出n个点的点权,给出特殊点(值为1),特殊点有到其他任何边权。 边权等于两点权值乘积。求所以边权之和。 解法:一边遍历一遍筛除特殊点。 //#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <string> #include <stdio.h> #include <queue> #include <stack> #include <map> #include <set> #include <string.h> #include<time.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF 0x3f3f63f3f #define mod 20191117 #define PI acos(-1) using

网络流扩展知识

时间秒杀一切 提交于 2019-12-06 03:34:58
网络流扩展知识 最小费用最大流 luogu P3381 【模板】最小费用最大流 解析: 先用spfa求出最短路径(单位流量费用最少) 多路增广流掉这些流量(spfa没有记录dep信息,但凭借dis[]信息的关系不能保证不会访问之前访问过的节点,所以需要vis[]标记) code #include<bits/stdc++.h> #include<iostream> using namespace std; #define CL(a,b) memset(a,b,sizeof(a)) #define db(x) cout<<"["<<#x<<"]="<<x<<endl #define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) const int inf = 0x3f3f3f3f; const int maxn = 5e3+100; const int maxm = 5e4+100; struct edge{ int u,v,cap,cost,nxt; }es[maxm*100]; int cnt, head[maxn],dis[maxn],vis[maxn]; void addEdge(int u,int v,int cap,int cost){ es[cnt].u = u, es[cnt].v = v,es

CodeForces - 1255D (模拟+构造+贪心)

情到浓时终转凉″ 提交于 2019-12-05 22:18:31
题意 https://vjudge.net/problem/CodeForces-1255D rxc的农场里'R'表示有米,现在有K只鸡,给这k只鸡选一些格子,每个鸡可以有多个格子(每个鸡至少吃一个米),但是每个鸡的格子必须连通。问吃到最多的米和最少的米的差最小是多少。 思路 如果农场一共有cnt个米,那么最优的分配肯定是差值为1或0,即给每个鸡先分cnt/k个米,然后把多余的分配给每个鸡。因为鸡的格子必须是连通的,所以可以考虑类似蛇形填数的方法,每找到cnt/k(多余的类似)个米就换下一只鸡,这样就能保证是连通而且差值最小了。 代码写的有点冗长,我的判断退出的方法是判断当前点的上下左右是否被填过(先把所有位置都赋值成填过,再把rxc的位置赋值为未填过),如果都填过了,那么就结束。 代码 #include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define ll long long const int N=105; const int mod=1e9+7; const double eps=1e-8; const double PI = acos(-1.0); #define lowbit(x) (x&(-x)) char g[N][N],ch,res[N][N]; int a,b,now,vis[N

HDU 5917 Instability (Ramsey定理)

十年热恋 提交于 2019-12-05 20:49:50
题意: n个点,m个边,求符合条件的点集合数(一个集合中有三个元素相互认识或不认识为符合条件) 思路: Ramsey定理:6 个人中至少存在3人相互认识或者相互不认识。 根据定理,我们能够算出选择的集合点数大于等于6的结果: 2 n − ∑ 5 i = 0 ( i n ) 2 n − ∑ i = 0 5 ( i n ) //--> ,现在剩下的就是低于6个大于等于3个,结果就是纯暴力地for,因为实际计算次数为 ( 5 n ) + ( 4 n ) + ( 3 n ) ( 5 n ) + ( 4 n ) + ( 3 n ) //--> ,所以不会T 错误及反思: 代码: #include<bits/stdc++.h> using namespace std ; const int N = 55 ; const int mod = 1e9 + 7 ; bool vis[N][N]; int n,m; long long ans,c[N][N]; void init(){ c[ 1 ][ 1 ]=c[ 0 ][ 1 ]= 1 ; for ( int i= 2 ;i<=n;i++) for ( int j= 0 ;j<=i;j++){ if (j== 0 ) c[j][i]= 1 ; else c[j][i]=(c[j][i- 1 ]+c[j- 1 ][i- 1 ])%mod; } }

C - League of Leesins-构造

泪湿孤枕 提交于 2019-12-05 20:15:57
题意就是给多个三元组(内部没有顺序),让你构造一个序列,使得所有的三元组都是存在的 简单的思考后就会发现一个简单的思路,开头的数一定只出现一次,进而可以找到头或者尾部的第一个三元组,然后我们知道序列最开始的元素是什么,但是后面两个我们并不知道,两个的顺序是什么,但是我们知道,两个相邻的元素,可以找到连与其相邻的两个元素,然后就很简单了,每次查找下一个元素,然后看前面两个元素中,与第三个元素是否是相邻的,用map瞎搞就行,但是要注意代码的交叉覆盖 #include <bits/stdc++.h> #define LL long long #define pii pair<int,int> #define rep(i,j,k) for(int i=j;i<=k;i++) #define per(i,j,k) for(int i=j;i>=k;i--) #define mp make_pair using namespace std; const int maxx =2e5+6; map<pii,int>p; map<pii,int>pp; int vis[maxx]; int ar[maxx][3]; vector<int>ans; int main(){ int n; scanf("%d",&n); p.clear(); int a,b,c; memset(vis,0,sizeof

acm博弈论基础总结

空扰寡人 提交于 2019-12-05 19:53:57
acm博弈论基础总结 常见博弈结论 Nim 问题 : 共有 N 堆石子,编号 1..n ,第 i 堆中有个 a[i] 个石子。 每一次操作 Alice 和 Bob 可以从任意一堆石子中取出任意数量的石子,至少取一颗,至多取出这一堆剩下的所有石子。 结论 :对于一个局面,当且仅当 a[1] xor a[2] xor ...xor a[n]=0 时,该局面为 P 局面,即必败局面。 证明 :二进制位证明即可。 Moore’s Nim 问题 :n 堆石子,每次从不超过 k 堆中取任意多个石子,最后不能取的人失败。 结论 : 这是一个 nim 游戏的变形:把 n 堆石子的石子数用二进制表示,统计每个二进制位上 1 的个数,若每一位上 1 的个数 mod(k+1) 全部为 0 ,则必败,否则必胜。 ( 先手 ) 证明 :分类讨论 N/P 状态。 Staircase N im 问题 : 在阶梯上进行,每层有若干个石子,每次可以选择任意层的任意个石子将其移动到该层的下一层。最后不能操作的人输。 结论 :在 奇数堆的石子做 Nim 。 证明 : 阶梯博弈经过转换可以变为 Nim. 把所有奇数阶梯看成 N 堆石子做 nim 。把石子从奇数堆移动到偶数堆可以理解为拿走石子,就相当于几个奇数堆的石子在做 Nim 。 New Nim 问题 : 在第一个回合中,第一个游戏者可以直接拿走若干个整堆的火柴

CodeForces - 1255C(构造+模拟)

狂风中的少年 提交于 2019-12-05 19:07:53
题意 https://vjudge.net/problem/CodeForces-1255C 一个长度为n的序列,给你n-2个三元组,比如p=[1,4,2,3,5],那么三元组为[1,4,2],[4,2,3],[2,3,5],其中每个三元组内的元素可以交换位置,整个三元组也可以和别的三元组整体交换位置,但不能交换不同三元组的数。求这个序列。 思路 记录每个数在所有三元组出现的次数、和每个数连了哪些数(和哪些数在一个三元组里),其中出现次数为1的肯定是序列的头或尾,因为序列可以反转(得到同样的三元组),所以随便选一个出现次数为1的数当头,然后这个数连的点中出现次数为2的就是第二个数。后面的数可以通过判断前面两个数连的数是否有相同,如果有,那么这个数就是第三个数,以此类推。 代码 #include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define ll long long const int N=200005; const int mod=1e9+7; const double eps=1e-8; const double PI = acos(-1.0); #define lowbit(x) (x&(-x)) int cnt[N],ans[N],vis[N]; vector<int> v[N]; int

Codeforces Round #438 by Sberbank and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A,B,C【真的菜·】

你离开我真会死。 提交于 2019-12-05 17:55:49
8说了 1 #include<bits/stdc++.h> 2 3 using namespace std; 4 #define int long long 5 6 signed main(){ 7 string str; 8 cin>>str; 9 int _; 10 cin>>_; 11 int flag1=0; 12 int flag2=0; 13 int flag3=0; 14 int flag4=0; 15 while(_--){ 16 string s; 17 cin>>s; 18 if(s==str){ 19 flag4=1; 20 continue; 21 } 22 if(s[0]==str[1]&&s[1]==str[0]){ 23 flag3=1; 24 continue; 25 } 26 if(str[0]==s[1]){ 27 flag1=1; 28 } 29 if(str[1]==s[0]){ 30 flag2=1; 31 } 32 } 33 // cout<<flag1<<" "<<flag2<<" "<<flag3<<" "<<flag4; 34 if(flag3||flag4||(flag1+flag2==2)){ 35 printf("YES\n"); 36 }else{ 37 printf("NO\n"); 38 } 39 return 0;

训练16

我是研究僧i 提交于 2019-12-05 12:28:09
3991: Electoral Rolls Revision 题意:对n对数排序,从小到大输出 #include<bits/stdc++.h> using namespace std; inline int read() { int x=0; char c=getchar(); bool flag=0; while(c<'0'||c>'9'){if(c=='-')flag=1; c=getchar();} while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();} return flag?-x:x; } priority_queue<int,vector<int> ,greater<int> > q; int main() { int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { int x=read(); q.push(x); } } while(!q.empty()) { printf("%d\n",q.top()); q.pop(); } } //快读+优先队列 4603: Interesting Calculator 题意:模拟计算器,每个按键有一个花费,问使数x变成数y的最小花费位多少,以及按键次数

bfs(同一最短路径)

自作多情 提交于 2019-12-05 11:45:10
http://oj.jxust.edu.cn/contest/Problem?id=1702&pid=7 题意:现在有两个相同大小的地图,左上角为起点,右下角问终点。问是否存在同一条最短路径。最短距离一样,他们走的路径也一样。 n 行 m 列(1 <= n , m <= 500) 存在就输出YES , 否则NO; 解法:三个bfs (其中一个是合并的图),判断三个最短路径是否相等且不为-1(不存在)。 //#include <bits/stdc++.h> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <iostream> #include <string> #include <stdio.h> #include <queue> #include <stack> #include <map> #include <set> #include <string.h> #include <vector> #define ME(x , y) memset(x , y , sizeof(x)) #define SF(n) scanf("%d" , &n) #define rep(i , n) for(int i = 0 ; i < n ; i ++) #define INF