poj-3665 iCow(暴力吧)
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(暴力吧)的更多相关文章
- POJ - 3665 icow
Fatigued by the endless toils of farming, Farmer John has decided to try his hand in the MP3 player ...
- POJ - 3665 iCow(模拟)
题意:有N首歌曲,播放的顺序按照一定的规则,输出前T首被播放的歌的编号.规则如下: 1.每首歌有一个初始的等级r,每次都会播放当前所有歌曲中r最大的那首歌(若r最大的有多首,则播放编号最小的那首歌). ...
- poj 2363 Blocks(暴力)
题目链接:http://poj.org/problem?id=2363 思路分析:由于数据较小,采用暴力搜索法.假设对于矩形边长 1 <= a <= b <= c <= N; ...
- poj 1731 Orders(暴力)
题目链接:http://poj.org/problem?id=1731 思路分析:含有重复元素的全排列问题:元素个数为200个,采用暴力枚举法. 代码如下: #include <iostream ...
- POJ 2029 DP || 暴力
在大矩形中找一个小矩形 使小矩形包括的*最多 暴力或者DP 水题 暴力: #include "stdio.h" #include "string.h" int ...
- POJ 2912 Rochambeau(暴力)+【带权并查集】
<题目链接> 题目大意: n个人进行m轮剪刀石头布游戏(0<n<=500,0<=m<=2000),接下来m行形如x, y, ch的输入,ch='='表示x, y平局 ...
- POJ 2912 - Rochambeau - [暴力枚举+带权并查集]
题目链接:http://poj.org/problem?id=2912 Time Limit: 5000MS Memory Limit: 65536K Description N children a ...
- POJ 3414 Pots 暴力,bfs 难度:1
http://poj.org/problem?id=3414 记录瓶子状态,广度优先搜索即可 #include <cstdio> #include <cstring> #inc ...
- POJ 1971-Parallelogram Counting,暴力1063ms!
Parallelogram Counting 刚学hash还不会用,看到5000ms的时限于是想着暴力来一发应该可以过.以前做过类似的题,求平行四边形个数,好像是在CF上做的,但忘了时限是多少了,方法 ...
- POJ 1840 Eqs 暴力
Description Consider equations having the following form: a1x13+ a2x23+ a3x33+ a4x43+ a5x53=0 The ...
随机推荐
- git本地仓库连接同步修改远程仓库
如何使用GIT BASH同步远程仓库 1. 新建一个目录 2. 右键GIT BASH 3. git clone git@github.com:purity12138/221701117.git (SS ...
- codeforces 596 C. p-binary
题意:给你一个n和一个p,让你用 (2k+p)进制来表示n,找出用最少的(2k+p)来表示n. 分析:首先我们看到2k,首先下想到二进制,我们可以我们列出式子,也就是 (2x1 + p)+(2x2 + ...
- handler method 参数绑定常用注解
handler method 参数绑定常用的注解,我们根据他们处理的Request的不同内容部分分为四类: A.处理requet uri 部分(这里指uri template中variable,不含q ...
- spring aop中的propagation的7种配置
1.前言 在声明式的事务处理中,要配置一个切面,即一组方法,如 <tx:advice id="txAdvice" transaction-manager="txMa ...
- Map的6种遍历方法
声明:迁移自本人CSDN博客https://blog.csdn.net/u013365635 探讨有几种遍历Map的方法其实意义并不大,网上的文章一般讲4种或5种的居多,重要的是知道遍历的内涵,从遍历 ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:Date(日期) 对象
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- py02_04:三元运算法
a if a > b else c # a>b 成立,则为真,如果a>b为假,则返回c
- PROOF|ADOBE READER
样稿PROOF,最后是印刷样张. 修改校样是最后一次修改错误. 每一版editor不一样,任务不同. 不能修改工作单位,但是可以加一个标注. 最好使用ADOBE READER中的COMMENT& ...
- 面试准备 css 书写顺序及原理
书写顺序 (1)定位属性:position display float left top right bottom overflow clear z-index (2)自身属性: ...
- iTOP-4412-Ubuntu系统源码-ubuntu没有声音的解决办法
准备工作 1.下载 vim 在命令行上输入 apt-get install vim 下载 vim 2.输入 vim /etc/hosts 在所打开界面的第一行最后写上 iTOP4412-ubuntu- ...