题解

187 条题解

  • 0
    @ 2015-08-03 16:42:31

    program e1201;
    var n,m,k,l,x,y:int64;
    i,j:longint;
    a,b,c,f:array[0..100]of int64;
    begin
    readln(n);
    k:=0;
    for i:=1 to 16 do
    begin
    a[i]:=n and 1;
    n:=n shr 1;
    end;
    for i:=1 to 16 do
    begin
    b[i]:=n and 1;
    n:=n shr 1;
    end;
    for i:=16 downto 1 do
    begin
    inc(k);
    c[k]:=a[i];
    end;
    for i:=16 downto 1 do
    begin
    inc(k);
    c[k]:=b[i];
    end;
    for i:=1 to k do
    if c[i]=1 then begin
    inc(l);
    f[l]:=32-i;
    end;
    for i:=1 to l do
    begin
    y:=1;
    for j:=1 to f[i] do
    y:=y*2;
    x:=x+y;
    end;
    writeln(x);
    end.

  • 0
    @ 2015-07-31 20:15:49

    ###上面的抄我程序干嘛
    测试数据 #0: Accepted, time = 0 ms, mem = 532 KiB, score = 10
    测试数据 #1: Accepted, time = 11 ms, mem = 532 KiB, score = 10
    测试数据 #2: Accepted, time = 15 ms, mem = 532 KiB, score = 10
    测试数据 #3: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #4: Accepted, time = 0 ms, mem = 524 KiB, score = 10
    测试数据 #5: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    测试数据 #6: Accepted, time = 1 ms, mem = 528 KiB, score = 10
    测试数据 #7: Accepted, time = 15 ms, mem = 528 KiB, score = 10
    测试数据 #8: Accepted, time = 15 ms, mem = 528 KiB, score = 10
    测试数据 #9: Accepted, time = 0 ms, mem = 528 KiB, score = 10
    Accepted, time = 57 ms, mem = 532 KiB, score = 100
    #include <iostream>
    #include <stdio.h>
    using namespace std;
    int num2[33];
    int num_2[33];
    int main()
    {
    int n;
    scanf("%d",&n);
    for(int i=1;;i++)
    {
    if(n==0)break;
    if(n%2==1)
    num2[i]=1;
    n/=2;
    }
    for(int i=1;i<=16;i++)
    {
    num_2[i]=num2[i+16];
    num_2[i+16]=num2[i];
    }
    long long ans=0;
    long long n_2=1;
    for(int i=1;i<=32;i++)
    {
    if(num_2[i])ans+=n_2;
    n_2*=2;
    }
    printf("%lld",ans);
    }

  • 0
    @ 2015-02-24 18:12:08

    var
    s,q:qword;
    a:array[1..32] of longint;
    i:longint;
    begin
    read(s);
    i:=32;
    while s<>0 do
    begin
    a[i]:=s mod 2;
    s:=s div 2;
    i:=i-1;
    end;
    q:=1;
    for i:=16 downto 1 do
    begin
    s:=s+a[i]*q;
    q:=q*2;
    end;
    for i:=32 downto 17 do
    begin
    s:=s+a[i]*q;
    q:=q*2;
    end;
    write(s);
    end.

  • 0
    @ 2015-02-08 12:17:48

    swap函数可以直接用。

    Pascal Code

    var
    s:longword;
    begin
    readln(s);
    writeln(swap(s));
    end.

  • 0
    @ 2014-12-14 17:42:11

    #include <iostream>
    using namespace std;
    int main()
    {
    unsigned int n=0;
    cin>>n;
    cout<<(n>>16)+(n<<16)<<endl;
    return 0;
    }

    • @ 2014-12-30 14:08:58

      学习了!跪跪跪神牛!Orz!祝RP++!

  • 0
    @ 2014-11-05 02:07:47

    P1201高低位交换
    Accepted

    记录信息

    评测状态 Accepted
    题目 P1201 高低位交换
    递交时间 2014-11-05 02:06:49
    代码语言 C++
    评测机 上海红茶馆
    消耗时间 7 ms
    消耗内存 540 KiB
    评测时间 2014-11-05 02:06:50

    评测结果

    编译成功

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

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

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

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

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

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

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

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

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

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

    Accepted, time = 0 ms, mem = 540 KiB, score = 100

    代码

    #include <stdio.h>

    unsigned int n;

    int main()
    {
    scanf( "%u" , &n );
    printf( "%u\n" , n >> 16 | n << 16 );
    return 0;
    }

    左右位移。。。

  • 0
    @ 2014-04-27 02:50:41

    #include <cstdio>
    int main(void){
    unsigned long x;
    scanf("%lu\n",&x);
    unsigned long y=x>>16|x<<16;
    printf("%lu\n",y);
    }
    70分的是因为最前面一位被当成了符号位,输出时有负数。把%ld换成%lu就可以了

  • 0
    @ 2013-11-01 06:56:39

    此题神水啊!
    var
    x:qword;
    begin
    readln(x);
    writeln(x mod (1<<16)*(1<<16)+x>>16);
    end.

  • 0
    @ 2013-10-30 15:21:03

    var i,j,k,l,m,n:Longint;
    NN,Ans:Int64;
    S:string;
    Begin
    Readln(NN);
    For i:=1 to 32 do
    Begin
    S:=chr(NN mod 2+48)+S;
    NN:=NN div 2;
    End;
    S:=Copy(S,17,16)+Copy(S,1,16);
    For i:=1 to 32 do Ans:=Ans*2+ord(S[i])-48;
    Writeln(Ans);
    End.

  • 0
    @ 2013-09-28 12:58:13

    我累个擦,longint改成longword就过,没天理

  • 0
    @ 2012-11-06 12:45:06

    我爱老夏!!老夏爱XX!!!>.

  • 0
    @ 2012-08-21 09:29:31

    记得 int64

  • 0
    @ 2012-08-10 15:00:29

    坑爹啊~pascal竟然还有swap函数

  • 0
    @ 2012-08-02 15:48:37

    点击查看代码[/red]

  • 0
    @ 2009-11-13 17:19:30

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-11-09 22:24:54

    强势位运算~!

    Flag   Accepted

    题号   P1201

    类型(?)   数论 / 数值

    通过   3946人

    提交   7269次

    通过率   54%

    难度   1

    #include

    #include

    int main()

    {

    long long n,m;

    long long x=0,y=0;

    scanf("%I64d",&n);

    x=n>>16;

    y=n-((n>>16)

  • 0
    @ 2009-11-08 09:36:56

    个人觉得还是这个比较简洁

    var a:dword;

    begin

    read(a);

    a:=a shr 16+a shl 16;

    write(a);

    end.

    貌似还有很多办法,位运算应该最优了。

  • 0
    @ 2009-11-01 06:37:13

    第30个AC...小小小小庆祝

  • 0
    @ 2009-10-30 20:27:03

    现在终于知道还有类型是

    dword longword

    还有函数是

    swap

  • 0
    @ 2009-10-28 16:03:34

    Orz……膜拜Einst、摁死他、爱因斯坦、lr、你是大傻你半秃你还喜欢XXX的旱地~神牛。

信息

ID
1201
难度
3
分类
模拟 点击显示
标签
(无)
递交数
3699
已通过
1824
通过率
49%
被复制
13
上传者