2020中石油组队训练第八场记录(上)

简介: 问题 D: Eeny Meeny时间限制: 2 Sec 内存限制: 128 MB题目描述“Eeny meeny miny moe” is a well-known nursery rhyme in English, used (among other things) by kids to “randomly” select members of a team. It exists in many variations, one of which goes like this:Eeny, meeny, miny, moe,Catch a tiger by the toe.

问题 D: Eeny Meeny

时间限制: 2 Sec 内存 限制: 128 MB


题目描述


“Eeny meeny miny moe” is a well-known nursery rhyme in English, used (among other things) by kids to “randomly” select members of a team. It exists in many variations, one of which goes like this:

Eeny, meeny, miny, moe,

Catch a tiger by the toe.

If he hollers, let him go,

Eeny, meeny, miny, moe.

Similar verses exist in most languages, such as “Ulle dulle dof” in finnish, “Akka bakka bonka rakka” in Norwegian, and “Ole dole doff” in Swedish.

Two teams are to be selected for a game and the rhyme is used to select one kid for a team at a time, alternating between the two teams, until all kids have been selected. The kids are standing in a circle. In each selection round we start counting the kids in clockwise order around the circle, skipping one kid for every word in the rhyme, until the last word. The kid matching the last word is chosen for the current team and then the next round starts. In all rounds but the first, the counting starts at the next remaining kid (in clockwise order) after the one that was selected in the previous round. See figure E.1 for an example.

Given such a rhyme, and a group of kids, can you tell which kids will be in which team?

微信图片_20220531161500.png


figure E.1: Illustration of the first three rounds of Sample Input 1. In rounds 1 and 3, Alvar and Rakel get selected for the first team, and in round 2, Lisa is selected for the second team. In round 4 (not shown), only Kalle remains and is selected for the second team.


输入


The first line of input contains the rhyme, consisting of a list of words separated by spaces. The second line of input contains an integer n (1 ≤ n ≤ 100), the number of kids. Then follow the names of the kids, one per line. The kids are given in clockwise order and the first kid listed is the one at which counting starts in the first round.

All words and names consist only of upper and lower case letters ‘ A ’-‘ Z ’ and ‘ a ’-‘ z ’. No input line is empty or longer than 100 characters (excluding the newline character at the end of the line).


输出


Output the two teams, starting with the one whose first member is chosen first. For each team, output the number of kids in the team, followed by the names of the kids in the team, in the same order as they were chosen for the team.


样例输入 Copy


eeny meeny miny
4
Kalle
Lisa
Alvar
Rakel


样例输出 Copy


2
Alvar
Rakel
2
Lisa
Kalle


题目大意


约瑟夫环经典问题

微信图片_20220531161635.png

大意可以理解为:有n个人,开始的时候,第一个人开始数数,数到m,就加入一组队伍,如果是第奇数个加入队伍的,就进入一号队伍,否则就是二号队伍

一直重复这种情况,直到所有人都加入队伍

最后问每个队伍有多少人,分别有谁

经典的约瑟夫环

Main_code:

int n;
string in;
struct node {
  string name;
  int val;
  int t;
};
bool cmp(node a, node b) {
  if (a.val != b.val) return a.val < b.val;
  else return a.t < b.t;
}
node b[maxn];
string a[maxn];
int main()
{
  getline(cin, in);
  in += '#';
  int num = 0;
  int len = in.size();
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> b[i].name;
  string temp;
  for (int i = 0; i < len; i++) {
    temp += in[i];
    if (in[i + 1] == ' ' || in[i + 1] == '#') {
      a[++num] = temp;
      temp.clear();
      i++;
    }
  }
  int cnt1 = 0, cnt2 = 0;
  int over = 0;
  do {
    ++cnt1;
    if (cnt1 > n) cnt1 = 1;
    if (b[cnt1].val == 0) {
      cnt2++;
    }
    if (cnt2 == num) {
      cnt2 = 0;
      over++;
      if (over % 2) b[cnt1].val = 1;
      else b[cnt1].val = 2;
      b[cnt1].t = over;
    }
  } while (over != n);
  sort(b + 1, b + 1 + n, cmp);
  cnt1 = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i].val == 1) cnt1 ++;
    else break;
  }
  cout << cnt1 << endl;
  for (int i = 1; i <= cnt1; i++) {
    cout << b[i].name << endl;
  }
  cout << n - cnt1 << endl;
  for (int i = cnt1 + 1; i <= n; i++) {
    cout << b[i].name << endl;
  }
  return 0;
}

Alphabet Animals

时间限制: 1 Sec 内存限制: 128 MB


题目描述


You are playing a game in which a group of players take turns saying animal names. The animal name you say when it is your turn must start with the same letter as the previously said animal ends with and it must not have been said previously in this round of the game. If there is no valid name or you cannot come up with one you are eliminated.

