http://poj.org/problem?id=3665

题目描述

Fatigued by the endless toils of farming, Farmer John has decided to try his hand in the MP3 player market with the new iCow.

It is an MP3 player that stores N songs (1 <= N <= 1,000) indexed 1 through N that plays songs in a "shuffled" order,

as determined by Farmer John's own algorithm:

* Each song i has an initial rating Ri (1 <= Ri <= 10,000).

* The next song to be played is always the one with the highest rating (or, if two or more are tied, the highest rated song with the lowest index is chosen).

* After being played, a song's rating is set to zero, and its rating points are distributed evenly among the other N-1 songs.

* If the rating points cannot be distributed evenly (i.e., they are not divisible by N-1), then the extra points are parceled out one at a time to the first songs on the list (i.e., R1, R2, etc. -- but not the played song) until no more extra points remain.

This process is repeated with the new ratings after the next song is played. Determine the first T songs (1 <= T <= 1000) that are played by the iCow.

输入描述:

* Line 1: Two space-separated integers: N and T
* Lines 2..N+1: Line i+1 contains a single integer: Ri

输出描述:

* Lines 1..T: Line i contains a single integer that is the i-th song that the iCow plays.

输入


输出


说明

The iCow contains 3 songs, with ratings 10, 8, and 11, respectively. You must determine the first 4 songs to be played.
The ratings before each song played are:
R1 R2 R3
10 8 11 -> play #3 11/2 = 5, leftover = 1
16 13 0 -> play #1 16/2 = 8
0 21 8 -> play #2 21/2 = 10, leftover = 1
11 0 18 -> play #3 ...

刚开始以为要用优先队列,结果越写越麻烦,最后写乱了,wa了,还不如直接暴力做

 #include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <math.h> #define INF 0x3f3f3f3f
#define MAXN 1005
const int mod = 1e9 + ; using namespace std; int d[MAXN]; int main()
{
int N, K;
cin >> N >> K; for (int i = ; i <= N; i++)
scanf("%d", &d[i]); while (K--) {
int maxx = -;
int flag = ;
for (int i = ; i <= N; i++)
if (d[i] > maxx)
maxx = d[i], flag = i;
printf("%d\n", flag);
int temp = d[flag] / (N - );
if (temp) {
for (int i = ; i <= N; i++) {
if (i != flag)
d[i] += temp;
}
}
temp = d[flag] % (N - );
d[flag] = ;
if (temp) {
for (int i = ; i <= N && temp; i++) {
if (i != flag)
d[i]++, temp--;
}
}
} return ;
}

poj-3665 iCow(暴力吧)的更多相关文章

  1. POJ - 3665 icow

    Fatigued by the endless toils of farming, Farmer John has decided to try his hand in the MP3 player ...

  2. POJ - 3665 iCow(模拟)

    题意:有N首歌曲,播放的顺序按照一定的规则,输出前T首被播放的歌的编号.规则如下: 1.每首歌有一个初始的等级r,每次都会播放当前所有歌曲中r最大的那首歌(若r最大的有多首,则播放编号最小的那首歌). ...

  3. poj 2363 Blocks(暴力)

    题目链接:http://poj.org/problem?id=2363 思路分析:由于数据较小,采用暴力搜索法.假设对于矩形边长 1 <= a <= b <= c <= N; ...

  4. poj 1731 Orders(暴力)

    题目链接:http://poj.org/problem?id=1731 思路分析:含有重复元素的全排列问题:元素个数为200个,采用暴力枚举法. 代码如下: #include <iostream ...

  5. POJ 2029 DP || 暴力

    在大矩形中找一个小矩形 使小矩形包括的*最多 暴力或者DP  水题 暴力: #include "stdio.h" #include "string.h" int ...

  6. POJ 2912 Rochambeau(暴力)+【带权并查集】

    <题目链接> 题目大意: n个人进行m轮剪刀石头布游戏(0<n<=500,0<=m<=2000),接下来m行形如x, y, ch的输入,ch='='表示x, y平局 ...

  7. POJ 2912 - Rochambeau - [暴力枚举+带权并查集]

    题目链接:http://poj.org/problem?id=2912 Time Limit: 5000MS Memory Limit: 65536K Description N children a ...

  8. POJ 3414 Pots 暴力,bfs 难度:1

    http://poj.org/problem?id=3414 记录瓶子状态,广度优先搜索即可 #include <cstdio> #include <cstring> #inc ...

  9. POJ 1971-Parallelogram Counting,暴力1063ms!

    Parallelogram Counting 刚学hash还不会用,看到5000ms的时限于是想着暴力来一发应该可以过.以前做过类似的题,求平行四边形个数,好像是在CF上做的,但忘了时限是多少了,方法 ...

  10. POJ 1840 Eqs 暴力

      Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The ...

随机推荐

  1. java基础——既然有了字节流,为什么还要有字符流呢?

    不管是文件读写还是网络发送接收,信息的最小存储单元都是字节,那为什么I/O流操作要分字节流操作和字符流操作呢? 字符流是由JVM将字节转换得到的,所以这个过程还是非常耗时的,同样假如我们不知道编码方式 ...

  2. MessageBox.Show的使用

    MessageBox.Show("内容","标题") // 摘要:// 使用指定的帮助文件.HelpNavigator 和帮助主题显示一个具有指定文本.标题.按 ...

  3. Spring Boot Actuator Endpoints

    常用内建的Endpoints: beans:显示当前Spring应用上下文的Spring Bean完整列表(包含所有ApplicationContext的层次) conditions:显示当前应用所有 ...

  4. JDK8 API离线文档免费下载&JavaEE API文档离线下载&API在线查看链接&常用的JAR包下载

    1.JDK8 API离线文档 链接:https://pan.baidu.com/s/1fYc-QesmYRumTEPmnSgEKA 提取码:2bdr 2.JavaEE API文档离线下载 链接:htt ...

  5. Python说文解字_Python之多任务_03

    问:线程学完了,现在我们开始学习进程了吧? 答:是的.前面说到线程就是我们的手,我们现在可以学习一下我们的“胳膊”了. 我们有了多线程,为什么还要学习多进程呢?这是因为在Python当中有一把GIL锁 ...

  6. 解压版mysql安装步骤

    第一步:解压mysql,例如解压后的目录在C:\Program Files\mysql-5.6.36-winx64 第二步:配置mysql环境变量,类似配置java的环境变量 计算机右键===> ...

  7. 关于Java的String字符串常量的长度问题

    虽然这种问题应该很难遇到,但是遇到了也会感到莫名其妙.不知道大家有没有遇到那种在java代码里用字符串写sql语句的情况,但是如果sql语句字符串的长度太长的话就会报错. 代码如下: 代码A Stri ...

  8. JS高级学习笔记(2)之js多线程

    参考大神:Javascript多线程 web worker ---- 6.Web Worker 概述 截图过来: 线程之间的通信 let worker = new Worker(‘js文件路径’) 主 ...

  9. Python语言基础与应用 (P16)上机练习:基本数据类型

    本文是笔者在学习MOOC课程<Python语言基础与应用> (北京大学-陈斌)中根据上机课时的要求写下在代码 课程总链接: 中国大学MOOC B站 本节课链接 数值基本运算: 33和7+, ...

  10. 解决 springweb Filter 读取request body miss body

    package com.lb.demo.listener; import java.io.BufferedReader; import java.io.ByteArrayInputStream; im ...