UVA154 Recycling【水题】

Kerbside recycling has come to New Zealand, and every city from Auckland to Invercargill has leapt on to the band wagon. The bins come in 5 different colours — red, orange, yellow, green and blue — and 5 wastes have been identified for recycling — Plastic, Glass, Aluminium, Steel, and Newspaper. Obviously there has been no coordination between cities, so each city has allocated wastes to bins in an arbitrary fashion. Now that the government has solved the minor problems of today (such as reorganising Health, Welfare and Education), they are looking around for further challenges. The Minister for Environmental Doodads wishes to introduce the “Regularisation of Allocation of Solid Waste to Bin Colour Bill” to Parliament, but in order to do so needs to determine an allocation of his own. Being a firm believer in democracy (well some of the time anyway), he surveys all the cities that are using this recycling method. From these data he wishes to determine the city whose allocation scheme (if imposed on the rest of the country) would cause the least impact, that is would cause the smallest number of changes in the allocations of the other cities. Note that the sizes of the cities is not an issue, after all this is a democracy with the slogan “One City, One Vote”.
    Write a program that will read in a series of allocations of wastes to bins and determine which city’s allocation scheme should be chosen. Note that there will always be a clear winner.
Input
Input will consist of a series of blocks. Each block will consist of a series of lines and each line will contain a series of allocations in the form shown in the example. There may be up to 100 cities in a block. Each block will be terminated by a line starting with ‘e’. The entire file will be terminated by a line consisting of a single ‘#’.
Output
Output will consist of a series of lines, one for each block in the input. Each line will consist of the number of the city that should be adopted as a national example.
Sample Input
r/P,o/G,y/S,g/A,b/N
r/G,o/P,y/S,g/A,b/N
r/P,y/S,o/G,g/N,b/A
r/P,o/S,y/A,g/G,b/N
e
r/G,o/P,y/S,g/A,b/N
r/P,y/S,o/G,g/N,b/A
r/P,o/S,y/A,g/G,b/N
r/P,o/G,y/S,g/A,b/N
ecclesiastical

Sample Output
1
4

问题链接UVA154 Recycling
问题简述:(略)
问题分析:简单题不解释
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA154 Recycling */

#include <bits/stdc++.h>

using namespace std;

const int N = 5;

int main()
{
    map<char, int> m;
    m['r'] = 0, m['o'] = 1, m['y'] = 2, m['g'] = 3, m['b'] = 4;
    string s;
    vector<string> v[N];
    while(cin >> s) {
        if(s[0] == '#') break;
        else if(s[0] == 'e') {
            int end = v[0].size(), ans, maxc = 0;
            for(int i = 0; i < end; i++) {
                int cnt = 0;
                for(int j = 0; j < end; j++)
                    for(int k = 0; k < N; k++)
                        if(v[k][i] == v[k][j]) cnt++;
                if(cnt > maxc) {
                    maxc = cnt;
                    ans = i + 1;
                }
            }
            printf("%d\n", ans);
            for(int i = 0; i < N; i++) v[i].clear();
        } else
            for(int i = 0; i < 19; i += 4)
                v[m[s[i]]].push_back(s.substr(i, 3));
    }

    return 0;
}
发布了2259 篇原创文章 · 获赞 2368 · 访问量 263万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 代码科技 设计师: Amelia_0503

分享到微信朋友圈

×

扫一扫,手机浏览