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;
}
目录
相关文章
|
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
116 0
2021中石油组队训练第八场记录(下)
|
机器学习/深度学习 程序员
lduoj_2021年初寒假训练第41场(上)
2021年初寒假训练第41场 A. 复制-粘贴 B. 足球联赛 C. 捕食关系 D. 幻方 E. 求和 F. 猜歌名
172 0
|
程序员
lduoj_2021年初寒假训练第42场(下)
目录 2021年初寒假训练第41场 A. 复制-粘贴 B. 足球联赛 C. 捕食关系 D. 幻方 E. 求和 F. 猜歌名
201 0
lduoj_2021年初寒假训练第42场(下)
|
人工智能 算法 BI
第320场周赛赛后分析总结(前三题)
前言 几个星期没打周赛,手感生疏了好多,果然算法题还是得勤加练习,多找适应比赛的感觉。 同时,第二、三题都是图和树相关的内容,像我这种对这个专题还不熟的也可以借此机会巩固一下。
104 0
|
自动驾驶
摩根斯坦利再次出手估价:特斯拉自动驾驶打车网络值 177 亿美元
Autopilot 还不能自动驾驶呢,哪来的打车网络?
450 0
|
双11
阿里数据:全国近3000万爸妈爱“剁手”,80后、90后的爸妈战斗力地表最强
“父母会淘宝是一种怎样的体验?”“他们的购物车是你没见过的世面。”前不久,“父母淘宝”的话题成为知乎热帖,上述评论引发了不少网友的共鸣。 实际上,爸妈早已不是我们想象中的中老年模样,他们和年轻人一样,正在通过智能手机积极拥抱移动互联网的新生活。
2362 0
德法提议设5000亿欧元恢复基金,资助受重创成员国走出疫情
5月18日,法国和德国提议设立一个5000亿欧元(5420亿美元)的基金,以推动欧盟经济从疫情破坏中恢复。
|
6月前
|
算法 安全 量子技术
【2023 年第十三届 MathorCup 高校数学建模挑战赛】 B 题 城市轨道交通列车时刻表优化问题 42页论文及代码
本文介绍了2023年第十三届MathorCup高校数学建模挑战赛B题的研究成果,提供了城市轨道交通列车时刻表优化问题的详细建模方案、C++代码实现以及42页的完整论文,旨在通过贪心算法、二分搜索法和多目标规划等方法最小化企业运营成本并最大化服务水平。
119 0
【2023 年第十三届 MathorCup 高校数学建模挑战赛】 B 题 城市轨道交通列车时刻表优化问题 42页论文及代码

热门文章

最新文章