【 题集 】 杭电ACM集训队训练赛(VI) 更新ing......

     无聊拉了一些题,发现自己好水, 一题都不会写,所以决定写个文章,以便监督自己把题写完,and   补题!!!

     链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=61926#status//-/0

     F - 验证角谷猜想

    最水的一题了,一开始竟然没看见!! 只需按着题目来模拟即可,不止为啥,还是习惯用c语言、、、

  

Description

数论中有许多猜想尚未解决,其中有一个被称为“角谷猜想”的问题,该问题在五、六十年代的美国多个著名高校中曾风行一时,这个问题是这样描述的:任何一个大于一的自然数,如果是奇数,则乘以三再加一;如果是偶数,则除以二;得出的结果继续按照前面的规则进行运算,最后必定得到一。现在请你编写一个程序验证他的正确性。
 

Input

本题有多个测试数据组,第一行为测试数据组数N,接着是N行的正整数。
 

Output

输出验证“角谷猜想”过程中的奇数,最后得到的1不用输出;每个测试题输出一行;每行中只有两个输出之间才能有一个空格;如果没有这样的输出,则输出:No number can be output !。
 

Sample Input

    
    
4 5 9 16 11
 

Sample Output

 
 
5 9 7 11 17 13 5 No number can be output !

   

#include <stdio.h>
#include <string.h>

int tt[1010];

int main()
{
    int t;
    int n;
    while(~scanf("%d",&t))
    {
        while(t --)
        {
            int cnt = 1;
            scanf("%d",&n);
            while(n != 1)
            {
                if(n % 2 == 1)
                {
                    tt[cnt ++] = n;
                }
                if(n % 2 == 0)
                {
                    n = n/2;
                }
                else
                {
                    n = n * 3 + 1;
                }
            }
            if(cnt == 1)
            {
                printf("No number can be output !");
            }
            else
            {
                printf("%d",tt[1]);
                for(int i = 2; i < cnt; i ++)
                    printf(" %d",tt[i]);
            }
            printf("\n");
        }
    }
}

    G - 前m大的数

    不知道为什么,看到这个题目的数据,就害怕了,要怎么写,会不会超时,要不要用快排?  到最后,我是用哈希,实现很简单,因为任意两个数加起来不会超过10000,所以用哈希比较简单,到最后竟然是0ms 过的,(其实我不知道怎么看时间复杂度)。不知道sort 能不能过,有兴趣可以试一试呀。

   

Description

还记得Gardon给小希布置的那个作业么?(上次比赛的1005)其实小希已经找回了原来的那张数表,现在她想确认一下她的答案是否正确,但是整个的答案是很庞大的表,小希只想让你把答案中最大的M个数告诉她就可以了。
给定一个包含N(N<=3000)个正整数的序列,每个数不超过5000,对它们两两相加得到的N*(N-1)/2个和,求出其中前M大的数(M<=1000)并按从大到小的顺序排列。
 

Input

输入可能包含多组数据,其中每组数据包括两行:
第一行两个数N和M,
第二行N个数,表示该序列。

 

Output

对于输入的每组数据,输出M个数,表示结果。输出应当按照从大到小的顺序排列。
 

Sample Input

    
    
4 4 1 2 3 4 4 5 5 3 6 4
 

Sample Output

  
  
7 6 5 5 11 10 9 9 8

   

#include <stdio.h>
#include <string.h>

int tt[10010];
int arr[3010];


int main()
{
	int n, m;
	int i, j;
	while(~scanf("%d%d",&n,&m))
	{
		memset(tt,0, sizeof(tt));
		for(i = 0; i < n; i ++)
		{
			scanf("%d",&arr[i]);
		}
		for(i = 0; i < n - 1; i ++)
		{
			for(int j = i + 1; j < n; j ++)
			{
				tt[ arr[i] + arr[j] ] ++;
			}
		}
		int cnt =0;
		for(i = 10000; i > 0; i --)
		{
				for(j = 0; j < tt[i] ; j ++)
				{	
					if(cnt == m)
						break;
					cnt ++;
				
					if(cnt == 1)
						printf("%d", i);
					else
						printf(" %d", i);
				}
				if(cnt == m)
					break;
		}
		printf("\n");

	}

}

   

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值