跳过正文
  1. Posts/

codeforces 330 B. Road Construction (图论基础)

·2 分钟

题目链接 题意:n个点,m(m<n/2)条不能走的边,问最少连多少条边,使得任何两个点之间的距离最多为2. 输出最少的边数和连接的哪些边。 思路: **数据范围很关键。**数据范围很关键。数据范围很关键。

因为m<n/2,每条禁止的边最多禁止两个点,所以禁止的点数<n..那么至少有一个点是和可以和其他所有点相连的。。于是把其他所有点和该点相连即可。

 1/* ***********************************************
 2Author :111qqz
 3Created Time :2016年03月19日 星期六 10时39分40秒
 4File Name :code/cf/problem/330B.cpp
 5************************************************ */
 6
 7#include <cstdio>
 8#include <cstring>
 9#include <iostream>
10#include <algorithm>
11#include <vector>
12#include <queue>
13#include <set>
14#include <map>
15#include <string>
16#include <cmath>
17#include <cstdlib>
18#include <ctime>
19#define fst first
20#define sec second
21#define lson l,m,rt<<1
22#define rson m+1,r,rt<<1|1
23#define ms(a,x) memset(a,x,sizeof(a))
24typedef long long LL;
25#define pi pair < int ,int >
26#define MP make_pair
27
28using namespace std;
29const double eps = 1E-8;
30const int dx4[4]={1,0,0,-1};
31const int dy4[4]={0,-1,1,0};
32const int inf = 0x3f3f3f3f;
33const int N=1E3+7;
34int cnt[N];
35int n,m;
36int main()
37{
38	#ifndef  ONLINE_JUDGE
39	freopen("code/in.txt","r",stdin);
40  #endif
41
42	ms(cnt,0);
43	cin>>n>>m;
44	for ( int i = 1 ; i <= m ; i++) //因为m<n/2...一条m限制两个点不能相连。。最多限制2*m<n个。。。
45	{				//所以至少有一个点不受任何限制。。把其他的所有点连到这个点上即可。
46	    int u,v;                    //此时得到一个 star graph.
47	    cin>>u>>v;
48	    cnt[v]++;
49	    cnt[u]++;
50	}
51
52	int p;
53	for ( int i = 1 ; i <= n ; i++)
54	{
55	    if (cnt[i] == 0)
56	    {
57		p = i ;
58		break;
59	    }
60	}
61
62	cout<<n-1<<endl;
63	for ( int i = 1; i <= n ; i++)
64	{
65	    if (i==p) continue;
66	    cout<<p<<" "<<i<<endl;
67	}
68
69
70
71
72  #ifndef ONLINE_JUDGE
73  fclose(stdin);
74  #endif
75    return 0;
76}

相关文章

codeforces croc 2016 C. Enduring Exodus

·1 分钟
题目链接 题意:给出n和k,给出一个长度为n的字符串表示房间的占用情况(0表示没占用,1表示已占用),从n个房间中找出k+1个,使得k+1中的k个距离k+1个中的1个的距离和最小。

codeforces croc 2016 B. Mischievous Mess Makers (贪心)

·1 分钟
题目链接 题意:长度为n的初始为1,2,3…n的序列,最多进行k次两个数交换,变换后的序列中最懂能有多少逆序对。 思路:贪心得想。。每次变最外层的对答案贡献最多。 以及,最能能变化n/2次。

codeforces croc2016 A. Amity Assessment (暴力)

·1 分钟
题目链接 题意:2×2的格子,有三个位置分别放”A“ “B” “C” ,一个位置为空。只有和空位相邻位置上的字母能移动到空位。没有其他移动规则。现在给出两个状态。问能否互相转化。 思路: 貌似可以dfs…?但是一共才2*2,可以直接暴力枚举。 手写一种变换最多能有12种。

hdu 4734 F(x) (数位dp)

·3 分钟
题目链接s 题意:将一个10进制数x按照2进制展开后得到的值设为f(x)…现在给出a,b(10^9)问【0,b】中满足f[x]<=f[a]的数的个数。 思路:先算出f[a]…然后我们发现f(x)最大也就10*2^10=10240.。。数组可以存下。。搞之。和上一道题类似。。我们不关心两个f函数的值具体是多少。。。只关心他们的相对大小情况。。所以还是可以合并成一个变量。。。然而我用两个变量为什么错了。。不懂==