Summer training round2 #5 (Training #21)
A:正着DFS一次处理出每个节点有多少个优先级比他低的(包括自己)作为值v[i] 求A B 再反着DFS求优先级比自己高的求C
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define EPS 1.0e-9 #define PI acos(-1.0) #define INF 30000000 #define MOD 1000000007 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define pai pair<int,int> //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; typedef unsigned long long ull; const int maxn=5005; int value[maxn]; int number[maxn]; vector<int> pe[maxn]; vector<int> pe2[maxn]; //queue<int> que; void dfsgo(int x) { number[x]++; int len=pe2[x].size(); for(int i=0;i<len;i++) { if(!value[pe2[x][i]]) { value[pe2[x][i]]=1; dfsgo(pe2[x][i]); } } } void dfsback(int x) { number[x]++; int len=pe[x].size(); for(int i=0;i<len;i++) { if(!value[pe[x][i]]) { value[pe[x][i]]=1; dfsback(pe[x][i]); } } } int main() { int a,b,e,p; int anser1=0; int anser2=0; int anser3=0; cin >> a >> b >> e >> p; mem(value,0); mem(number,0); int now,to; for(int i=1;i<=p;i++) { scanf("%d %d",&now,&to); pe[now].pb(to); pe2[to].pb(now); } for(int i=0;i<e;i++) { mem(value,0); value[i]=1; dfsgo(i); } //for(int i=0;i<e;i++) //cout<<number[i]<<" "; //cout<<endl; for(int i=0;i<e;i++) { int curr=number[i]; if(e-curr<a) anser1++; if(e-curr<b) anser2++; } mem(number,0); for(int i=0;i<e;i++) { mem(value,0); value[i]=1; dfsback(i); } for(int i=0;i<e;i++) if(number[i]>b) anser3++; cout<<anser1<<endl<<anser2<<endl<<anser3; }
C:哈夫曼树做法
D:签到题 直接暴力
E:递推DP
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> #include <cstring> #include <iostream> #include <algorithm> #define EPS 1.0e-9 #define PI acos(-1.0) #define INF 30000000 #define MOD 1000000007 #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define pai pair<int,int> //using ll = long long; //using ull= unsigned long long; //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; typedef long long ll; typedef unsigned long long ull; ll mod=2147483647; int a[2005]; ll ans[2010][2010]; ll anser=0; int main() { int n; while(~scanf("%d",&n)) { //mem(ans,0); anser=0; int x; ll minn; ll maxn; ll now; for(int i=0;i<=n;i++) scanf("%d",&a[i]); ans[1][a[0]]=1; for(int i=2;i<=n;i++) for(int j=1;j<=n+1;j++) { minn=min(a[i-1],j); maxn=max(a[i-1],j); now=a[i]; if(now>minn) { ans[i][minn]=(ans[i][minn]+ans[i-1][j])%mod; } if(now<maxn) { ans[i][maxn]=(ans[i][maxn]+ans[i-1][j])%mod; } } for(int i=1;i<=n+1;i++) anser+=ans[n][i]; cout<<anser%mod<<endl; } }
F!:网络流
G:SG函数
H:问区间[x,y]中有多少数的二进制表示是ABAB..AB型或者A型的,其中A是n个1,B是m个0,n,m>0 直接暴力
J:凸包+扫描线+二分
给出l个大点和s个小点,问有多少小点被三个大点组成的三角形覆盖
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include <bits/stdc++.h> #define MN 10010 #define pi acos(-1.0) using namespace std; typedef long long LL; struct Point { LL x, y; Point(LL x = 0, LL y = 0) : x(x), y(y) {} bool operator<(const Point &rhs) const { return x < rhs.x || (x == rhs.x && y < rhs.y); } Point operator-(const Point &rhs) const { return Point(x - rhs.x, y - rhs.y); } LL operator^(const Point &rhs) const { return x * rhs.y - y * rhs.x; } } a[MN], p[MN]; int n, tot; void ConvexHull() { sort(a + 1, a + 1 + n); tot = 0; for (int i = 1; i <= n; i++) { while (tot > 1 && ((p[tot - 1] - p[tot - 2]) ^ (a[i] - p[tot - 2])) <= 0)tot--; p[tot++] = a[i]; } int k = tot; for (int i = n - 1; i > 0; i--) { while (tot > k && ((p[tot - 1] - p[tot - 2]) ^ (a[i] - p[tot - 2])) <= 0)tot--; p[tot++] = a[i]; } if (n > 1)tot--; } bool Judge(Point A) { int l = 1, r = tot - 2, mid; while (l <= r) { mid = (l + r) / 2; LL a1 = (p[mid] - p[0]) ^ (A - p[0]); LL a2 = (p[mid + 1] - p[0]) ^ (A - p[0]); if (a1 >= 0 && a2 <= 0) { if (((p[mid + 1] - p[mid]) ^ (A - p[mid])) >= 0)return true; return false; } else if (a1 < 0) { r = mid - 1; } else { l = mid + 1; } } return false; } int s, ans = 0; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;; ConvexHull(); cin >> s; Point t; for (int i = 1; i <= s; i++) { cin >> t.x >> t.y; if (Judge(t)) ans++; } printf("%d", ans); return 0; }