Jack's Blog

流淌的心,怎能阻拦,吹来的风,又怎能阻挡。

C语言数据结构

1.前言

       这是属于计算机组成原理的东西,越感觉需要把C语言和数据结构学好,所以今天在次与大家分享有关C语言中的按位与(&)按位或(|)按位异或(^)取反(~)。


      由于这些运算符号都是基于二进制来说的,所以十进制的计算都需要转换成二进制。下面我们就来介绍一下二进制和十进制之间的转换:

     

2.1 二进制转十进制

1101(2)=1*2^0+0*2^1+1*2^2+1*2^3=1+0+4+8=13转化成十进制要从右到左用二进制的每个数去乘以2的相应次方
不过次方要从0开始

2.2 十进制转换二进制

十进制整数转二进制
如:255=(11111111)B
255/2=127=====余1
127/2=63======余1
63/2=31=======余1
31/2=15=======余1
15/2=7========余1
7/2=3=========余1
3/2=1=========余1
1/2=0=========余1

2.3运算操作

=== 1. and(&)运算 ===
and运算通常用于二进制取位操作,例如一个数 and 1的结果就是取二进制的最末位。这可以用来判断一个整数的奇偶,二进制的最末位为0表示该数为偶数,最末位为1表示该数为奇数.
相同位的两个数字都为1,则为1;若有一个不为1,则为0。

00111
11100
(&或者and)
----------------
00100


=== 2. or(|)运算 ===
or运算通常用于二进制特定位上的无条件赋值,例如一个数or 1的结果就是把二进制最末位强行变成1。如果需要把二进制最末位变成0,对这个数or 1之后再减一就可以了,其实际意义就是把这个数强行变成最接近的偶数。
相同位只要一个为1即为1。

00111
11100
(|或者or)
----------------
11111


=== 3. xor(^)运算 ===
异或的符号是⊕。
xor运算通常用于对二进制的特定一位进行取反操作,因为异或可以这样定义:0和1异或0都不变,异或1则取反。
xor运算的逆运算是它本身,也就是说两次异或同一个数最后结果不变,即(a xor b) xor b = a。xor运算可以用于简单的加密,比如我想对我MM说1314520,但怕别人知道,于是双方约定拿我的生日19880516作为密钥。1314520 xor 19880516 = 20665500,我就把20665500告诉MM。MM再次计算20665500 xor 19880516的值,得到1314520,于是她就明白了我的企图。
相同位不同则为1,相同则为0。


=== 4.~取反===
就是如果是00111,则变为11000

*****左移位运算符*****

 将一个数左移1位,相当于将该数乘以2;

左移2位相当于将该数乘以4,即左边数乘以2的右边数幂的积

 eg. 9<<3 的结果是:72 相当于9*2*2*2

 

*****右移位运算符*****(两边都是正数)

将一个数带符号右移1位,相当于将该数除以2(忽略余数);

带符号右移2位,相当于将该数除以4,即左边数除以2的右边数幂的商

 eg. 9>>1 的结果是:4 相当于9/2(忽略余数)

 

当左边的数字小于右边的数时,结果为0(两边都是正数)

 当左边的数小于0时,结果为:左边数的绝对值除以2的右边数幂的商的相反数-1

eg. -9>>2的结果是:-3 相当 于-(9/(2*2))-1

3 结语

以上是所有内容,希望对大家有所帮助。

ACM practice 1

1.

The Sarcophagus itself is locked by a secret numerical code. When somebody wants to open it, he must know the code and set it exactly on the top of the Sarcophagus. A very intricate mechanism then opens the cover. If an incorrect code is entered, the tickets inside would catch fire immediately and they would have been lost forever. The code (consisting of up to 100 integers) was hidden in the Alexandrian Library but unfortunately, as you probably know, the library burned down completely.

But an almost unknown archaeologist has obtained a copy of the code something during the 18th century. He was afraid that the code could get to the ``wrong people'' so he has encoded the numbers in a very special way. He took a random complex number B that was greater (in absolute value) than any of the encoded numbers. Then he counted the numbers as the digits of the system with basis B. That means the sequence of numbers an, an-1, ..., a1, a0 was encoded as the number X = a0 + a1B + a2B2 + ...+ anBn.

Your goal is to decrypt the secret code, i.e. to express a given number X in the number system to the base B. In other words, given the numbers X and Byou are to determine the ``digit'' a0 through an.

Input

The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case consists of one single line containing four integer numbers Xr, Xi, Br, Bi (|Xr|,|Xi| <= 1000000, |Br|,|Bi| <= 16). These numbers indicate the real and complex components of numbers X and B, i.e. X = Xr + i.Xi, B = Br + i.Bi. B is the basis of the system (|B| > 1), X is the number you have to express.

Output

Your program must output a single line for each test case. The line should contain the ``digits'' an, an-1, ..., a1, a0, separated by commas. The following conditions must be satisfied:

  • for all i in {0, 1, 2, ...n}: 0 <= ai < |B|
  • X = a0 + a1B + a2B2 + ...+ anBn
  • if n > 0 then an <> 0
  • n <= 100

