Gym 100962G Green Day (找规律)

题意:你用k 个生成树构成一个完全图。

析:n 个点的完全图有n(n-1)/2个边,一个生成树有n-1个边,你有k 个生成树 即边数等于 K(n-1) ,即  n(n-1)/2 == k(n-1)   n = 2*k

所以2k 个边足够,你会发现在每个结点只能做一次开头或者结尾。然后找找规律就好。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#define print(a) printf("%d\n", (a))
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const LL LNF = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1e2 + 5;
const int mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int Min(int a, int b){ return a < b ? a : b; }
inline int Max(int a, int b){ return a > b ? a : b; }
inline LL Min(LL a, LL b){ return a < b ? a : b; }
inline LL Max(LL a, LL b){ return a > b ? a : b; }
inline bool is_in(int r, int c){
    return r >= 0 && r < n && c >= 0 && c < m;
}

int main(){
    while(scanf("%d", &n) == 1){
        m = n << 1;
        printf("%d\n", m);
        for (int i = 1; i <= n; ++i){
            for (int j = i+1; j <= i + n; ++j) printf("%d %d\n",i, j);
            for (int j = 1; j <= m-n-1; ++j) printf("%d %d\n",i+n, (i+n+j) % m == 0 ? m : (i+n+j)%m);
        }
    }
    return 0;
}
时间: 2024-08-07 01:17:58

Gym 100962G Green Day (找规律)的相关文章

Codeforces Gym 100637B B. Lunch 找规律

B. Lunch Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/B Description The swamp looks like a narrow lane with length n covered by floating leaves sized 1, numbered from 1 to n with a fly sitting on the top of ea

Codeforces Gym 100114 A. Hanoi tower 找规律

A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Description you the conditions of this task. There are 3 pivots: A, B, C. Initially, n disks of different diameter are placed on the pivot A: the smallest dis

The Cow Lineup_找规律

Description Farmer John's N cows (1 <= N <= 100,000) are lined up in a row.Each cow is labeled with a number in the range 1...K (1 <= K <=10,000) identifying her breed. For example, a line of 14 cows might have these breeds: 1 5 3 2 5 1 3 4 4

UVA - 1646 - Edge Case(找规律)

题意:n(3 <= n <= 10000)个结点组成一个圈,求匹配(即没有公共点的边集)的个数. 找规律为斐波那契的性质,因为数太大所以用的java大数. import java.math.BigInteger; import java.util.Scanner; public class Main{ public static int MAXN = 10000 + 10; public static BigInteger []c = new BigInteger[MAXN]; public

【55测试】【字符串】【栈】【找规律】

集训第二天,额,考崩了. 第一题 hao 大意:(这个名字就不要在意了,其实是祖玛游戏) 模拟祖玛游戏的模式,给一个'A'~'Z'的字符串,然后有t个插入操作为 “ 添加后的在原字符串的位置 x  插入元素 c ”,字符串中有超过或等于 3 个相同的字符,则被消除,输出每次操作后剩余的字符串,如果为空,则输出“-”. 样例: ACCBA                     输出:  ABCCBA 5   AABCCBA 1 B AABBCCBA 0 A - 2 B A 4 C 0 A 解:

2016(胡赛复现)_大数找规律

Time Limit: 5 Sec  Memory Limit: 128 MB Description 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m;  2. a×b 是 2016 的倍数. Input 输入包含不超过 30 组数据. 每组数据包含两个整数 n,m (1≤n,m≤109). Output 对于每组数据,输出一个整数表示满足条件的数量. Sample Input 32 63 2016 2016 1000000000 1000

HDU 5703 Desert 水题 找规律

已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这题输出二进制数就行了......那就更简单了,直接输出1,然后后面跟n-1个0就行了╮(╯_╰)╭ 下面AC代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>

找规律/hdu 1005 Number Sequence

题意 给出a,b,n,已知f[1]=f[2]=1,f[i]=(a*f[i-1]+b*f[i-2]) mod 7 输出f[n] 数据范围 1 <= A, B <= 1000, 1 <= n <= 100,000,000 分析 首先,直接求..肯定是不行的 会tle 会mle 但是可以找到规律,例如对a=1,b=1 这个数据,有 f1=1 f2=1 f3=3 f4=5 f5=4 f6=0 f7=1 f8=1 f9=3 f10=5 f11=4 f12=0 ???? 我们会发现有一定的规律

hdu 2147 kiki&#39;s game(DP(SG)打表找规律)

题意: n*m的棋盘,一枚硬币右上角,每人每次可将硬币移向三个方向之一(一格单位):左边,下边,左下边. 无法移动硬币的人负. 给出n和m,问,先手胜还是后手胜. 数据范围: n, m (0<n,m<=2000) 思路: dp[i][j]=0,说明从(i,j)这个点到时左下角先手败.dp[i][j]=1则先手胜. 然后记忆搜.但是记忆搜会超时. 搜完把整张表打出来,发现规律了,,,,然后,,,代码剩几行了. 代码: ///打表观察 /* int f[2005][2005]; int go(in