Given the last animal name said before your turn and a list of all names not yet used, can you make it through this turn? If so, can you make sure to eliminate the next player?


输入


The first line of input contains a single word, the animal that the previous player just said. The next line contains a single integer n (0 ≤ n ≤ 105 ), the number of valid unused animal names.

Each of the following n lines contains one valid unused animal name.

All animal names (including the one the previous player said) are unique and consist of at least 1 and at most 20 lower case letters ‘ a ’-‘ z ’.


输出


If there is any animal name you can play that eliminates the next player, output the first such name from the input list, followed by an exclamation mark.

Otherwise, if there is any animal name that you can play, output the first such name. Otherwise, output a question mark (in this case you will just have to make up a fake name in the hope that the others will trust you that this is a real animal).


样例输入 Copy


pig
2
goat
toad


样例输出 Copy


goat


题目分析:

这个题并不难,但是容易被题意卡的死死的

如果能够选出把后面的人卡死的情况下,就输出最优的情况**并且在后面加上一个叹号,否则就输出第一个自己匹配的情况,要是找不到以上两种情况,就输出一个问号**

Main_code:

  string s;
    cin>>s;
    int lens=s.size();
    char ttt = s[lens-1];
    int n=read;
    string ans;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mp[a[i][0]] ++;
    }
    int flag=0;
    for(int i=1;i<=n;i++){
        char l=a[i][0];
        int lena=a[i].size();
        char r=a[i][lena-1];
        if((ttt == l && !mp[r])||(ttt==l&&l==r)&&mp[r]==1){
            flag=1;
            ans=a[i];
            break;
        }
    }
    if(flag) cout<<ans<<'!'<<endl;
    else{
        for(int i=1;i<=n;i++){
            char l=a[i][0];
            int lena=a[i].size();
            char r=a[i][lena-1];
            if(ttt == l){
                flag = 1;
                ans=a[i];
                break;
            }
        }
        if(flag) cout<<ans<<endl;
        else cout<<'?'<<endl;
    }
    return 0;


问题 B: Building Boundaries

时间限制: 1 Sec 内存限制: 128 MB


题目描述


Maarja wants to buy a rectangular piece of land and then construct three buildings on that land.

The boundaries of the buildings on the ground must have rectangular sizes a1 × b1 , a2 × b2 ,and a3 × b3 . They can touch each other but they may not overlap. They can also be rotated as long as their sides are horizontal and vertical.

What is the minimum area of land Maarja has to buy?

微信图片_20220531162101.png

Figure B.1: Illustration of the two test scenarios in Sample Input 1 and their solutions. In the second scenario the 5 × 1 building has been rotated by 90 degrees.


输入


The input consists of multiple test scenarios. The first line of input contains a single integer t(1 ≤ t ≤ 1000), the number of scenarios. Then follow the t scenarios. Each scenario consists of a single line, containing six integers a1 , b1 , a2 , b2 , a3 and b3 (1 ≤ a1 , b1 , a2 , b2 , a3 , b3 ≤ 109 ).


输出


For each test scenario, output the minimum area of land such that Maarja can construct the three buildings.


样例输入 Copy


2
2 3 2 2 1 1
2 4 5 1 2 3


样例输出 Copy


12
21


题意很简单,给出三个矩形的长和宽,然后找出面积最小的矩形放下这三个矩形,问符合这个条件的矩形的面积是多少

这种问题直接交给队友

队友用的二进制枚举

