题解

210 条题解

  • 0
    @ 2014-08-06 10:33:03

    水题…………

    记录信息
    评测状态 Accepted
    题目 P1848 记数问题
    递交时间 2014-08-06 10:32:26
    代码语言 C++
    评测机 VijosEx
    消耗时间 1135 ms
    消耗内存 272 KiB
    评测时间 2014-08-06 10:32:32
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 272 KiB, score = 10
    测试数据 #2: Accepted, time = 202 ms, mem = 268 KiB, score = 10
    测试数据 #3: Accepted, time = 15 ms, mem = 272 KiB, score = 10
    测试数据 #4: Accepted, time = 234 ms, mem = 268 KiB, score = 10
    测试数据 #5: Accepted, time = 124 ms, mem = 272 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 268 KiB, score = 10
    测试数据 #7: Accepted, time = 124 ms, mem = 272 KiB, score = 10
    测试数据 #8: Accepted, time = 218 ms, mem = 272 KiB, score = 10
    测试数据 #9: Accepted, time = 218 ms, mem = 268 KiB, score = 10
    Accepted, time = 1135 ms, mem = 272 KiB, score = 100

  • 0
    @ 2014-07-20 10:39:05

    #include<cstdio>
    #define IOFileName "P1848"
    int n,m,x,y,ans=0;
    int main(){
    //freopen(IOFileName".in","r",stdin);
    //freopen(IOFileName".out","w",stdout);
    scanf("%d %d\n",&n,&m);
    for(int i=1;i<=n;i++){
    x=i;
    while(x!=0){
    y=x%10;
    x/=10;
    if(y==m){
    ans++;
    }
    }
    }
    printf("%d\n",ans);
    }

  • 0
    @ 2014-07-05 23:30:28

    #include <iostream>
    using namespace std;
    int x,r,l,k,ans;
    int main(){
    cin>>r>>x;
    for(l=1;l<=r;l++)
    {
    k=l;
    while(k!=0){if(k%10==x)ans++;k/=10;}
    }
    cout<<ans;
    return 0;
    }

  • 0
    @ 2014-07-03 14:12:50

    program _1848jishu2;
    label 00,01;
    var a:integer;
    ifactor,count,n,low,curr,high:int64;
    begin
    read(n,a);
    ifactor:=1;
    if a<>0 then
    begin
    while(n div ifactor<>0) do
    begin
    low:=n-(n div ifactor)*ifactor;
    curr:=(n div ifactor)mod 10;
    high:=n div(ifactor*10);
    if curr<=a then
    if curr<a then begin inc(count,high*ifactor);goto 00;end
    else begin inc(count,high*ifactor+low+1);goto 00;end
    else begin inc(count,(high+1)*ifactor);goto 00;end;
    00:ifactor:=ifactor*10;
    end;
    end
    else
    begin
    ifactor:=10;
    count:=n div 10;
    while (n div ifactor<>0) do
    begin
    low:=n-(n div ifactor)*ifactor;
    curr:=(n div ifactor)mod 10;
    high:=n div(ifactor*10);
    if high=0 then break;
    if curr=0 then begin inc(count,(high-1)*ifactor+low+1);goto 01;end
    else begin inc(count,high*ifactor);goto 01;end;
    01:ifactor:=ifactor*10;
    end;
    end;
    writeln(count);
    readln;
    end.
    这才是数学方法= =

  • 0
    @ 2014-06-24 23:47:22

    数学方法,瞬间全过!!!!
    试一试一瞬间刷爆int64没问题!!!!

    function p(x,y:longint):int64;begin p:=round(exp(y*ln(x))) end;
    var a:array[0..11]of int64; i,j,k,l:longint; s:string;
    begin
    readln(a[10],a[11]);
    str(a[10],s);
    for i:=1to ord(s[0])do
    begin
    for j:=1to ord(s[0])-i do
    begin
    for k:=0to 9do
    a[k]:=a[k]+(ord(s[i])-ord('0'))*p(10,ord(s[0])-i-1);
    end;

    for j:=1to ord(s[i])-ord('0')-1do
    a[j]:=a[j]+p(10,ord(s[0])-i);

    a[ord(s[i])-ord('0')]:=
    a[ord(s[i])-ord('0')]+a[10]mod p(10,ord(s[0])-i)+1
    end;
    for i:=1to ord(s[i])do if s[i]='0'then a[0]:=a[0]-p(10,ord(s[0])-i);
    writeln(a[a[11]]);
    end.

  • 0
    @ 2014-05-31 15:11:22

    var s,n,x,i:longint;

    procedure jishu(a:longint);
    var b:longint;
    begin
    while a<>0 do
    begin
    b:=a mod 10;
    if b=x then s:=s+1;
    a:=a div 10;
    end;
    end;

    begin
    s:=0;
    read(n);
    read(x);
    for i:=1 to n do
    jishu(i);
    writeln(s);
    end.

  • 0
    @ 2014-01-01 12:03:03

    Vijos 题解:http://hi.baidu.com/umule/item/2c997f8ed9600fdae596e017
    有疑问请留言 共同进步

  • 0
    @ 2013-12-08 14:21:24

    代码:

    var
    a,x,j,i,total:longint;
    s:string;
    begin
    readln(a,x);
    for i:=1 to a do
    begin
    str(i,s);
    for j:=1 to length(s) do
    if s[j]=chr(ord('0')+x) then inc(total);
    end;
    write(total);
    end.

  • 0
    @ 2013-12-07 22:45:54

    #include <stdio.h>
    int main()
    {
    int n,x,a,b=0,c;
    scanf ("%d%d",&n,&x);

    for (c=1;c<=n;c++)
    {

    a=c;
    while (a)
    {
    if (a%10==x)
    b++;
    a/=10;
    }
    }
    printf ("%d",b);
    return 0;
    }

  • 0
    @ 2013-11-29 13:55:43

    var n,m,i,j,x:longint;
    s,c:string;
    begin
    assign(input,'count.in');
    reset(input);
    read(n);
    read(x);
    close(input);
    m:=0;
    for i:=1 to n do
    begin
    str(i,s);
    str(x,c);
    if pos(c,s)=0 then
    continue;
    for j:=1 to length(s) do
    if s[j]=c then
    inc(m);
    end;
    assign(output,'count.out');
    rewrite(output);
    write(m);
    close(output);
    end.

  • 0
    @ 2013-11-24 18:41:54

    include <cstdio>

    using namespace std;
    int main()
    {
    int n,k,ans=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
    for(int j=i;j>0;j/=10)
    if(j%10==k)ans++;
    }
    printf("%d",ans);
    return 0;
    }
    新学C+=的

  • 0
    @ 2013-11-24 16:35:23

    为什么错????

    var
    n,i,t,sum:longint;
    x:integer;
    s,s1:string;
    begin
    read(n,x);
    for i:=1 to n do
    begin
    str(i,s1);
    s:=s+s1;
    end;
    for i:=1 to length(s) do
    begin
    val(s[i],t);
    if t=x then sum:=sum+1;
    end;
    write(sum);
    end.

    • @ 2013-11-29 13:56:00

      var n,m,i,j,x:longint;
      s,c:string;
      begin
      assign(input,'count.in');
      reset(input);
      read(n);
      read(x);
      close(input);
      m:=0;
      for i:=1 to n do
      begin
      str(i,s);
      str(x,c);
      if pos(c,s)=0 then
      continue;
      for j:=1 to length(s) do
      if s[j]=c then
      inc(m);
      end;
      assign(output,'count.out');
      rewrite(output);
      write(m);
      close(output);
      end.

  • 0
    @ 2013-11-23 20:02:16

    a[i]=a[i/10]+1 (i mod 10=x)
    a[i]=ai/10
    递推累加即可

    • @ 2014-03-08 16:23:44

      用不着,又不是10^100000;

  • 0
    @ 2013-11-21 13:52:49

    var
    n,x,j,ans:longint;
    s,z:string;
    begin
    readln(n,x);
    str(x,z);
    for j:=1 to n do
    begin
    str(j,s);
    while pos(z,s)<>0 do
    begin
    ans:=ans+1;
    s[pos(z,s)]:=' ';
    end;
    end;
    writeln(ans);
    end.

  • 0
    @ 2013-11-20 12:57:06

    #include<cstdio>
    using namespace std;
    int main()
    {
    freopen("count.in","r",stdin);
    freopen("count.out","w",stdout);
    int ans=0,n,k,sb;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){int j=i;
    while(j>0){sb=j%10;if(sb==k)ans++;j/=10;}
    }printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2013-11-20 10:45:18

    #include<iostream>
    #include<string.h>
    using namespace std;
    int main(){
    int i,j,k,n,m;
    cin>>n>>m;
    for(i=1,k=0;i<=n;i++){
    j=i;
    while (j>0){
    if(j%10==m)k++;
    j/=10;
    }
    }
    cout<<k<<"\n";

    return 0;
    }
    直接AC

  • 0
    @ 2013-11-19 18:00:24

    用比赛的源程序,忘删文抄了

  • 0
    @ 2013-11-18 21:20:55

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    int n,x,a,ans=0;
    scanf("%d%d",&n,&x);
    for(int i=1;i<=n;i++){
    int j=1,a=i;
    while(a!=0){
    if(a%10==x) ans++;
    a/=10;
    }
    }
    printf("%d",ans);
    return 0;
    }

  • -1
    @ 2020-05-28 19:17:36

    #include<cstdio>
    using namespace std;
    int n, x, ans = 0;
    int main() {
    scanf("%d %d", &n, &x);
    for(int i = 1; i <= n; i++) {
    int k = i;
    while(k) {
    if(k % 10 == x) ans++;
    k /= 10;
    }
    }
    printf("%d\n", ans);
    }

  • -1

    #include<iostream>
    using namespace std;
    int main()
    {
    int k,a,j=0;
    cin>>k>>a;
    for(int i=1;i<=k;i++)
    {
    int t=i;
    while(t>=10)
    {
    if(t%10==a) j++;
    t=t/10;
    }
    if(t==a) j++;
    }
    cout<<j;
    return 0;
    }

信息

ID
1848
难度
5
分类
(无)
标签
递交数
16399
已通过
5732
通过率
35%
被复制
33
上传者