• Codeforces Round #257 (Div. 2) A题


    A. Jzzhu and Children
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There are n children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1to n. The i-th child wants to get at least ai candies.

    Jzzhu asks children to line up. Initially, the i-th child stands at the i-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm:

    1. Give m candies to the first child of the line.
    2. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home.
    3. Repeat the first two steps while the line is not empty.

    Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order?

    Input

    The first line contains two integers n, m (1 ≤ n ≤ 100; 1 ≤ m ≤ 100). The second line contains n integersa1, a2, ..., an (1 ≤ ai ≤ 100).

    Output

    Output a single integer, representing the number of the last child.

    Sample test(s)
    input
    5 2
    1 3 1 4 2
    output
    4
    input
    6 4
    1 1 2 2 3 3
    output
    6
    Note

    Let's consider the first sample.

    Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the end of the line. Currently the line looks like [5, 2, 4]. Then child 5 gets 2 candies and goes home. Then child 2 gets two candies and goes home, and finally child 4 gets 2 candies and goes home.

    Child 4 is the last one who goes home.

    ---------------------------------------------------

    题目意思是给几个孩子发糖,每个孩子都有自己要的糖的个数,但是每次只是固定的发一定量的糖,每个没拿到自己期望的糖数就到队尾继续排队,问你最后走的孩子是几号

    、、、、、、、、、、、、、、、、、、、、、、、、、、

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <stdlib.h>
     4 #include <iostream>
     5 #include <algorithm>
     6 
     7 using namespace std;
     8 
     9 int main()
    10 {
    11     int n,m,i,j;
    12     while(scanf("%d%d",&n,&m)!=EOF)
    13     {
    14         int str[105],maxx=0,st;
    15         for(i=0;i<n;i++)
    16         {
    17             scanf("%d",&str[i]);
    18             if(maxx<str[i])
    19             {
    20                 maxx=str[i];
    21             }
    22         }
    23         st=maxx/m;
    24         if(st*m<maxx)
    25         {
    26             st++;
    27         }//printf("%d%d**",st,maxx);
    28         for(i=0;i<n;i++)
    29         {
    30             str[i]-=(st-1)*m;//printf("%d**",str[i]);
    31         }
    32         int res=0,cas;
    33         for(i=0;i<n;i++)
    34         {
    35             if(str[i]>0)
    36             {
    37                 //res=str[i];
    38                 cas=i;
    39             }
    40         }
    41         printf("%d
    ",cas+1);
    42     }
    43     return 0;
    44 }

    这是队列模拟的

     1 #include <stdio.h>
     2 #include <iostream>
     3 #include <algorithm>
     4 #include <queue>
     5 
     6 using namespace std;
     7 
     8 typedef struct stu
     9 {
    10     int id,m;
    11 }stu;
    12 stu str[105];
    13 
    14 int main()
    15 {
    16     int i,j,n,m,k,t;
    17 
    18     while(scanf("%d%d",&n,&m)!=EOF)
    19     {
    20         queue<stu >q;
    21 
    22         for(i=0;i<n;i++)
    23         {
    24             scanf("%d",&str[i].m);
    25             str[i].id=i+1;
    26             q.push(str[i]);
    27         }
    28         int tmp=0;
    29         while(!q.empty())
    30         {
    31             stu x=q.front();
    32             q.pop();
    33             if(x.m<=m)
    34             {
    35                 tmp=x.id;
    36             }
    37             else
    38             {
    39                 x.m-=m;
    40                 q.push(x);
    41             }
    42         }
    43         printf("%d
    ",tmp);
    44     }
    45     return 0;
    46 }

    这题A题卡了我好久,主要因为数组模拟没有想到找最大的那个趟数来模拟

    经验不足……

  • 相关阅读:
    循环处理
    XMLHttpRequest 加载进度
    createjs 的 bitmapdata类
    console打印数组object具体内容
    html5 粒子组合成logo 的制作思路及方法
    createjs 更新
    css取消input、select默认样式(手机端)
    js获取url参数 兼容某些带#url
    Adobe Edge Animate CC 不再开发更新!
    《FLASH CC 2015 CANVAS 中文教程》——3、this关键字 入门
  • 原文地址:https://www.cnblogs.com/ccccnzb/p/3869875.html
Copyright © 2020-2023  润新知