Main_code:

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
struct node {
    ll h, w;
}q[6];
ll mi;
ll get1(node* q) {
    //三个一行
    ll w = 0, h = 0;
    for (int i = 1; i <= 3; i++) {
        w += q[i].w;
        h = max(h, q[i].h);
    }
    return w * h;
}
ll get2(node* q) {
    //两个一列
    ll w = 0, h = 0;
    for (int i = 1; i <= 2; i++) {
        w = max(w, q[i].w);
        h += q[i].h;
    }
    w += q[3].w, h = max(h, q[3].h);
    return w * h;
}
ll get3(node* q) {
    //两个一列
    ll w = 0, h = 0;
    for (int i = 2; i <= 3; i++) {
        w = max(w, q[i].w);
        h += q[i].h;
    }
    w += q[1].w, h = max(h, q[1].h);
    return w * h;
}
ll get4(node* q) {
    //两个一列
    ll w = 0, h = 0;
    for (int i = 1; i <= 3; i++) {
        if (i == 2) continue;
        w = max(w, q[i].w);
        h += q[i].h;
    }
    w += q[2].w, h = max(h, q[2].h);
    return w * h;
}
void dfs() {
    for (ll i = 0; i <= 7; i++) {
        ll n = i; node tt[6];
        for (ll k = 1; k <= 3; k++) {
            tt[k] = q[k];
        }
        for (ll j = 2; j >= 0; j--) {
            ll t = (n >> j);
            if (t & 1) swap(tt[j + 1].h, tt[j + 1].w);
        }
        mi = min(mi, get1(tt));
        mi = min(mi, get2(tt));
        mi = min(mi, get3(tt));
        mi = min(mi, get4(tt));
    }
    return;
}
int main() {
    int T; cin >> T;
    while (T--) {
        for (ll i = 1; i <= 3; i++) {
            cin >> q[i].w >> q[i].h;
        }
        mi = 4e18;
        dfs();
        cout << mi << endl;
    }
    return 0;
}
目录
相关文章
|
3月前
|
机器学习/深度学习 数据采集 算法
【 2021 MathorCup杯大数据挑战赛 A题 二手车估价】初赛复赛总结、方案代码及论文
总结了2021 MathorCup杯大数据挑战赛A题“二手车估价”的初赛和复赛经验,包括题目要求、解题思路、所用方法和结果,提供了详细的数据分析、模型构建、论文撰写和工具使用技巧,并展示了初赛和复赛的论文。
66 2
|
3月前
【2023 华数杯全国大学生数学建模竞赛】 A题 隔热材料的结构优化控制研究 问题分析及完整论文
本文提供了2023年华数杯全国大学生数学建模竞赛A题的完整论文,深入分析了隔热材料的结构优化控制研究,包括建立数学模型、求解单根纤维的热导率、优化织物结构参数以及考虑对流换热影响的模型调整,旨在开发出具有更优隔热性能的新型织物。
77 0
【2023 华数杯全国大学生数学建模竞赛】 A题 隔热材料的结构优化控制研究 问题分析及完整论文
|
3月前
|
人工智能 算法 安全
【2023 年第十三届 MathorCup 高校数学建模挑战赛】C 题 电商物流网络包裹应急调运与结构优化问题 赛后总结之31页论文及代码
本文总结了2023年第十三届MathorCup高校数学建模挑战赛C题的解题过程,详细阐述了电商物流网络在面临突发事件时的包裹应急调运与结构优化问题,提出了基于时间序列预测、多目标优化、遗传算法和重要性评价模型的综合解决方案,并提供了相应的31页论文和代码实现。
77 0
|
6月前
|
算法 数据可视化 数据挖掘
JCR一区10.9分|单细胞:有一手数据的肿瘤课题组怎么冲高分文章
这篇文章介绍了在《肿瘤免疫疗法》杂志上发表的一项研究,该研究利用单细胞RNA测序技术揭示了肝细胞癌(HCC)中FABP1(脂肪酸结合蛋白1)依赖的免疫抑制环境。研究分析了II期和III期HCC患者样本的免疫细胞,发现FABP1在III期HCC的肿瘤相关巨噬细胞(TAMs)中过度表达,并与免疫抑制有关。FABP1与PPARG(过氧化物酶体增殖物激活受体伽玛)相互作用,促进了HCC中的脂肪酸氧化,进而影响免疫应答。
96 0
|
机器学习/深度学习 算法 数据可视化
“华为杯”第十八届中国研究生数学建模竞赛D题:抗乳腺癌候选药物的优化建模(一等奖)
“华为杯”第十八届中国研究生数学建模竞赛D题:抗乳腺癌候选药物的优化建模(一等奖)
213 0
|
机器学习/深度学习 算法 数据可视化
精准高效估计多人3D姿态,美图&北航分布感知式单阶段模型入选CVPR 2022
精准高效估计多人3D姿态,美图&北航分布感知式单阶段模型入选CVPR 2022
136 0
|
安全 数据挖掘 定位技术
2022年中国研究生数学建模竞赛F题 COVID-19疫情期间生活物资的科学管理问题思路分析
2022年中国研究生数学建模竞赛F题 COVID-19疫情期间生活物资的科学管理问题
6122 5
2021年度训练联盟热身训练赛第三场——C,G,I
2021年度训练联盟热身训练赛第三场——C,G,I
92 0
2021年度训练联盟热身训练赛第一场——Weird Flecks, But OK(最小圆覆盖)
2021年度训练联盟热身训练赛第一场——Weird Flecks, But OK(最小圆覆盖)
97 0
|
Go 网络架构 iOS开发
2021中石油组队训练第八场记录(下)
题目描述 Alice and Bob decide to share a chocolate bar, which is an n by m rectangular grid of chocolate cells. They decide that Alice should get a < n·m pieces and that Bob should get b = n·m − a pieces. To split the chocolate bar, they repeatedly take a single piece of chocolate and break it either
104 0
2021中石油组队训练第八场记录(下)
下一篇
无影云桌面