2015年NEUACM一月月赛

181 篇文章 0 订阅
112 篇文章 0 订阅


问题 J: Eliminate zero AC

时间限制: 1 Sec  内存限制: 128 MB
提交: 332  解决: 131
[ 提交][ 状态][ 讨论版]

题目描述

Last night,Kid submitted a problem for many times but he got many WA,so he is sad.Out of sympathy, his coach gave him a very simple problem so that Kid can solve it quickly. The problem is to select as many numbers as possible range 1 to n so that among these selected number there are no number can be divided exactly by other number. Can you solve it as quick as Kid?

 

输入

There are multiple cases.

For each case, there is a integer n(1<=n<=10^9)

 

输出

For each case,just output the answer.(the most numbers you can select)

 

样例输入

5

样例输出

3

提示

 

You can select {2,3,5} or {3,4,5}... but you can’t select {2,3,4,5} because 2|4.


So the answer is 3.

 

 

 

思路:这题由规律。。。n为奇数是最长是n/2+1,偶数时n/2。。。因为为偶数时他前面一半的都可以整除后面的,而奇数需要把他自己也加上去所以要+1.

 

 

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
#ifdef CDZSC_OFFLINE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    int n,i,j;
    while(scanf("%d",&n)!=EOF)
    {
        if(n%2!=0)
        {
            printf("%d\n",n/2+1);
        }
        else
        {
            printf("%d\n",n/2);
        }
    }
    return 0;
}


问题 C: Sum?Sum!

时间限制: 1 Sec  内存限制: 128 MB
提交: 653  解决: 176
[ 提交][ 状态][ 讨论版]

题目描述

Kid want to learn math better.Now Kid know how to calculate the sum of 1 to n in a short time.But this time,he is given a much more difficult question——to calculate the sum of 1 to 10^n.Kid think for a long time——10^10 ms and then he solve the question successfully.

Do you know how to solve it ?

 

输入

The first line is a integer t(1<=t<=10),indicate the number of case.

For each t,there is a integer n(the meaning of n is in the above),0<=n<=10^4.

 

输出

For each case,just print the answer of the sum.

 

样例输入

1
1

样例输出

55

提示

 

 

 

 

思路:其实这是由规律的n=1的时候是55,n=2的时候5050,n=3  500500,n=4   50005000。。。。一直下去

PS注意n=0事为1


#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int t,n,i;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        if(n==0)
        {
            printf("1\n");
            continue;
        }
        printf("5");
        for(i=0; i<n-1; i++)
        {
            printf("0");
        }
        printf("5");
        for(i=0; i<n-1; i++)
        {
            printf("0");
        }
        printf("\n");
    }
    return 0;
}


问题 B: a Simple Problem

时间限制: 1 Sec  内存限制: 128 MB
提交: 412  解决: 99
[ 提交][ 状态][ 讨论版]

题目描述

Many people think hh is a diaosi, but hh is a very rich man whose nickname is wenzhoutuhao,and he made a lot of money by buying the stock of neusoft. He bought n diamonds.One day he found that his warehouse is too small to accommodate these diamonds. so he decide to transfer c of the diamonds to another warehouse.He made the n diamonds into a row, with a number written on their positions, the number is the value of the diamond,the unit is billion(oh no so rich man),then,hh tells you to choose c diamonds,which will be sent to other warehouse,he also imposed two conditions.They are:

  1.the chosen c diamonds must be formed a contiguous

segment

  2.any of the chosen diamond’s value should not be greater than t,because he thought you may be would steal them.Find the number of ways you can choose the c diamonds.

 

 

 

输入

50 group tests,the first line of input will contain three space separated integer n(1<=n<=10^5),t(0<=t<=10^9) and c(1<=c<=n)

the next line will contain n space separated integer,the ith integer is the value of ith diamond,the value will be non-negative and will not be exceed 10^9

 

输出

print a single integer——the number of ways you can choose the c diamonds

 

样例输入

4 3 3
2 3 1 1
1 1 1
2

样例输出

2
0

提示

 

题意: 给出n 个数字,求出存在多少个组连续的t个数字,满足这t个数字每个数字的值都小于c.

Solution :

注意下是保证单个数字的值小于c即可,只需要从前向后模拟下,扫描到val>c 时将扫描长度清零即可。


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
#ifdef CDZSC_OFFLINE
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif
    int n,t,c,i,a[100050],p;
    while(scanf("%d%d%d",&n,&t,&c)!=EOF)
    {
        memset(a,0,sizeof(a));
        int sum=0,k=1;
        for(i=1; i<=n; i++)
        {
            scanf("%d",&p);
            if(p>t)
            {
                a[k++]=i;
            }
        }
        a[k++]=n+1;
        if(k-2==0)
        {
            printf("%d\n",n-c+1);
        }
        else if(k-2==n)
        {
            printf("0\n");
        }
        else
        {
            for(i=1; i<k; i++)
            {
                if(a[i]-a[i-1]-1>=c)
                {
                    sum+=(a[i]-a[i-1]-1-c+1);
                }
            }
            printf("%d\n",sum);
        }
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值