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;
}

参考

目录
相关文章
|
25天前
BUUCTF---新年快乐(reverse)
BUUCTF---新年快乐(reverse)
(数学)(必要解题步骤)2021icpc上海D. Strange Fractions
(数学)(必要解题步骤)2021icpc上海D. Strange Fractions
48 0
(思维)(必要做题步骤)(皮卡丘与 Codeforces )D - 先来签个到
(思维)(必要做题步骤)(皮卡丘与 Codeforces )D - 先来签个到
78 0
【CCCC】L2-029 特立独行的幸福 (25分),模拟题,set用法
【CCCC】L2-029 特立独行的幸福 (25分),模拟题,set用法
142 0
CF979B Treasure Hunt(贪心 思维)
CF979B Treasure Hunt(贪心 思维)
74 0
CF979B Treasure Hunt(贪心 思维)
|
人工智能 BI
CF1398C. Good Subarrays(思维 前缀和)
CF1398C. Good Subarrays(思维 前缀和)
76 0
Codeforces1486 C2.Guessing the Greatest (hard version)(交互题+奇怪的二分)
Codeforces1486 C2.Guessing the Greatest (hard version)(交互题+奇怪的二分)
35 0
头歌php数组答案
头歌php数组答案
152 0
|
机器学习/深度学习 人工智能 算法
每日一题冲刺大厂第十六天提高组 codeforces 783 div1 Half Queen
大家好,我是泡泡,给大家带来每日一题的目的是为了更好的练习算法,我们的每日一题提高组是为了有余力的同学准备的,让大家练到各种各样的题目,一年以后,蜕变成为一个不一样的自己!
93 0
每日一题冲刺大厂第十六天提高组 codeforces 783 div1 Half Queen

热门文章

最新文章