Livestock Lineup//全排列//排位1

Livestock Lineup//全排列


题目

Every day, Farmer John milks his 8 dairy cows, named Bessie, Buttercup, Belinda, Beatrice, Bella, Blue, Betsy, and Sue. The cows are rather picky, unfortunately, and require that Farmer John milks them in an order that respects N constraints (1≤N≤7). Each constraint is of the form “X must be milked beside Y”, stipulating that cow X must appear in the milking order either directly after cow Y or directly before cow Y.

Please help Farmer John determine an ordering of his cows that satisfies all of these required constraints. It is guaranteed that an ordering is always possible. If several orderings work, then please output the one that is alphabetically first. That is, the first cow should have the alphabetically lowest name of all possible cows that could appear first in any valid ordering. Among all orderings starting with this same alphabetically-first cow, the second cow should be alphabetically lowest among all possible valid orderings, and so on.

Input
The first line of input contains N. The next N lines each contain a sentence describing a constraint in the form “X must be milked beside Y”, where X and Y are names of some of Farmer John’s cows (the eight possible names are listed above).

Output
Please output, using 8 lines, an ordering of cows, one cow per line, satisfying all constraints. If multiple orderings work, output the one that is alphabetically earliest.

Example

input
3
Buttercup must be milked beside Bella
Blue must be milked beside Bella
Sue must be milked beside Beatrice

output
Beatrice
Sue
Belinda
Bessie
Betsy
Blue
Bella
Buttercup
题意
某牛在某牛旁边,总共8头,求其排列
链接:http://codeforces.com/group/5yyKg9gx7m/contest/269717/problem/G

思路

数量少,暴力全排列,algorithm里有现成全排列,用就完事了

代码

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <deque>
#include <queue>
#include <cmath>
#include <stack>
#define pi 3.1415926
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

string cow[8];
string a[1000],b[1000],none;
int main()
{
    cow[0]="Beatrice";
    cow[1]="Belinda";
    cow[2]="Bella";
    cow[3]="Bessie";
    cow[4]="Betsy";
    cow[5]="Blue";
    cow[6]="Buttercup";
    cow[7]="Sue";
    int t1,t2;
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>none>>none>>none>>none>>b[i];
    }
    int judge=1;
    do{
        judge=1;
        for(int i=0;i<n;i++){
            int t1,t2;
            for(int j=0;j<8;j++){
                if(a[i]==cow[j]) t1=j;
                if(b[i]==cow[j]) t2=j;
            }
            if(abs(t1-t2)>1){
                judge=0;
                break;
            }
        }
        if(judge==1){
            for(int i=0;i<8;i++)
                cout<<cow[i]<<endl;
            return 0;
        }
    }while(next_permutation(cow,cow+8));


    return 0;
}

注意

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
引用\[1\]:在西欧,畜牧业数量和FCH4-ruminant的减少是由一系列政策引起的:(1)欧盟通过共同农业政策(CAP)向农民提供各种激励措施,将牧场上的畜牧密度限制在每公顷1.7个畜牧单位左右。\[1\] 引用\[2\]:在这项研究中,年FCH4-ruminant是基于IPCC第二层方法计算的。与使用畜牧数量数据和默认排放因子的IPCC第一层方法相比,第二层方法使用了更详细的国家特定数据,包括总能量摄入和特定畜牧类别的甲烷转化因子,允许考虑饲料数量和质量。\[2\] 引用\[3\]:球畜牧饲料数据,包括浓缩饲料、草料、秸秆和偶尔饲料,仅在2000年可用。根据我们的估计,2000年反刍动物消耗了总浓缩饲料的33%,比参考文献给出的值高11%。\[3\] 问题:畜牧密度是什么? 回答:畜牧密度是指单位面积上的畜牧动物数量。在西欧,通过共同农业政策的限制,畜牧密度被限制在每公顷1.7个畜牧单位左右。\[1\]畜牧密度的计算通常需要考虑畜牧数量和可用的土地面积。 #### 引用[.reference_title] - *1* *2* *3* [Revisiting enteric methane emissions from domestic ruminants and their δ](https://blog.csdn.net/weixin_39968724/article/details/117684714)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值