hdu 1084 What Is Your Grade?

What Is Your Grade?

                                                                           Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
                                                                                                 Total Submission(s): 8522    Accepted Submission(s): 2616


Problem Description
“Point, point, life of student!”
This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this course.
There are 5 problems in this final exam. And I will give you 100 points if you can solve all 5 problems; of course, it is fairly difficulty for many of you. If you can solve 4 problems, you can also get a high score 95 or 90 (you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems). Analogically(以此类推), you can get 85、80、75、70、65、60. But you will not pass this exam if you solve nothing problem, and I will mark your score with 50.
Note, only 1 student will get the score 95 when 3 students have solved 4 problems.
I wish you all can pass the exam! 
Come on!
 

Input
Input contains multiple test cases. Each test case contains an integer N (1<=N<=100, the number of students) in a line first, and then N lines follow. Each line contains P (0<=P<=5 number of problems that have been solved) and T(consumed time). You can assume that all data are different when 0<p.
A test case starting with a negative integer terminates the input and this test case should not to be processed.
 

Output
Output the scores of N students in N lines for each case, and there is a blank line after each case.
 

Sample Input
  
  
4 5 06:30:17 4 07:31:27 4 08:12:12 4 05:23:13 1 5 06:30:17 -1
 

Sample Output
  
  
100 90 90 95 100
 

Author
lcy
 

