zcmu 思维题来一波~

目录

  1. 1031: Graveyard
  2. 1325: 整除的尾数
  3. 1327: 核电站问题
  4. 1333: 盐水的故事
  5. 2067: 翻硬币(思维+字符串)

1031: Graveyard

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 229  Solved: 118
[Submit][Status][Web Board]

Description

Programming contests became so popular in the year 2397 that the governor of New Earck -- the largest human-inhabited planet of the galaxy -- opened a special Alley of Contestant Memories (ACM) at the local graveyard. The ACM encircles a green park, and holds the holographic statues of famous contestants placed equidistantly along the park perimeter. The alley has to be renewed from time to time when a new group of memorials arrives.

When new memorials are added, the exact place for each can be selected arbitrarily along the ACM, but the equidistant disposition must be maintained by moving some of the old statues along the alley.

Surprisingly, humans are still quite superstitious in 24th century: the graveyard keepers believe the holograms are holding dead people souls, and thus always try to renew the ACM with minimal possible movements of existing statues (besides, the holographic equipment is very heavy). Statues are moved along the park perimeter. Your work is to find a renewal plan which minimizes the sum of travel distances of all statues. Installation of a new hologram adds no distance penalty, so choose the places for newcomers wisely!

Input

The input file contains several test cases, each of them consists of a a line that contains two integer numbers: n -- the number of holographic statues initially located at the ACM, and m -- the number of statues to be added (2<=n<=1000, 1<=m<=1000) . The length of the alley along the park perimeter is exactly 10 000 feet.

Output

For each test case, write to the output a line with a single real number -- the minimal sum of travel distances of all statues (in feet). The answer must be precise to at least 4 digits after decimal point.

Pictures show the first three examples. Marked circles denote original statues, empty circles denote new equidistant places, arrows denote movement plans for existing statues.

Sample Input

2 1

2 3

3 1

10 10

Sample Output

1666.6667

1000.0000

1666.6667

0.0000

HINT

Source

浙江中医药大学第六届程序设计竞赛

【题意】周长为10000的圆环放n个物体,现在加进m个物体,问最少移动的距离。

【分析】原来是n个物体时,间隔disn=10000/n;现在是n+m个物体间隔是dism=10000/(n+m);

初始时另起点和终点(st、ed)都在0处,然后枚举过去,比较相邻两点的距离,选择小距离(绝对值进行比较)

【代码】

#include
#include
#include
using namespace std;

int main()
{
	int n,m;
	while(~scanf("%d%d",&n,&m))
	{
		double ans=0;
		double st=0,ed=0;
		double disn=10000.0/n,dism=10000.0/(m+n);
		int x=m+n;
		while(x--)
		{
			if(fabs(ed-st)

1325: 整除的尾数

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 592  Solved: 326
[Submit][Status][Web Board]

Description

一个整数,只知道前几位,不知道末二位,被另一个整数除尽了,那么该数的末二位该是什么呢

Input

输入数据有若干组,每组数据包含二个整数a,b(0<a<10000, 10<b<100),若遇到0 0则处理结束

Output

对应每组数据,将满足条件的所有尾数在一行内输出,格式见样本输出。同组数据的输出,其每个尾数之间空一格,行末没有空格。

Sample Input

200 40

1992 95

0 0

Sample Output

00 40 80

15

【分析】将a乘100后从0加到100来除以b(注意不是11~100,因为后两位是可以有类似于01、02这种前缀0的数的),如果能整除则存进数组,然后输出。

【代码】

#include
#include
#include
#include
using namespace std;
int num[105];
int main()
{
    int a,b;
    while(~scanf("%d%d",&a,&b)&&a&&b)
    {
    	int sum=0,t=0;
    	for(int i=0;i<100;i++)
    	{
    		sum=a*100+i;
    		if(sum%b==0)
    			num[t++]=i;
    	}
    	for(int i=0;i

1327: 核电站问题

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 193  Solved: 162
[Submit][Status][Web Board]

Description

一个核电站有N个放核物质的坑,坑排列在一条直线上。如果连续3个坑中放入核物质,则会发生爆炸,于是,在某些坑中可能不放核物质。现在,请你计算:对于给定的N,求不发生爆炸的放置核物质的方案总数。

Input

输入文件只有多行,每行对应一个正整数N<=40;

Output

输出文件有多行,每行只有一个正整数,表示方案总数

Sample Input

1

2

3

4

10

Sample Output

2

4

7

13

504

#include
#include
#include
#include
using namespace std;
int a[45];
int main()
{
	a[1]=2;a[2]=4;a[3]=7;
	for(int i=4;i<=45;i++)
	{
		a[i]=a[i-1]+a[i-2]+a[i-3];
	}
    int n;
    while(~scanf("%d",&n))
    {
	    printf("%d\n",a[n]);
	}
     return 0;
}

1333: 盐水的故事

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 576  Solved: 263
[Submit][Status][Web Board]

Description

挂盐水的时候,如果滴起来有规律,先是滴一滴,停一下;然后滴二滴,停一 下;再滴三滴,停一下...,现在有一个问题:这瓶盐水一共有VUL毫升,每一滴是D毫升,每一滴的速度是一秒(假设最后一滴不到D毫升,则花费的时间也 算一秒),停一下的时间也是一秒这瓶水什么时候能挂完呢?

Input

输入数据占一行,由VUL和D组成,其中0< D< VUL< 5000。

Output

请输出挂完盐水需要的时间。

Sample Input

10 1

Sample Output

13

【分析】因为最后不足Dml时,加的时间是不确定的。要注意这点。

【代码】

#include
#include
#include
#include
using namespace std;
int main()
{
	int v,d;
	while(~scanf("%d%d",&v,&d))
	{
	    int sum=0,i=1,k=0,t=0;
	    while(1)
	    {
	    	for(int j=1;j<=i;j++)
	    	{
	    	    sum+=d; 
	    	    t++;
	    	    if(sum>=v)
	    	    {
	    		printf("%d\n",t);
			return 0; 
	    	    }
		}
	    i++;t++;
	    }
	}
    return 0;
}

2067: 翻硬币(思维+字符串)

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 53  Solved: 38
[Submit][Status][Web Board]

Description

小明正在玩一个“翻硬币”的游戏。

桌上放着排成一排的若干硬币。我们用 * 表示正面,用 o 表示反面(是小写字母,不是零)。

比如,可能情形是:**oo***oooo

如果同时翻转左边的两个硬币,则变为:oooo***oooo

现在小明的问题是:如果已知了初始状态和要达到的目标状态,每次只能同时翻转相邻的两个硬币,那么对特定的局面,最少要翻动多少次呢?

我们约定:把翻动相邻的两个硬币叫做一步操作,那么要求:

Input

两行等长的字符串,分别表示初始状态和要达到的目标状态。每行的长度<1000

Output

一个整数,表示最小操作步数。

Sample Input

**********

o****o****

Sample Output

5

【分析】转换为整型数组用±1表示。

【代码】

#include
#include
#include
#include
#include
using namespace std;
const int maxn=1e3+5;
int a[maxn],b[maxn];
int main()
{
	string s1,s2;
	while(cin>>s1>>s2)
	{
		int ans=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b)); 
		int len=s1.length();
		for(int i=0;i

 

你可能感兴趣的:(ZCMU-OJ,思维,ACM刷题册)