好久没打CF,最近又开始忙里偷闲,结果就掉到DIV2了。。。 而且这次做了三题结果还被hack了一道。。。
A和B就不说了
Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and biare not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.
Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).
Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.
The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.
The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.
The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).
Output the answer to the problem.
1 1 -1 -1 2 0 1 0 1 0 0
2
1 1 -1 -1 3 1 0 0 0 1 0 1 1 -3
2
Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<string>
#include<cstdio>
#include<map>
using namespace std;
#define ll long long
struct node{ll a,b,c;};
int n;
node s,t, nd;
bool f(node x){
return (nd.a*s.a+nd.b*s.b+nd.c>0)^(nd.a*t.a+nd.b*t.b+nd.c>0);
}
int main()
{
cin>>s.a>>s.b>>t.a>>t.b;
cin>>n;
int ans=0;
for(int i=1;i<=n;i++)
{
cin>>nd.a>>nd.b>>nd.c;
if(f(nd))ans++;
}
cout<<ans<<endl;
}
You have written on a piece of paper an array of n positive integers a[1], a[2], ..., a[n] and m good pairs of integers (i1, j1), (i2, j2), ..., (im, jm). Each good pair (ik, jk) meets the following conditions: ik + jk is an odd number and 1 ≤ ik < jk ≤ n.
In one operation you can perform a sequence of actions:
- take one of the good pairs (ik, jk) and some integer v (v > 1), which divides both numbers a[ik] and a[jk];
- divide both numbers by v, i. e. perform the assignments:
and
.
Determine the maximum number of operations you can sequentially perform on the given array. Note that one pair may be used several times in the described operations.
The first line contains two space-separated integers n, m (2 ≤ n ≤ 100, 1 ≤ m ≤ 100).
The second line contains n space-separated integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109) — the description of the array.
The following m lines contain the description of good pairs. The k-th line contains two space-separated integers ik, jk (1 ≤ ik < jk ≤ n,ik + jk is an odd number).
It is guaranteed that all the good pairs are distinct.
Output the answer for the problem.
3 2 8 3 8 1 2 2 3
0
3 2 8 12 8 1 2 2 3
2
bool f(int u){
for(int i=0;i<edge[u].size();i++){
int v=edge[u][i];
if(vis[v])continue;
vis[v]=1;
if(pei[v]==0||f(pei[v])){
pei[v]=u;
return 1;
}
}
return 0;
}
int main()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
vis[j]=0;
if(f(i)){
ans+=1;
}
}
}
将每个点的value分解成每个质数因子,所有质数因子的集合构成了二分图的顶点。然后建立边,遍历m个pair,每个pair中有两个质数因子的集合,然后两个集合中的每个点对分别判断是否该连一条边。
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<set>
#include<stack>
#include<string>
#include<cstdio>
#include<map>
using namespace std;
#define ll long long
int n,m,x,y;
vector<int>v[101];
int num[101];
int p[2][2001],id[2];
vector<int>edge[2001];
int vis[2001];
int pei[2001];
bool f(int u){
for(int i=0;i<edge[u].size();i++){
int v=edge[u][i];
if(vis[v])continue;
vis[v]=1;
if(pei[v]==0||f(pei[v])){
pei[v]=u;
return 1;
}
}
return 0;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>x;
int j=2;
while(x>1&&j*j<=x){
while(x%j==0)
id[i%2]++,p[i%2][id[i%2]]=j,
num[i]++,v[i].push_back(id[i%2]),x/=j;
j++;
}
if(x>1)id[i%2]++,p[i%2][id[i%2]]=x,
num[i]++,v[i].push_back(id[i%2]);
}
for(int i=1;i<=m;i++){
cin>>x>>y;
if(num[x]==0||num[y]==0)continue;
for(int j=0;j<v[x].size();j++){
int le= p[x%2][v[x][j]];
for(int k=0;k<v[y].size();k++){
int ri=p[y%2][v[y][k]];
if(le!=ri)continue;
if(x%2)
edge[v[x][j]].push_back(v[y][k]);
else edge[v[y][k]].push_back(v[x][j]);
}
}
}
int ans=0;
for(int i=1;i<=id[1];i++){
for(int j=1;j<=id[0];j++)
vis[j]=0;
if(f(i))ans++;
}
cout<<ans<<endl;
}
本文解析了CF竞赛中的两道题目:C题“疯狂城市”要求计算从家到大学的最少穿越街区步数;E题“数组与操作”探讨如何通过特定操作最大化操作次数,涉及二分图与匈牙利算法。
1498

被折叠的 条评论
为什么被折叠?



