Title Description
A group of aliens will attack Mars.
The map of Mars is an n-point graph without a direction. The aliens will invade as follows, with an attack level of 0 (equivalent to removing it), then a 1 point, and so on, until the n-1 point.
All the point statistics are dynamic statistics. (When a point is deleted, the point of the point connected to it will be-1). An alien attack is an attack at the same time as a certain number of points.
You need to design the side of the diagram to make the most of the points that are not being attacked.
Input/output format
Input Format:
The input file contains one line of integer n.
output Format:
An integer line that represents the most last point that was not attacked.
Input/Output sample
Input Sample # #:
3
Sample # # of output:
1
Description
"Sample Interpretation"
①-②-③, so first delete the degree of 1 ① and ③, at this time ② degrees of 0, will not be deleted.
"Data Range"
For 20% of data 1<=n<=10
For 100% of data 1<=n<=50000
"Source of the topic"
Tinylic adaptation
by Tinylic
After finding the law, we can find the answer is n-2.
Here is the proof:
Order D[i] is the degree of I.
Consider the condition that a point I is not deleted, necessarily the point J (which can be multiple) adjacent to the front and I, which is deleted, leading to D[i]
Decrease to less than or equal to d[j].
1) Easy to know ans!=n.
2) Consider whether ans can be n-1, that is, to delete only one point, set this point for I.
Because I is the only point deleted, so d[i] must not be the largest, that is, d[i]<n-1.
The second deletion of I causes the rest of the d[] to change and thus cannot be deleted.
That I and the rest of the points are connected, d[i]=n-1, contradiction.
So ans!=n-1.
3) We can construct the situation of ans=n-2:
Construct complete graph G and delete an edge (I,J). This d[i]=d[j]=n-2, the rest of the d[] are n-1.
First delete the VI,VJ, so that the remaining points are less than two sides, d[] all become n-3, do not have to be deleted.
This n-2 is a legal solution and the largest solution, so the answer is n-2.
1 /*by Silvern*/2#include <iostream>3#include <cstdio>4 using namespacestd;5 intMain () {6 intN;7scanf"%d",&n);8printf"%d\n", Max (0, N-2));9 return 0;Ten}
Rokua P1755 attack on Mars