数据处理题最主要的时看清题  细心点就行
注意每个层次只有一个人的时候这个人可以拿到该层次的最高分。。
具体处理下面代码有注释。。。。。。
#include<iostream>
#include<cstdio>
#include<cstring>
#define M 100001000
#include<algorithm>
using namespace std;
struct node{
    int n,time;
}a[1005];//记录每个同学的答题状态和所用时间
int main()
{
    int cas,flag5,flag4,flag3,flag2,flag1;//用于统计每个层次的人数
    int s[1005],sa[1005],e[1005],y[1005];//记录每个层次排名前50%的人的位置
    int n,i;
    int l,q,p,k;
    char str[20];
    while(cin>>cas)
    {
        if(cas<0)
            break;
        flag4=flag3=flag2=flag1=0;
        for(i=0;i<cas;i++)
        {
            cin>>a[i].n;
            if(a[i].n==4)
                flag4++;
            else if(a[i].n==3)
                flag3++;
            else if(a[i].n==2)
                flag2++;
            else if(a[i].n==1)
                flag1++;
            cin>>str;
            a[i].time=3600*(10*(str[0]-'0')+str[1]-'0')+60*(10*(str[3]-'0')+str[4]-'0')+10*(str[6]-'0')+str[7]-'0';//全部转化为秒
        }
        if(flag4!=1)
        flag4=(flag4)/2;
        if(flag3!=1)
        flag3=flag3/2;
        if(flag2!=1)
        flag2=flag2/2;
        if(flag1!=1)
        flag1=flag1/2;
        //每个层次只有前一半能拿到该层次的最高分   当每个层次只有一个人的时候那么这个人就能拿到该层次的最高分
        l=0;q=0;p=0;k=0;
        int b;
        int mixn;
        for(i=0;i<cas;i++)  //标记出每个层次排名前50%的人的位置
        {
            if(a[i].n==4&&flag4)
            {
                mixn=a[i].time;
                b=i;
                for(int j=0;j<cas;j++)//每次循环都能找出该层次中用时最少的那个人的位置
                                      //并将其标记且赋一个很大的值保证下次循环不会再被使用
                  {
                    if(a[j].n==4&&a[j].time<mixn)
                       {
                           mixn=a[j].time;
                           b=j;
                       }

                  }
                       s[l++]=b;
                       a[b].time=M;
                       flag4--;
            }

            if(a[i].n==3&&flag3)
            {
                  mixn=a[i].time;
                  b=i;
                  for(int j=0;j<cas;j++)
                  {
                      if(a[j].n==3&&a[j].time<mixn)
                       {
                        mixn=a[j].time;
                        b=j;
                       }
                   }
                   sa[q++]=b;
                   a[b].time=M;
                   flag3--;
            }

            if(a[i].n==2&&flag2)
            {
                mixn=a[i].time;
                b=i;
                for(int j=0;j<cas;j++)
                   {
                       if(a[j].n==2&&a[j].time<mixn)
                       {
                        mixn=a[j].time;
                          b=j;
                       }
                   }
                    e[p++]=b;
                    a[b].time=M;
                    flag2--;
            }
              if(a[i].n==1&&flag1)
            {
                mixn=a[i].time;
                b=i;
                for(int j=0;j<cas;j++)
                   {
                       if(a[j].n==1&&a[j].time<mixn)
                       {
                        mixn=a[j].time;
                          b=j;
                       }
                   }
                    y[k++]=b;
                    a[b].time=M;
                    flag1--;
            }
        }
        for(i=0;i<cas;i++)//输出
        {
            if(a[i].n==5)
                cout<<"100"<<endl;
            else if(a[i].n==4)
            {
                flag4=0;//前面的flag在后面没有用了所以偷了点懒重新利用了一下用于标记该同学的排名是否是他所处层次的前50%
                for(int j=0;j<l;j++)
                  {
                     if(s[j]==i)
                      {
                        cout<<"95"<<endl;
                        flag4=1;
                        break;
                      }
                 }
                if(!flag4)
                    {
                       cout<<"90"<<endl;

                    }
            }
             else if(a[i].n==3)
            {
                flag3=0;
                for(int j=0;j<q;j++)
               {
                   if(sa[j]==i)
                    {
                        cout<<"85"<<endl;
                        flag3=1;
                        break;
                    }

               }
               if(!flag3)
                    {
                        cout<<"80"<<endl;
                    }
            }
             else if(a[i].n==2)
            {
                flag2=0;
                for(int j=0;j<p;j++)
               {
                    if(e[j]==i)
                    {
                        cout<<"75"<<endl;
                        flag2=1;
                        break;
                    }

               }
                 if(!flag2)
                    {
                        cout<<"70"<<endl;
                    }
            }
             else if(a[i].n==1)
            {
                flag3=0;
                for(int j=0;j<k;j++)
                {
                    if(y[j]==i)
                    {
                        cout<<"65"<<endl;
                        flag3=1;
                        break;
                    }
                }
                if(!flag3)
                {
                    cout<<"60"<<endl;
                }
            }
            else
                cout<<"50"<<endl;
        }
        cout<<endl;
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,HDU1622是一道关于二叉树的题目,要求读入一系列二叉树的节点信息,输出它们的层序遍历结果。如果输入的二叉树不完整或存在重复节点,则输出"not complete"。下面是Java的实现代码: ```java import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { static class Node { int val; Node left, right; public Node(int val) { this.val = val; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String s = sc.nextLine(); if (s.isEmpty()) { continue; } String[] nodes = s.split("\\s+"); Node root = new Node(Integer.parseInt(nodes[0].substring(1))); Queue<Node> queue = new LinkedList<>(); queue.offer(root); boolean isComplete = true; for (int i = 1; i < nodes.length - 1; i += 2) { Node cur = queue.poll(); if (!nodes[i].equals("()")) { cur.left = new Node(Integer.parseInt(nodes[i].substring(1))); queue.offer(cur.left); } else { isComplete = false; } if (!nodes[i + 1].equals("()")) { cur.right = new Node(Integer.parseInt(nodes[i + 1].substring(0, nodes[i + 1].length() - 1))); queue.offer(cur.right); } else { isComplete = false; } } if (!isComplete) { System.out.println("not complete"); continue; } StringBuilder sb = new StringBuilder(); queue.offer(root); while (!queue.isEmpty()) { Node cur = queue.poll(); sb.append(cur.val).append(" "); if (cur.left != null) { queue.offer(cur.left); } if (cur.right != null) { queue.offer(cur.right); } } System.out.println(sb.toString().trim()); } } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值