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 ...
随机推荐
- oracle 导入问题(imp)
oracle 导入问题(imp) 1.密码过期 [oracle @oracle ~]$ imp graph/graph@orcl file=/tmp/neo4j.dmp full=y; 解决方案: 使 ...
- 报错:Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
1.问题 写了一个简单的单层神经网络跑mnist手写数字集,结果每次fit都会出现dead kernel 很多dead kernel首先不要急着去网上搜dead kernel怎么解决,因为大家出现的原 ...
- 19 01 04 CSS3 圆角 grba(带通明的) tansition动画 transform变换 animation动画
CSS3圆角 设置某一个角的圆角,比如设置左上角的圆角:border-top-left-radius:30px 60px; 同时分别设置四个角: border-radius:30px 60px 120 ...
- linux 下shell 编写脚本
linux 下shell 编写脚本: 1.程序结构练习:编写一个脚本,给定一个正整数,计算出这个数所有位的数字之和. 例如:程序给定输入123,那么应该返回1+2+3=6. 2.程序结构练习:编写一个 ...
- 12 react 基础 的 css 过渡动画 及 动画效果 及 使用 react-transition-group 实现动画
一. 过渡动画 # index.js import React from 'react';import ReactDOM from 'react-dom';import App from './app ...
- windows server 2012 ftp搭建
1.安装IIS的时候勾选ftp 2.创建ftp站点,先检查21端口是否开放 一定要勾选身份认证,匿名去掉,不然一直登陆不了,也不提示 一直点下一步, 遇到的坑,第一个:出现“打开ftp服务器上的文件夹 ...
- leetcode--200--python(深度广度优先遍历实现代码)
点滴积累,厚积薄发,做好每一天,向时间要效率,向生命要质量. 一.深度优先搜索和广度优先搜索DFS(Depth-First-Search),是盲目搜索算法的一种.常常用在树的遍历及图的处理上.假设当前 ...
- Maven--部署构件至 Nexus
日常开发生成的快照版本构件可以直接部署到 Nexus 中策略为 Snapshot 的宿主仓库中,项目正式发布的构件则应该部署到 Nexus 中策略为 Release 的宿主仓库中. <proje ...
- 数据处理pandas
1.缺失值时间戳不为NaN,为NaT, 同样判断都为isna()或notna()方法2.删值\去重 df.dropna() df.drop_duplicates() 3.上下值插值 df.fillna ...
- 22. docker 数据持久化 Data Volume
1 . 使用场景 在docker 容器被删除的时候 希望数据不丢失 2 . Volume 的使用 * 注意 在 mysql 的 Dockerfile 内 定义了 VOLUME ["var/ ...