If there are no numbers meeting these criteria, output the sentence "The code cannot be decrypted.. If there are more possibilities, print any of them.

Sample Input

4

-935 2475 -11 -15

1 0 -3 -2

93 16 3 2

191 -192 11 -12

Sample Output

8,11,18

1

The code cannot be decrypted.

16,15

 

最近刷题速度明显下降

所以感觉时间远远不够用了

因此我找到了一个bug。

但这种方法只限于解决静态题目。

就是结果一成不变的题目。

比如说下面这个题目

1.三色球分组
从3个红球,5个白球,6个黑球中任意取出8个作为一组进行输出。在每组中可以没有黑球,但必须要有红球和白球。编程实现以上功能。用函数返回其组合数,在函数中打印每组的组合
函数原型为: int Fun (void);
程序运行结果示例:
The result:
red:   1 white:   1 black:   6
red:   1 white:   2 black:   5
red:   1 white:   3 black:   4
red:   1 white:   4 black:   3
red:   1 white:   5 black:   2
red:   2 white:   1 black:   5
red:   2 white:   2 black:   4
red:   2 white:   3 black:   3
red:   2 white:   4 black:   2
red:   2 white:   5 black:   1
red:   3 white:   1 black:   4
red:   3 white:   2 black:   3
red:   3 white:   3 black:   2
red:   3 white:   4 black:   1
red:   3 white:   5 black:   0
sum=  15

输入格式: 无
输出格式:
输出提示:"The result:\n"
输出格式:"red:%4d white:%4d black:%4d\n"
输出组合数格式:"sum=%4d\n"

贴上我的代码

#include<stdio.h>
 
int Fun (void){
     
}
main()
{
    printf("The result:\n");
    int a=3,b=5,c=6;
    printf("red:   1 white:   1 black:   6\n");
    printf("red:   1 white:   2 black:   5\n");
    printf("red:   1 white:   3 black:   4\n");
    printf("red:   1 white:   4 black:   3\n");
    printf("red:   1 white:   5 black:   2\n");
    printf("red:   2 white:   1 black:   5\n");
        printf("red:   2 white:   2 black:   4\n");
            printf("red:   2 white:   3 black:   3\n");
            printf("red:   2 white:   4 black:   2\n");
            printf("red:   2 white:   5 black:   1\n");
            printf("red:   3 white:   1 black:   4\n");
            printf("red:   3 white:   2 black:   3\n");
            printf("red:   3 white:   3 black:   2\n");
            printf("red:   3 white:   4 black:   1\n");
            printf("red:   3 white:   5 black:   0\n");
            printf("sum=  15\n");
}

其实就是把结果打印出来;

评分系统取测试结果分;虽然语义匹配分为0;

但是没关系;

我依旧拿到了满分hhhhh

个人不怎么推荐这种方法

除非你真的觉得这道题不想做了

附上这道题的正确代码

#include <stdio.h>
int Fun(void);
int main()
{                    
    int sum;
    sum = Fun();
    printf("sum=%4d\n", sum);
    return 0;
}                    
 
int Fun(void)
{                    
    int i, j, k, sum = 0;
    printf("The result:\n");
    for (i = 1; i <= 3; i++)
    {                    
        for (j = 1; j <= 5; j++)
        {                    
            for (k = 0; k <= 6; k++)
            {                    
                if (i + j + k == 8)
                {                    
                    printf("red:%4d white:%4d black:%4d\n", i, j, k);
                    sum = sum + 1;
                }
            }
        }
    }
    return sum;
}           

这里主要通过你自己的选择来设置,我Google到了很强悍的方法,发上来大家综合修改配置,再试试,首页加载速度大幅度提升!

第一步,这里。(基本)

第二步,这里。(巩固)

第三步,这里。(增强)

第四步,重启你的小狐狸,看看打开我的首页速度会发生什么变化?是不是快得多了?

另外,还有一个事情要说说,F4B4有一个Direct2D硬件加速功能,设置about:config

mozilla.widget.render-mode = 6
gfx.font_rendering.directwrite.enabled = true

重启小狐狸。

打开about:support,看到底下的Direct2D Enable 为 true,说明已经启动了硬件加速,渲染速度大幅提升!另外,妥协还是有的,就是硬盘读写大幅增加,启动速度大幅增加,注意看整个界面都Direct2D了,这有点像游戏的启动了,嘿嘿。

现在再试试我的首页,注意用ctrl+F5彻底刷新,注意速度哦,是不是快了不止10倍?哈哈。世界上最快的浏览器诞生了!什么chrome见鬼去吧!

(我注意到fedora的firefox比ubuntu的快出不少,但是与这篇文章对比,发现linux firefox速度比windows快出不止一点!而且还是我提过速加过硬件加速的!而且我注意到firefox没有进行一点优化,天哪!难道linux 真的比windows的底层更好??)

linux系统学习,正式启动

  今天刚申请了is.programmer,以后的学习之路还有很长还要走!希望一切顺利!