A. God a graph theory problem (god.cpp)
Topic Link
The meaning of problems
Given an undirected graph, each point has the right to punctual, delete points is the cost of a weight not removed all nodes connected to it and , find the minimum cost to delete all points.
solution
Consider any two points connected \ (U \) and \ (V \) .
Set \ (U \) point with a weight of \ (A \) .
\ (V \) point with a weight of \ (B \) .
And \ (U \) weight value of the node and connected, by subtracting \ (V \) point weights, the result is \ (C \) .
And \ (V \) weight value of the node and connected, by subtracting \ (U \) point weights, the result is \ (D \) .
So, if you delete \ (U \) , then delete \ (v \) , the price for \ (b + c + d \) .
If you delete \ (v \) , then delete \ (U \) , a consideration of \ (A + c + d \) .
So if \ (A> b \) , should delete \ (U \) , then delete \ (v \) .
Otherwise, you should delete the \ (v \) , then delete \ (U \) .
That should delete \ (u, v \) greater weight in points.
Obviously this conclusion can be generalized to all points.
So greedy strategy is to delete large descending weights point.
Code
#include<bits/stdc++.h>
const int SIZE=200005;
int x[SIZE],head[SIZE],nex[SIZE],to[SIZE],Tot,Ans[SIZE];
void Link(int u,int v)
{
nex[++Tot]=head[u];head[u]=Tot;to[Tot]=v;
nex[++Tot]=head[v];head[v]=Tot;to[Tot]=u;
}
struct node
{
int x,pos;
bool operator <(const node &p)const
{
return x>p.x;
}
}Tem[SIZE];
bool Removed[SIZE];
long long Tot_Ans;
int main()
{
freopen("god.in","r",stdin);
freopen("god.out","w",stdout);
int n,m,u,v;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&x[i]);
Tem[i]=(node){x[i],i};
}
std::sort(Tem+1,Tem+1+n);
for(int i=1;i<=m;i++)
{
scanf("%d%d",&u,&v);
Link(u,v);
Ans[u]+=x[v];
Ans[v]+=x[u];
}
for(int o=1;o<=n;o++)
{
u=Tem[o].pos;
for(int i=head[u];i;i=nex[i])
{
v=to[i];
if(Removed[v])continue;
Ans[v]-=x[u];
}
Tot_Ans+=Ans[u];
Removed[u]=1;
}
printf("%lld",Tot_Ans);
return 0;
}
B. Bitwise (bit.cpp)
Topic Link
The meaning of problems
Custom number \ (n \) value of \ (k \) is \ (| n | \) digits of the sum.
Seeking to meet less than \ (n-\) , value \ (K +. 1 \) , and the maximum number.
\ (| n | \ 10 ^ {100000} \) .
solution
Category talk.
If \ (n-\) is negative, the first to find a low-order bit is not from \ (9 \) position, to the position \ (1 + \) can. If all the bits are \ (9 \ ) , at the top make up \ (1 \) .
If \ (n-\) non-negative, to find a position to consider:
- This position may be \ (- 1 \) (i.e., the number of this position is not \ (0 \) ).
- The numbers to the right position and that position can be \ (+ 2 \) .
As long as you can find such a position, you can find a positive number to meet the meaning of the questions ...