codeforces1210——A.Anadi and Domino(思维+枚举)

简介: codeforces1210——A.Anadi and Domino(思维+枚举)

原题链接

思路:

我们可以给每个点都标号,然后和每个点相连的边上放的骨牌的标号和点的标号相同。这样可以看出当n<=6时,每个边都可以放骨牌,并且不会冲突。当n==7时,就意味着有两个点的标号一样,这样就会有一些边上没有骨牌,只需要记录一下就好了。

有·思维。

代码:

#pragma GCC optimize(3)
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>PLL;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
#define I_int ll
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
char F[200];
inline void out(I_int x) {
    if (x == 0) return (void) (putchar('0'));
    I_int tmp = x > 0 ? x : -x;
    if (x < 0) putchar('-');
    int cnt = 0;
    while (tmp > 0) {
        F[cnt++] = tmp % 10 + '0';
        tmp /= 10;
    }
    while (cnt > 0) putchar(F[--cnt]);
    //cout<<" ";
}
ll ksm(ll a,ll b,ll p){ll res=1;while(b){if(b&1)res=res*a%p;a=a*a%p;b>>=1;}return res;}
const ll inf = 0x3f3f3f3f3f3f3f3f;
const int maxn=1e6+100,N=1e6+100;
const double PI = atan(1.0)*4;
const double eps=1e-6;
int mp[15][15];
int main(){
    int n=read(),m=read();
    for(int i=1;i<=m;i++){
        int u=read(),v=read();
        mp[u][v]=mp[v][u]=1;
    }
    if(n<=6) out(m);
    else{
        int cnt=inf;
        for(int i=1;i<=7;i++)
            for(int j=1;j<=7;j++){
                ///i和j填充相同的数字
                int tmp=0;
                for(int k=1;k<=7;k++)
                    if(mp[i][k]&&mp[j][k]) tmp++;///不能添加的边
                cnt=min(cnt,tmp);
            }
        out(m-cnt);
    }
    return 0;
}

参考

目录
相关文章
|
C语言 C++
PAT (Basic Level) Practice (中文)1099 性感素数(20分)
“性感素数”是指形如 (p, p+6) 这样的一对素数。之所以叫这个名字,是因为拉丁语管“六”叫“sex”(即英语的“性感”)。(原文摘自 http://mathworld.wolfram.com/SexyPrimes.html) 现给定一个整数,请你判断其是否为一个性感素数。
107 0
ZZULIOJ-1091: 童年生活二三事(多实例测试)(Java)
ZZULIOJ-1091: 童年生活二三事(多实例测试)(Java)
(数学)(必要解题步骤)2021icpc上海D. Strange Fractions
(数学)(必要解题步骤)2021icpc上海D. Strange Fractions
51 0
CF979B Treasure Hunt(贪心 思维)
CF979B Treasure Hunt(贪心 思维)
75 0
CF979B Treasure Hunt(贪心 思维)
|
机器学习/深度学习 人工智能 算法
每日一题冲刺大厂第十六天提高组 codeforces 783 div1 Half Queen
大家好,我是泡泡,给大家带来每日一题的目的是为了更好的练习算法,我们的每日一题提高组是为了有余力的同学准备的,让大家练到各种各样的题目,一年以后,蜕变成为一个不一样的自己!
93 0
每日一题冲刺大厂第十六天提高组 codeforces 783 div1 Half Queen
|
BI
2022年牛客多校第2场 J . Link with Arithmetic Progression (三分+枚举)
2022年牛客多校第2场 J . Link with Arithmetic Progression (三分+枚举)
97 0
|
存储 安全 程序员
Libra教程之:move语言的特点和例子
Libra教程之:move语言的特点和例子
Libra教程之:move语言的特点和例子
|
人工智能 算法
每天一道 CodeForces 构造/思维题 (day1)
每天一道 CodeForces 构造/思维题 (day1)