zoukankan      html  css  js  c++  java
  • light oj 1148

    1148 - Mad Counting
    Time Limit: 0.5 second(s) Memory Limit: 32 MB

    Mob was hijacked by the mayor of the Town "TruthTown". Mayor wants Mob to count the total population of the town. Now the naive approach to this problem will be counting people one by one. But as we all know Mob is a bit lazy, so he is finding some other approach so that the time will be minimized. Suddenly he found a poll result of that town where N people were asked "How many people in this town other than yourself support the same team as you in the FIFA world CUP 2010?" Now Mob wants to know if he can find the minimum possible population of the town from this statistics. Note that no people were asked the question more than once.

    Input

    Input starts with an integer T (≤ 100), denoting the number of test cases.

    Each case starts with an integer N (1 ≤ N ≤ 50). The next line will contain N integers denoting the replies (0 to 106) of the people.

    Output

    For each case, print the case number and the minimum possible population of the town.

    Sample Input

    Output for Sample Input

    2

    4

    1 1 2 2

    1

    0

    Case 1: 5

    Case 2: 1

     题意:现在要求一个村庄的总人数,向n个人询问在他们的村庄有多少人和他自己喜欢同一个球队根据数据估计村庄的最少人数

    题解:输入数据对数据从小到大排序,如果有连续相同的数a则将这些连续相同的看做是喜欢的同一个球队的人,(相同的个数最多是a+1  如果超过这个则按另一支队算)

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #define MAX 1000
    #define MAXM 1001000
    #define INF 0x7fffff
    #define LL long long 
    using namespace std;
    int s[MAXM];
    int main()
    {
    	int n,m,j,i,t,k;
    	int sum;
    	//LL sum;
    	scanf("%d",&t);
    	k=1;
    	while(t--)
    	{
    		sum=0;
    		int ans;
    		scanf("%d",&n);
    		for(i=0;i<n;i++)
    		    scanf("%d",&s[i]);
    		sort(s,s+n);
    		for(i=0;i<n;i++)
    		{	
    		    int num=0;	    
    			ans=s[i];
    			num=s[i];
    			while(s[i+1]==ans&&num)
    			{
    				i=i+1;
    				num--;
    			}
    			sum=sum+ans+1;
    		}
    		printf("Case %d: ",k++);
    		printf("%d
    ",sum);
    	}
    	return 0;
    }
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #define MAX 1000
    #define MAXM 1001000
    #define INF 0x7fffff
    #define LL long long 
    using namespace std;
    int s[MAXM];
    int main()
    {
    	int n,m,j,i,t,k;
    	int sum;
    	//LL sum;
    	scanf("%d",&t);
    	k=1;
    	while(t--)
    	{
    		sum=0;
    		int ans;
    		scanf("%d",&n);
    		for(i=0;i<n;i++)
    		    scanf("%d",&s[i]);
    		sort(s,s+n);
    		for(i=0;i<n;i++)
    		{	
    		    int num=0;	    
    			ans=s[i];
    			num=s[i];
    			while(s[i+1]==ans&&num)
    			{
    				i=i+1;
    				num--;
    			}
    			sum=sum+ans+1;
    		}
    		printf("Case %d: ",k++);
    		printf("%d
    ",sum);
    	}
    	return 0;
    }
    

      

  • 相关阅读:
    Neutron 理解 (1): Neutron 所实现的虚拟化网络 [How Netruon Virtualizes Network]
    openstack里面的Provider network 和 Tenant network 的区别
    Openstack网络相关概念比较复杂,经常使人混淆,本文进行相关说明。
    OpenStack 网络:Neutron 初探
    openstack 网络架构 nova-network + neutron
    Java 性能测试的四项原则
    微信公众号开发之微信买单
    微信公众号开发之如何使用JSSDK
    微信公众号开发之如何一键导出微信所有用户信息到Excel
    [内核驱动] 链表LIST_ENTRY的操作(转)
  • 原文地址:https://www.cnblogs.com/tonghao/p/4909783.html
Copyright © 2011-2022 走看看