• 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.
    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?
    在这里插入图片描述

    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
    

    题目大意
    约瑟夫环经典问题
    在这里插入图片描述

    大意可以理解为:有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?
    在这里插入图片描述

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

    问题 C: Cocoa Coalition
    时间限制: 1 Sec 内存限制: 128 MB

    题目描述
    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 horizontally or vertically, creating two smaller pieces of chocolate. See Figure C.1 for an
    example.
    What is the minimum number of splits that Alice and Bob need to perform in order to split the n-by-m chocolate bar into two piles consisting of a and b chocolate cells?
    在这里插入图片描述

    Figure C.1: Illustration of a solution to Sample Input 2, showing the original 10-by-10 chocolate bar split three times into pieces of size 10-by-2, 10-by-5, 3-by-3 and 7-by-3. Giving Alice the 10-by-5 and 7-by-3 pieces, she gets a total of 50 + 21 = 71 chocolate cells.
    输入
    The input consists of a single line, containing the three integers n, m and a (1 ≤ n, m ≤ 106 ,1 ≤ a < n · m).
    输出
    Output the minimum number of splits needed to achieve the desired division of chocolate.
    样例输入 Copy

    3 10 9
    

    样例输出 Copy

    1
    

    题目大意:
    给出一个矩形的巧克力方块,每个小方块是1*1的,每次可以横着或者是竖着切一刀,问切出面积总共为 a 的一块最少需要操作几次

    有一种比较sao的情况是:
    5 * 15 的方块,切出大小为31的一块,最少是两刀,不是三刀:
    第一次切出45的一块来,然后右面剩下的事511的一块,然后正好还差 11小块,此时切一刀解决问题
    Main_code:

    	ll n, m, a; cin >> n >> m >> a;
        ll _a = a;
        if (2 * a > n * m) a = n * m - a;
        if (n > m) swap(n, m);
        if (a % n == 0 || a % m == 0) {
            cout << 1 << endl;
            return 0;
        }
        if (a >= 1 && a < m) {
            cout << 2 << endl;
            return 0;
        }
        for (ll i = 2; i * i <= _a; i++) {
            if (_a % i == 0) {
                ll j = _a / i;
                if (i <= n && j <= m) {
                    cout << 2 << endl;
                    return 0;
                }
            }
        }
     
        for (ll t = 1; t <= m; t++) {
            ll u = n * t, v = _a - u;
            ll mi = m - t, mx = n;
            if (mi > 0 && v > 0) {
                if (v % mi == 0 || v % mx == 0) {
                    cout << 2 << endl;
                    return 0;
                }
            }
            else break;
        }
     
        for (ll t = 1; t <= n; t++) {
            ll u = m * t, v = _a - u;
            ll mi = n - t, mx = m;
            if (mi > 0 && v > 0) {
                if (v % mi == 0 || v % mx == 0) {
                    cout << 2 << endl;
                    return 0;
                }
            }
            else break;
        }
     
        cout << 3 << endl;
        return 0;
    

    问题 G: Hot Hike
    时间限制: 1 Sec 内存限制: 128 MB

    题目描述
    In order to pass time during your vacation, you decided to go on a hike to visit a scenic lake up in the mountains. Hiking to the lake will take you a full day, then you will stay there for a day to rest and enjoy the scenery, and then spend another day hiking home, for a total of three days. However, the accursed weather this summer is ridiculously warm and sunny, and since severe dehydration is not at the top of your priority list you want to schedule the three-day trip during some days where the two hiking days are the least warm. In particular you want to minimize the maximum temperature during the two hiking days.
    Given the current forecast of daily maximum temperatures during your vacation, what are the best days for your trip?
    输入
    The first line of input contains an integer n (3 ≤ n ≤ 50), the length of your vacation in days. Then follows a line containing n integers t1 , t2 , . . . , tn (−20 ≤ t i ≤ 40), where ti is the temperature forecast for the i’th day of your vacation.
    输出
    Output two integers d and t, where d is the best day to start your trip, and t is the resulting maximum temperature during the two hiking days. If there are many choices of d that minimize the value of t, then output the smallest such d.
    样例输入 Copy

    5
    23 27 31 28 30
    

    样例输出 Copy

    2 28
    

    不再赘述

    int minn=inf,tag=-1;
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<n-1;i++)
        {
            if(minn>max(a[i],a[i+2]))
            {
                tag=i;
                minn=max(a[i],a[i+2]);
            }
        }
        cout<<tag<<" "<<minn<<endl;
    

    问题 F: Game of Gnomes
    时间限制: 1 Sec 内存限制: 128 MB

    题目描述
    The enemy and their massive army is approaching your fortress, and all you have to defend it is a legion of guardian gnomes. There is no hope of winning the battle, so your focus will instead be on causing as much damage as possible to the enemy.
    You have n gnomes at your disposal. Before the battle, they must be divided into at most m non-empty groups. The battle will then proceed in turns. Each turn, your gnomes will attack the enemy, causing one unit of damage for each living gnome. Then the enemy will attack by throwing a lightning bolt at one of the m groups. The lightning bolt kills k of the gnomes in that group, or all of them if the number of living gnomes in the group is less than k. The battle ends when all gnomes are dead. The enemy will always throw the lightning bolts in an optimal way such that the total damage caused by the gnomes is minimized.
    Now you wonder, what is the maximum amount of damage you can cause to the enemy if you divide the gnomes into groups in an optimal way?
    For example, if as in Sample Input 1 you have n = 10 gnomes that are to be divided into m = 4 groups, and the lightning bolt does at most k = 3 damage, then an optimal solution would be to create one large group of size 7 and three small groups of size 1. In the first round, you cause 10 damage and the lightning bolt reduces the large group by 3. In the next round, you cause 7 damage and the large group is reduced down to size 1. In the remaining four rounds you do 4, 3, 2, and 1 damage respectively and the lightning bolt removes one group each round. In total you do 10 + 7 + 4 + 3 + 2 + 1 = 27 damage.
    输入
    The input consists of a single line containing the three integers n, m, and k (1 ≤ n ≤ 109 ,1 ≤ m, k ≤ 107 ), with meanings as described above.
    输出
    Output the maximum amount of damage you can cause to the enemy.
    样例输入 Copy

    10 4 3
    

    样例输出 Copy

    27
    

    这是一道比较不错的涉及数学的贪心构造思维题;
    学长的博客讲解很详细

    	ll n, m, k;
    	cin >> n >> m >> k;
    	ll i = (n / k - m) - 10;
    	if (i < 0) i = 0;
    	for (; i <= n / k; i++) {
    		if (n - i * k >= m * k) continue;
    		ll t1 = n - (i - 1) * k;
    		ll max1 = (n + t1) * i / 2;
    
    		ll rem = n - i * k;/// 剩余的
    		ll tot = rem / m;/// 
    		ll modd = rem % m;
    
    		ll temp1 = (rem + (m - modd) * tot + tot + 1) * modd / 2;
    		ll temp2 = (tot + (m - modd) * tot) * (m - modd) / 2;
    		ll ans = max1 + temp1 + temp2;
    		res = max(res, ans);
    	}
    	cout << res << endl;
    

    更新中。。。。。。

  • 相关阅读:
    IO—》字节流&字符流
    IO—》递归
    IO—》File类
    IDEA快速升级模块版本号
    redis使用Jackson2JsonRedisSerializer序列化问题
    git 创建管理多用户
    linux后台启动程序脚本实例
    linux 安装配置kafka脚本
    linux 安装配置zookeeper脚本
    linux安装配置JDK脚本
  • 原文地址:https://www.cnblogs.com/PushyTao/p/13675759.html
Copyright © 2020-2023  润新知