Sunday has been particularly interested in graph theory recently, what Euler circuit, what Hamiltonian circuit, is a ring and a tree. After reading a book, he was very confident in himself, so he found a big bull, hoping that he would come up with a question to test himself.
There are N cities in the far ancient east, which can be connected by two-way roads. Any two cities are directly connected by no more than one road, and no city's road leads to itself. But Niu Benben is a pure-hearted young man. Although he doesn't have a girlfriend yet, he still hates third parties so much that he hates the number three. So he hopes that Sunday can construct a map of N cities. In this map, no three cities can directly reach each other, and the number of roads in the map is the largest.
Considering that Sunday is a rookie, Niu Benben only asked him to answer the number of roads contained in the above map, without the need to output which roads the map consists of. (Off-topic: In fact, it's just because the special judge's evaluation process is more troublesome)
The first line contains an integer T (1 <= T <= 100), which represents the number of groups of test data.
Each set of data contains only one N (1 <= N <= 1000), representing N cities.
There is only one row for each set of data output, indicating the maximum number of roads that can be connected to N cities under the meaning of the question.
2 3 4Sample Output
2 4
The meaning of the question: Now there are n points, some lines can be connected between these n points, and there can only be one line between two points. Now the connection requirements are: choose three points at will, and these three points cannot be two Two connected. 1 is connected to 2, 2 is connected to 3, then 1 cannot be connected to 3. Any three points have this limitation. How many connections can these n points have at most?
Idea: In order to avoid a ring of three points, there is a requirement that the newly appeared point cannot connect the two points that have been connected at the same time. And 1 is connected to 2, then the new 3 cannot be connected to 1 and 2 at the same time; the main idea is this one, which can solve the problem.
At 1 o'clock: 1
When there are 2 points: 1,2 (1-2)//I use this to represent the connection relationship
At 3 points: 1,2,3 (1-2) (2-3)
At 4 points: 1,2,3,4 (1-2) (2-3) (1-4)(3-4)
At 5 points: 1,2,3,4,5 (1-2) (2-3) (1-4)(3-4) (2-5)(4-5)
At 6 points: 1,2,3,4,5,6 (1-2) (2-3) (1-4)(3-4) (2-5)(4-5) (1- 6)(3-6)(5-6)
At 7 points: 1,2,3,4,5,6,7 (1-2) (2-3) (1-4)(3-4) (2-5)(4-5) ( 1-6)(3-6)(5-6) (2-7)(4-7)(6-7)
You will find that the newly appeared point n is connected to n-1 first, because the two adjacent points are already connected, so connect one every other (this can ensure the most connections)
#include <iostream> #include <stdio.h> #include<algorithm> #include<string.h> using namespace std; int years[1500]; intmain() { ans[0]=0; for(int i=1;i<=1000;i++) years[i]=years[i-1]+i/2; int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); printf("%d\n",ans[n]); } }