第九周周末总结

  这几天还是看的资料吧,还有就是昨天的训练赛也充分证明了不到最后一刻决不放弃总会有收获的道理,昨天训练赛的第三题本来快到时间了没想写的,最后想了想还是写了,终于在结束前的几分钟a了。

  A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- string "13" and can be divided by 13. For example, 130 and 2613 are wqb-numbers, but 143 and 2639 are not. Your task is to calculate how many wqb-numbers from 1 to n for a given integer n.

Input
Process till EOF. In each line, there is one positive integer n(1 <= n <= 1000000000).
Output
Print each answer in a single line.
Sample Input
13
100
200
1000
Sample Output
1
1
2
2

这道题就是其中能被13整除而且有13的。

#include<iostream>
#include<string.h>
using namespace std;
int a[20][20][3][10],f[20];
int dfs(int p,int flag,int now,int ret,int limit)
{
int s=0;
if(p==-1)
    {
    if(flag!=1)
        return 0;
    else
        {
        if(now==0)
            return 1;
        else
            return 0;
        }
    }
if(!limit&&a[p][now][flag][ret]!=-1)
    return a[p][now][flag][ret];
int up=limit?f[p]:9;
for(int i=0;i<=up;i++)
    s+=dfs(p-1,(ret==1&&i==3)||flag,(now*10+i)%13,i,limit&&i==up);
return limit?s:a[p][now][flag][ret]=s;
}
int solve(int x)
{
int p=0;
while(x)
    {
    f[p++]=x%10;
    x/=10;
    }
return dfs(p-1,0,0,0,true);
}
int main()
{
int n;
while(cin>>n)
    {
    memset(a,-1,sizeof(a));
    cout<<solve(n)<<endl;
    }
return 0;
}

The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the time bomb. The number sequence of the time bomb counts from 1 to N. If the current number sequence includes the sub-sequence "49", the power of the blast would add one point.
Now the counter-terrorist knows the number N. They want to know the final points of the power. Can you help them?
Input
The first line of input consists of an integer T (1 <= T <= 10000), indicating the number of test cases. For each test case, there will be an integer N (1 <= N <= 2^63-1) as the description.

The input terminates by end of file marker.
Output
For each test case, output an integer indicating the final points of the power.
Sample Input
3
1
50
500
Sample Output
0
1
15

该题为其中有49的


#include<iostream>
using namespacestd;
int a[22];
int dp[22][3];
void init(){
int i;
dp[0][0]=1,dp[0][1]=0,dp[0][2]=0;
for(i=1;i<=21;i++)
    {
    dp[i][0]=dp[i-1][0]*10-dp[i-1][1];
    dp[i][1]=dp[i-1][0];
    dp[i][2]=dp[i-1][2]*10+dp[i-1][1];
    }
}
long long solve(longlong x){
long long s=0;
int p=0;
while(x) { a[++p]=x%10;
    x/=10;
    }
a[p+1]=0;
bool flag=0;
for(int i=p;i>=1;i--)
    {
    s+=dp[i-1][2]*a[i];
    if(!flag)
        {
        if(a[i]>4)
        s+=dp[i-1][1];
        }
    else
        s+=dp[i-1][0]*a[i];
    if(a[i+1]==4&&a[i]==9)
        flag=1;
    }
if(flag)
    s++;
return s;
}
int main(){
long long n;
int t;
init();
cin>>t;
while(t--)
    {
    cin>>n;
    cout<<solve(n)<<endl;
    }
return 0;
}

下面是昨天训练赛的三道题,

第一题意思是给你一些数,如果能分成两份相等的数字,那么就输出Yes以及这两份的数字,第一遍读错题意了,我还以为是可以好多种数字,结果只能有两个数字。

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int a[105],b[105];
int i,n,x,flag;
int xx,yy;
while(cin>>n)
    {
    flag=0;
    memset(a,0,sizeof(a));
    for(i=0;i<n;i++)
        {
        cin>>x;
        if(a[x]==0)
            {
            flag++;
            a[x]++;
            if(flag==1)
                xx=x;
            else
                yy=x;
            }
        else
            a[x]++;
        }
    if(flag==2&&a[xx]==a[yy])
        {
        cout<<"Yes"<<endl;
        cout<<xx<<" "<<yy<<endl;
        }
    else
        cout<<"No"<<endl;
    }
}

第二题是找连续的小写字母字符串最多有多少种小写字母。

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
int n,maxx=0;
int b[30];
int i,k;
string a;
while(cin>>n)
    {
    cin>>a;
    k=0;
    maxx=0;
    memset(b,0,sizeof(b));
    for(i=0;i<n;i++)
        {
        if(a[i]>='a'&&a[i]<='z')
            {
            if(b[(int)(a[i]-'a')]==0)
                {
                k++;
                b[(int)(a[i]-'a')]++;
                if(k>maxx)
                    maxx=k;
                }
            else
                continue;
            }
        else
            {
            memset(b,0,sizeof(b));
            k=0;
            }
        }
    cout<<maxx<<endl;
    }
return 0;
}

第三题意思是汽车在坐标0与a之间来回行驶,从0到a与从a到0都算一趟,汽车油箱最大容量为b,加油站在f点,问你行驶k次最少需要加多少次油,不能完成就输出-1,否则输出最小加油次数,这个题考虑了好多情况啊。

#include<iostream>
using namespace std;
int main()
{
int a,b,f,k;
int kk;
int fx,now,bb;
int t;
int flag;
while(cin>>a>>b>>f>>k)
    {
    flag=1;
    t=0;
    kk=0;
    fx=1;
    bb=b-f;
    now=f;
    if(k==0)
        {
        cout<<0<<endl;
        continue;
        }
    if(f>b||(a-f)>b)
        {
        cout<<-1<<endl;
        continue;
        }
    while(1)
        {
        if(fx==1)
            {
            if(t==k-1&&bb>=a-f)
                break;
            if(t==k-1&&bb<a-f)
                {
                kk++;
                break;
                }
            if(bb<2*(a-f)&&t!=k-1)
                {
                if(b<2*(a-f))
                    {
                    flag=0;
                    break;
                    }
                bb=b-2*(a-f);
                kk++;
                t++;
                fx=-1;
                continue;
                }
            if(bb>=2*(a-f)&&t!=k-1)
                {
                bb-=2*(a-f);
                t++;
                fx=-1;
                continue;
                }
            }
        else
            {
            if(t==k-1&&bb>=f)
                break;
            if(t==k-1&&bb<f)
                {
                kk++;
                break;
                }
            if(bb<2*f&&t!=k-1)
                {
                if(b<2*f)
                    {
                    flag=0;
                    break;
                    }
                bb=b-2*f;
                kk++;
                t++;
                fx=1;
                continue;
                }
            if(bb>=2*f&&t!=k-1)
                {
                bb-=2*f;
                t++;
                fx=1;
                continue;
                }
            }
        }
    if(flag==0)
        cout<<-1<<endl;
    else
        cout<<kk<<endl;
    }
return 0;
}




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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值