Codeforces Round 65 B. Progress Bar(71)

https://codeforces.com/contest/71/problem/B

以上是本题地址,大家可以注册,然后在上面练习。

/*
A progress bar 进度条 is an element of graphical interface that displays the progress of a process for this very moment before it is completed.
Lets take a look at the following form of such a bar.

A bar is represented as squares 正方形, located in line.
To add clarity 为了更加清晰, let's number them with positive integers from 1 to z from the left to the right.

Each square has saturation 饱和度 (ai for the i-th square),
which is measured 度量 by an integer from 0 to k.
When the bar for some i is displayed,
squares 1,2,..., i- 1 has the saturation k,
squares i+1,i+2, ..., n has the saturation 0,
and the saturation of the square i can have any value from 0 to k.

So some first squares of the progress bar always have the saturation.
Some last squares always have the saturation 0.
And there is no more than one square that has the saturation different from 0 and k.

The degree of the process's completion is measured in percents.
Let the process be t% completed. Then the following inequation is fulfilled:

An example of such a bar can be seen on the picture.
n = 10, k = 10, t = 54
a: 10 10 10 10 10 4 0 0 0 0

For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.

Examples

Input

10 10 54

Output

10 10 10 10 10 4 0 0 0 0

Input

11 13 37

Output

13 13 13 13 0 0 0 0 0 0 0

*/

原题

分析:10,10,54 就显示5个10,1个4,其余0

公式 5 = (n*k * t%) / 整除 k

公式 4 = (n*k * t%) % 取余 k

从以上就可以知道,这个程序大概意思。

以下是本人写的代码(这次未参考别人),由于简单,所以一次成功!

Codeforces Beta Round 65 (Div. 2)

cpp 复制代码
/*
A progress bar is an element of graphical interface that displays the progress of a process 
 for this very moment before it is completed.
 
Lets take a look at the following form of such a bar.

A bar is represented as  squares, located in line.
To add clarity, let's number them with positive integers from 1 to z from the lett to the right. 

Each square has saturation (a; for the i-th square), 
which is measured by an integer from 0 to k. 
When the bar for some i is displayed, 
squares 1,2,..., i- 1 has the saturation k, 
squares i+1,i+2, ..., n has the saturation 0, 
and the saturation of the square i can have any value from 0 to k.

So some first squares of the progress bar always have the saturation.
Some last squares always have the saturation 0. 
And there is no more than one square that has the saturation different from 0 and k.

The degree of the process's completion is measured in percents. 
Let the process be t% completed. Then the following inequation is fulfilled:

An example of such a bar can be seen on the picture.
n = 10 k = 10 t = 54
a: 10 10 10 10 10 4 0 0 0 0

For the given n, k, t determine the measures of saturation for 
all the squares ai of the progress bar.

Examples
Input
10 10 54

Output
10 10 10 10 10 4 0 0 0 0

Input
11 13 37

Output
13 13 13 13 0 0 0 0 0 0 0
*/


#include <iostream>
using namespace std;

void cal_progress_bar(int n, int k, int t)
{
	int product = n*k;
	int c1 = 0;
	c1 = t*product*0.01;

	int number1 = 0;
	int number2 = 0;

	number1 = c1 / k;
	
	number2 = c1 % k;

	char space1 = ' ';
	for (int i = 0; i < number1; i++)
	{
		cout << k << space1;
	}
	
	int len = 0;
	if (number2>0)
	{
		cout << number2 << space1;
		len= n - number1 - 1;
	}
	else
	{
		len = n - number1;
	}

	for (int i = 0; i < len; i++)
	{
		cout << 0 << space1 ;
	}

}

int main()
{
	int n = 0, k = 0, t = 0;
	while (cin >> n >> k >> t)
	{
		cal_progress_bar(n, k, t);
	}
	return 0;
}
相关推荐
.格子衫.30 分钟前
022数据结构之树状数组——算法备赛
数据结构·算法·1024程序员节
黑科技Python43 分钟前
生活中的“小智慧”——认识算法
学习·算法·生活
Yupureki43 分钟前
从零开始的C++学习生活 16:C++11新特性全解析
c语言·数据结构·c++·学习·visual studio
紫荆鱼1 小时前
设计模式-迭代器模式(Iterator)
c++·后端·设计模式·迭代器模式
sali-tec2 小时前
C# 基于halcon的视觉工作流-章52-生成标定板
开发语言·图像处理·人工智能·算法·计算机视觉
IT古董2 小时前
【第五章:计算机视觉-项目实战之推荐/广告系统】2.粗排算法-(4)粗排算法模型多目标算法(Multi Task Learning)及目标融合
人工智能·算法·1024程序员节
熬了夜的程序员2 小时前
【LeetCode】89. 格雷编码
算法·leetcode·链表·职场和发展·矩阵
应茶茶2 小时前
C++11 核心新特性:从语法重构到工程化实践
java·开发语言·c++
對玛祷至昏2 小时前
数据结构理论知识
数据结构·算法·排序算法
oliveira-time2 小时前
二分搜索(Binary Search)
算法