zoukankan      html  css  js  c++  java
  • (set)MG loves gold hdu6019

    MG loves gold
    Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
    Total Submission(s): 1607    Accepted Submission(s): 659
     
     
    Problem Description
    MG is a lucky boy. He is always be able to find gold from underground.
     
    It is known that the gold is a sequence with n elements, which has its own color C.
     
    MG can dig out a continuous area of sequence every time by using one shovel, but he's unwilling to dig the golds of the same color with one shovel.
     
    As a greedy person, he wish to take all the n golds away with least shovel.
    The rules also require MG not to dig twice at the same position.
     
    MG thought it very easy and he had himself disdained to take the job. As a bystander, could you please help settle the problem and calculate the answer?
     
    Input
    The first line is an integer T which indicates the case number.(1<=T<=10)
     
    And as for each case, there are 1 integer n in the first line which indicate gold-number(1<=n<=100000).
     
    Then there are n integers C in the next line, the x-th integer means the x-th gold’s color(|C|<=2000000000).
     
    Output
    As for each case, you need to output a single line.
     
    there should be one integer in the line which represents the least possible number of shovels after taking away all n golds.
     
    Sample Input
    2
    5
    1 1 2 3 -1
    5
    1 1 2 2 3
     
    Sample Output
    2
    3
     
    #include <iostream> //就是碰上相同的金坷垃就换铁锹。
    #include <cstdio>
    #include <set>
    using namespace std;
    int main()
    {
    int T;
    long long a;
    set<int> s;
    scanf("%d",&T);
    while(T--)
    {
    int n,sum=1;
    scanf("%d",&n);
    s.clear();
    for(int i=0;i<n;i++)
    {
    scanf("%d",&a); //少点用数组,可能会超时。
    if(s.count(a))
    {
    sum++;
    s.clear();
    }
    s.insert(a);
    }
    cout<<sum<<endl;
    }
    return 0;
    }
     
     
  • 相关阅读:
    CHANGE YOUR BROWSER’S USER AGENT STRING TO VIEW IPAD READY WEBSITES
    javascript鼠标后面跟当前坐标
    四月上半月总结(雅虎面试+玩)
    the way javascript create objects
    Navigator 对象
    三月份总结(后台规范+面试)
    SVN客户端使用教程
    44种IE css bug实例测试总结(转载)
    处理兼容性问题(浮动),以及解决方法
    调用网页头部和尾部的公共部分
  • 原文地址:https://www.cnblogs.com/Weixu-Liu/p/9174853.html
Copyright © 2011-2022 走看看