题解

216 条题解

  • 0
    @ 2016-01-24 11:42:07

    program p1848;
    var s:string;
    题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题
    题题题题题题题题题题题题题题题题题题题题题题题题题题题题水水水水题题题题题
    题题题题题题题题题题题题题题题题题题题题题题题题水水水水水水水水水题题题题
    题题题题题题题题题题题题题题题题题题水水水水水水水水水水水水水水水题题题题
    题题题题题题题题题题题题题题题题水水水水水水水水水水水水水水水题题题题题题
    题题题题题题题题题题题水水水水题水水水水水水水水水水水题题题题题题题题题题
    题题题题题题题题水水水水水水水题水水水题题水水水水水题题题题题题题题题题题
    题题题水水水水水水水水水水水水题题题题题题水水水水题题题题题题题题题题题题
    题水水水水水水水水水水水水水水题题题题题题水水水水题题题题题题题题题题题题
    题水水水水水水水水水水水水题题题题题题题水水水水水水水水水水水题题题题题题
    题水水水水水水水水水水水水题题题题题题水水水水水水水水水水水水水水题题题题
    题题水水水水水水水水水水题题题题题水水水水水水题题题水水水水水水水题题题题
    题题题题题题题题水水水水题题题题题水水水水题题题题题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水题题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水水水题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水水水题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题题水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水水题水水水水题题水水水水水题题题题题
    题题题题题题题题水水水水题题题题水水水题题水水水水题题水水水水水题题题题题
    题题水水题题题水水水水水题题题题水水水题题水水水题题题水水水水水题题题题题
    题题水水水水水水水水水水题题题题题水水题题水水题题题题水水水水水题题题题题
    题题题水水水水水水水水水题题题题题题题题水水水题题题题水水水水题题题题题题
    题题题题题水水水水水水水题题题题题题题题水水水题水水水水题题题题题题题题题
    题题题题题题水水水水水水题题题题题题题水水水水题题水水水水题题题题题题题题
    题题题题题题题题题水水水题题题题题题水水水水水题题题水水水水水水水题题题题
    题题题题题题题题题题题题题题题题水水水水水水题题题题题水水水水水水题题题题
    题题题题题题题题题题题题题题题水水水水水水题题题题题题水水水水水水水题题题
    题题题题题题题题题题题题题题水水水水水题题题题题题题题题水水水水水水题题题
    题题题题题题题题题题题题题水水水水水题题题题题题题题题题题水水水水题题题题
    题题题题题题题题题题题题水水水题题题题题题题题题题题题题题题水水水题题题题
    题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题题
    c:char;

    n:longint;
    t: int64;
    a,i,j:longint;
    begin
    readln(n,a);
    str(a,s);
    c:=s[1];t:=0;

    for i:=1 to n do

    begin

    str(i,s);

    for j:=1 to length(s) do
    if s[j]=c then t:=t+1;
    end;
    writeln(t);
    end.

  • 0
    @ 2015-12-13 15:36:45

    编译成功

    Free Pascal Compiler version 2.6.2 [2013/02/12] for i386
    Copyright (c) 1993-2012 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    Linking foo.exe
    14 lines compiled, 0.1 sec , 28032 bytes code, 1628 bytes data

    测试数据 #0: Accepted, time = 15 ms, mem = 4528 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 4528 KiB, score = 10

    测试数据 #2: Accepted, time = 46 ms, mem = 4528 KiB, score = 10

    测试数据 #3: Accepted, time = 0 ms, mem = 4528 KiB, score = 10

    测试数据 #4: Accepted, time = 62 ms, mem = 4528 KiB, score = 10

    测试数据 #5: Accepted, time = 31 ms, mem = 4528 KiB, score = 10

    测试数据 #6: Accepted, time = 0 ms, mem = 4528 KiB, score = 10

    测试数据 #7: Accepted, time = 46 ms, mem = 4528 KiB, score = 10

    测试数据 #8: Accepted, time = 78 ms, mem = 4528 KiB, score = 10

    测试数据 #9: Accepted, time = 109 ms, mem = 4528 KiB, score = 10

    Accepted, time = 387 ms, mem = 4528 KiB, score = 100

    代码
    var j,i,n,x:longint;
    a:array[1..1000000]of longint;
    begin
    readln(n,x);
    j:=0;
    for i:=1 to n do a[i]:=i;
    for i:= 1 to n do if a[i]=x then j:=j+1
    else while a[i]<>0 do
    begin
    if a[i] mod 10=x then j:=j+1;
    a[i]:=a[i] div 10;
    end;
    writeln(j);
    end.

  • 0
    @ 2015-12-09 15:57:10

    var
    a,b,c,x,y,z,i,l,j:longint;
    begin
    readln(a,b);
    for i:=1 to a do
    begin
    z:=i;
    repeat
    x:=z mod 10 ;
    y:=z div 10 ;
    if x=b then inc(l);
    z:=y;
    until y=0;
    end;
    writeln(l);
    end.

  • 0
    @ 2015-11-07 10:58:29

    测试数据 #0: Accepted, time = 0 ms, mem = 512 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 516 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 516 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 516 KiB, score = 10
    测试数据 #4: Accepted, time = 46 ms, mem = 516 KiB, score = 10
    测试数据 #5: Accepted, time = 15 ms, mem = 516 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 516 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 516 KiB, score = 10
    测试数据 #8: Accepted, time = 31 ms, mem = 516 KiB, score = 10
    测试数据 #9: Accepted, time = 46 ms, mem = 516 KiB, score = 10
    Accepted, time = 168 ms, mem = 516 KiB, score = 100
    代码
    #include<iostream>
    using namespace std;
    int main()
    {
    int i,n,ans=0,x,y,m;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
    x=i;//穷举每一个数
    while(x>0)//拆开
    {
    y=x%10;//取个位
    x=x/10;//砍个位
    if(y==m)//判断
    ans++;
    }
    }
    cout<<ans<<endl;
    return 0;
    }

  • 0
    @ 2015-10-28 18:28:38

    记录信息
    评测状态 Accepted
    题目 P1848 记数问题
    递交时间 2015-10-28 18:27:24
    代码语言 Pascal
    评测机 VijosEx
    消耗时间 203 ms
    消耗内存 776 KiB
    评测时间 2015-10-28 18:27:26
    评测结果
    编译成功

    Free Pascal Compiler version 2.6.4 [2014/03/06] for i386
    Copyright (c) 1993-2014 by Florian Klaempfl and others
    Target OS: Win32 for i386
    Compiling foo.pas
    foo.pas(11,26) Warning: Variable "l" does not seem to be initialized
    foo.pas(2,5) Note: Local variable "c" not used
    foo.pas(2,17) Note: Local variable "j" not used
    Linking foo.exe
    15 lines compiled, 0.1 sec , 28016 bytes code, 1628 bytes data
    1 warning(s) issued
    2 note(s) issued
    测试数据 #0: Accepted, time = 0 ms, mem = 772 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 772 KiB, score = 10
    测试数据 #2: Accepted, time = 46 ms, mem = 772 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 776 KiB, score = 10
    测试数据 #4: Accepted, time = 31 ms, mem = 772 KiB, score = 10
    测试数据 #5: Accepted, time = 31 ms, mem = 772 KiB, score = 10
    测试数据 #6: Accepted, time = 2 ms, mem = 772 KiB, score = 10
    测试数据 #7: Accepted, time = 31 ms, mem = 772 KiB, score = 10
    测试数据 #8: Accepted, time = 31 ms, mem = 772 KiB, score = 10
    测试数据 #9: Accepted, time = 31 ms, mem = 772 KiB, score = 10
    Accepted, time = 203 ms, mem = 776 KiB, score = 100
    代码
    var
    a,b,c,x,y,z,i,l,j:longint;
    begin
    readln(a,b);
    for i:=1 to a do
    begin
    z:=i;
    repeat
    x:=z mod 10 ;
    y:=z div 10 ;
    if x=b then inc(l);
    z:=y;
    until y=0;
    end;
    writeln(l);
    end.

  • 0
    @ 2015-10-22 17:58:27

    #include<iostream>
    using namespace std;
    int main()
    {
    int n,x,y,p=0;
    cin>>n>>x;
    int q[20];
    for(int a=0;a<n;a++)
    {
    q[a]=a+1;
    while(q[a]>=10)
    {
    y=q[a]%10;
    q[a]/=10;
    if(y==x)
    p++;
    }
    if(q[a]==x)
    p++;
    }
    cout<<p;
    }

  • 0
    @ 2015-08-05 19:40:01

    水一水,用sprintf即可。把数字打印到字符串里,然后for慢慢走。
    贴代码
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main()
    {
    int n,k,ans=0;
    scanf("%d%d",&n,&k);
    char st[510];
    for(int i=1;i<=n;i++)
    {
    sprintf(st,"%d",i);
    int a=strlen(st);
    for(int j=0;j<=a;j++)
    {
    if(st[j]-'0'==k)
    {
    ans++;
    }
    }
    }
    printf("%d\n",ans);
    return 0;
    }

  • 0
    @ 2015-06-09 14:14:31

    这题目用最简单的穷举即可 当年的初赛题 各位请注意务必用longint。过去用的integer在复赛悲催了,切记切记。
    program p1848;
    var
    num,i,x,temp,val,p:**longint**;
    begin
    read(num);
    read(x);
    for i:=1 to num do
    begin
    p:=i;
    while p<> 0 do
    begin
    val:=p mod 10;
    if val=x then temp:=temp+1;
    p:=p div 10;
    end;
    end;
    write(temp);
    end.

  • 0
    @ 2015-05-05 18:40:54

    草稿
    var
    n,x,j,k,time:longint;
    begin
    readln(n,x);
    for j:=1 to n do
    repeat
    k:=j mod 10;
    if k=x then pred(time);
    j:=j div 10;
    until j<=0;
    writeln(time);
    end

  • 0
    @ 2015-02-09 09:56:55

    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 448 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 448 KiB, score = 10

    测试数据 #2: Accepted, time = 31 ms, mem = 440 KiB, score = 10

    测试数据 #3: Accepted, time = 0 ms, mem = 444 KiB, score = 10

    测试数据 #4: Accepted, time = 46 ms, mem = 444 KiB, score = 10

    测试数据 #5: Accepted, time = 31 ms, mem = 448 KiB, score = 10

    测试数据 #6: Accepted, time = 0 ms, mem = 452 KiB, score = 10

    测试数据 #7: Accepted, time = 31 ms, mem = 452 KiB, score = 10

    测试数据 #8: Accepted, time = 46 ms, mem = 448 KiB, score = 10

    测试数据 #9: Accepted, time = 31 ms, mem = 448 KiB, score = 10

    Accepted, time = 216 ms, mem = 452 KiB, score = 100

    代码
    #include<stdio.h>
    #include<string.h>
    int main()
    {
    int i,n,tot=0,x,y,m;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
    x=i;
    while(x>0)
    {
    y=x%10;
    x/=10;
    if(y==m)
    tot++;
    }
    }
    printf("%d",tot);
    return 0;
    }

  • 0
    @ 2015-02-09 09:34:19

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    int i,n,tot=0,x,y,m;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
    {
    x=i;
    while(x>0)
    {
    y=x%10;
    x/=10;
    if(y==m)
    tot++;
    }
    }
    printf("%d",tot);
    return 0;
    }

  • 0
    @ 2015-02-06 15:09:35

    为什么用log10()和pow()函数不对呢?
    非得叫我自己实现。
    下面是一种递推的方法。速度奇快。
    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 472 KiB, score = 10
    测试数据 #1: Accepted, time = 0 ms, mem = 476 KiB, score = 10
    测试数据 #2: Accepted, time = 0 ms, mem = 476 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 476 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 480 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 472 KiB, score = 10
    测试数据 #6: Accepted, time = 0 ms, mem = 468 KiB, score = 10
    测试数据 #7: Accepted, time = 0 ms, mem = 472 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 476 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 472 KiB, score = 10
    Accepted, time = 15 ms, mem = 480 KiB, score = 100
    代码
    #include<iostream>
    #include<string.h>
    #include<math.h>
    #include<stdio.h>
    using namespace std;
    int power(int n, int p){
    int ans = 1;
    while (p--)ans *= n;
    return ans;
    }
    int lg(int n){
    int ans = 0;
    while (n){
    ans++; n /= 10;
    }
    return ans-1;
    }
    long long int f(int n, int x, int wei){//第一位0
    if (n == 0){
    if (x == 0)
    return wei + 1;
    else return 0;
    }
    int di = power(10, wei);
    int me = n / di;
    int next = n%di;
    if (me > x){
    return di + me*f(di - 1, x, wei - 1) + f(next, x, wei - 1);
    }
    else if (me < x){
    return me*f(di - 1, x, wei - 1) + f(next, x, wei - 1);
    }
    else {
    return (next + 1) + me*f(di - 1, x, wei - 1) + f(next, x, wei - 1);
    }
    }
    long long int ans(int n, int x){
    if (n == 0)return 0;
    int wei = lg(n);
    int di = power(10, wei);
    int me = n / di;
    int next = n%di;
    int ret;
    if (x == 0){
    ret = (me - 1)*f(di - 1, x, wei - 1) + f(next, x, wei - 1);
    }
    else if (me > x){
    ret = di + (me - 1)*f(di - 1, x, wei - 1) + f(next, x, wei - 1);
    }
    else if (me < x){
    ret = (me - 1)*f(di - 1, x, wei - 1) + f(next, x, wei - 1);
    }
    else {
    ret = (next + 1) + (me - 1)*f(di - 1, x, wei - 1) + f(next, x, wei - 1);
    }
    return ret + ans(di - 1, x);
    }
    int test(int n, int x){
    int i;
    int ans = 0;
    for (i = 1; i <= n; i++){
    int j = i;
    while (j){
    if (j % 10 == x)ans++;
    j /= 10;
    }
    }
    return ans;
    }
    void play(){
    int n, x;
    for (x = 0; x < 10; x++)
    for (n = 999990; n < 1000000; n++){
    cout << ans(n, x) << endl<<test(n, x) << endl;
    if (ans(n, x) != test(n, x)){
    cout << n << endl;
    return;
    }
    }
    cout << "haha" << endl;
    }
    int main(){
    int n, x=0;
    cin >> n >> x;
    cout << ans(n, x) << endl;
    return 0;
    }

  • 0
    @ 2015-02-06 14:23:56

    我原以为这么做会超时,可能是数据太少了。
    #include<iostream>
    using namespace std;
    int main(){
    int n, x;
    cin >> n >> x;
    int i;
    int ans = 0;
    for (i = 1; i <= n; i++){
    int temp = i;
    while (temp){
    if (temp % 10 == x)ans++;
    temp /= 10;
    }
    }
    cout << ans << endl;
    return 0;
    }

  • 0
    @ 2015-01-24 20:04:16

    水题一次全过
    var n,x,ans,i:longint;
    function num(k:longint):integer;
    var t:integer;
    begin
    num:=0;
    repeat
    t:=k mod 10;
    if t=x then inc(num);
    k:=k div 10;
    until k=0;
    end;
    begin
    readln(n,x);
    for i:=1 to n do
    inc(ans,num(i));
    writeln(ans);
    end.

  • 0
    @ 2014-11-06 10:53:50

    var
    n,x,sum,ans,i:longint;
    procedure try(p:longint);
    begin
    if p mod 10=x then
    inc(sum);
    if (p<>0)and(p div 10>0) then
    try(p div 10);
    end;
    begin
    readln(n,x);
    for i:=1 to n do
    begin
    sum:=0;
    try(i);
    ans:=ans+sum;
    end;
    writeln(ans);
    end.

    淳朴的搜索数据太弱>_<

  • 0
    @ 2014-11-03 13:15:22

    program count;
    var n,i,j,x:longint;
    a:array[0..9] of longint;
    begin
    readln(n,x);
    for i:=0 to 9 do a[i]:=0;
    for i:=1 to n do
    begin
    j:=i;
    while j<>0 do
    begin
    inc(a[j mod 10]);
    j:=j div 10;
    end;
    end;
    writeln(a[x]);
    end.

  • 0
    @ 2014-10-31 16:59:54

    var
    x:integer;
    i,jc,n:longint;
    c:array[1..1000000] of longint;
    begin
    readln(n,x);
    jc:=0;
    for i:=1 to n do c[i]:=i;
    for i:=1 to n do if c[i]=x then inc(jc)
    else while c[i]<>0 do
    begin
    if c[i] mod 10=x then inc(jc);
    c[i]:=c[i] div 10;
    end;
    writeln(jc);
    readln;
    end.

  • 0
    @ 2014-10-24 18:57:33

    var i,n,s,x,t,m:longint;
    begin
    read(n); read(x);
    for i:=1 to n do
    begin
    if i=x then t:=t+1 else
    begin
    s:=i;
    while s<>0 do
    begin
    m:=s mod 10;
    if m=x then inc(t);
    s:=s div 10;
    end;
    end;
    end;
    write(t);
    end.

  • 0
    @ 2014-10-07 14:48:29

    爆0约一周年纪念

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

    P1784改一下就行了…………

信息

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