【2017河南省省赛个人选拔赛补题】hdu4722 Good Numbers9(找规律)+CodeForces 729D(思路题)

Good Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4714    Accepted Submission(s): 1499


Problem Description
If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number.
You are required to count the number of good numbers in the range from A to B, inclusive.
 

Input
The first line has a number T (T <= 10000) , indicating the number of test cases.
Each test case comes with a single line with two numbers A and B (0 <= A <= B <= 10 18).
 

Output
For test case X, output "Case #X: " first, then output the number of good numbers in a single line.
 

Sample Input
 
   
2 1 10 1 20
 

Sample Output
 
   
Case #1: 0 Case #2: 1
Hint
The answer maybe very large, we recommend you to use long long instead of int.

求A到B之间各位数之和能被10整除的数的个数

打表可以看出来每十个数之间必有一个这样的数,n/10得到前面的个数,在加上n/10*10~n中有没有满足的 ,如 128,120-128之间127满足,即12+1个

code:

#include
typedef long long LL;
LL solve(LL n)
{
    LL p=n/10;
    LL sum=0;
    for(LL i=p*10; i<=n; i++)
    {
        LL s=i;
        sum=0;
        while(s)
        {
            sum+=s%10;
            s/=10;
        }
        if(sum%10==0)
            return p+1;
    }
    return p;
}
int main()
{
    int T,t=0;
    scanf("%d",&T);
    while(T--)
    {
        LL a,b,ans;
        scanf("%lld%lld",&a,&b);
        ans=solve(b)-solve(a-1);
        printf("Case #%d: ",++t);
        printf("%lld\n",ans);

    }
}


D. Sea Battle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of bconsecutive cells. No cell can be part of two ships, however, the ships can touch each other.

Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").

Galya has already made k shots, all of them were misses.

Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.

It is guaranteed that there is at least one valid ships placement.

Input

The first line contains four positive integers nabk (1 ≤ n ≤ 2·1051 ≤ a, b ≤ n0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made.

The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.

Output

In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.

In the second line print the cells Galya should shoot at.

Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left.

If there are multiple answers, you can print any of them.

Examples
input
5 1 2 1
00100
output
2
4 2
input
13 3 2 3
1000000010001
output
2
7 11
Note

There is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.


题意:长度为n的0,1字符串表示n个位置,共有a个长度为b的轮船,1 表示已经射击k次但并没有射击到船的位置,求至少还要射击几次才能射击到至少一艘轮船

思路:找出0位置可以有轮船的所有位置,假设有x个位置可能有轮船,射击x-(a-1)次,必定射击中一艘轮船

code:

#include
using namespace std;
int pos[200005];
int main()
{
    char s[200005];
    int n,a,b,k;
    scanf("%d%d%d%d",&n,&a,&b,&k);
    scanf("%s",s+1);
    int sum=0,l=0;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='1')
        {
            sum=0;
        }
        else
        {
            sum++;
            if(sum%b==0)
            {
                pos[l++]=i;
            }
        }
    }
    int ans=l-(a-1);
    printf("%d\n",ans);
    for(int i=0;i


你可能感兴趣的:(赛后补题,codeforces,====数论,数学问题====)