编程日志&&刷题日志&&开发日志迁移之碎碎念

Given an array of integers, return indices of the two numbers such that they add up to a specific target.

You may assume that each input would have exactly one solution, and you may not use the same element twice.

Example:

Given nums = [2, 7, 11, 15], target = 9,

 

Because nums[0] + nums[1] = 2 + 7 = 9,

return [0, 1].

MY answer:

class Solution

{

public:

    vector<int> twoSum(vector<int>& nums, int target)

    {

        map<int, int> m;

        map<int,int>::iterator goal;

    for (int i = 0; i < nums.size(); i++)

{

        int complement = target - nums[i];

        goal= m.find(complement);

        if (goal!=m.end())

{

vector<int> st= { goal->second, i };

            return st;

        }

        m.insert(map<int,int>::value_type(nums[i],i));

    }

    }

};

Fastest anwsers from internet:

// how to get Leetcode tests to run approximately 10-40% faster, since they do a lot of print outs.

static auto x = [](){

    // turn off sync

    std::ios::sync_with_stdio(false);

    // untie in/out streams

    cin.tie(NULL);

    return 0;

}();class Solution {public:

    vector<int> twoSum(vector<int>& nums, int target) {

        vector<int> indices;

        int lenOfVectors = nums.size();

        bool found=false;

        vector< pair<int, int> > new_nums;

        for(int i=0; i<lenOfVectors; ++i){

            new_nums.push_back(make_pair(nums[i], i));

        }

        sort(new_nums.begin(), new_nums.end());

        int j=0, k=lenOfVectors-1;

        while(j<k){

            if(new_nums[j].first+new_nums[k].first==target){

                indices.push_back(new_nums[j].second);

                indices.push_back(new_nums[k].second);

                break;

            }

            else if(new_nums[j].first+new_nums[k].first<target){

                j++;

            }

            else{

                k--;

            }

        }

        return indices;

    }

};

 

To Sumup:

Map<Type,Type> m;

3 methods to insert data

1:Insert(map::Value_Type<type,type>(v,v))

2:insert(pair<type,type>(v,v))

3:m[1]=v m[2]=v only this method can writeover the existing item;

M.find() returns an iterator of the found item by key.if not ,returns the m.begin();

How to confirm whether an insertion is done?

Pair<map<Type,Type>::iterator,bool> insertbool;

Insertbool=m.insert(pair<Type,Type>(v,v)); //这里只能用pair的构造器。

The bool of insertbool stores the return value

map的基本操作函数:

     C++ maps是一种关联式容器,包含关键字/

     begin()         返回指向map头部的迭代器

     clear(        删除所有元素

     count()         返回指定元素出现的次数

     empty()         如果map为空则返回true

     end()           返回指向map末尾的迭代器

     equal_range()   返回特殊条目的迭代器对

     erase()         删除一个元素

     find()          查找一个元素

     get_allocator() 返回map的配置器

     insert()        插入元素

     key_comp()      返回比较元素key的函数

     lower_bound()   返回键值>=给定元素的第一个位置

     max_size()      返回可以容纳的最大元素个数

     rbegin()        返回一个指向map尾部的逆向迭代器

     rend()          返回一个指向map头部的逆向迭代器

     size()          返回map中元素的个数

     swap()           交换两个map

     upper_bound()    返回键值>给定元素的第一个位置

     value_comp()     返回比较元素value的函数

td::ios::sync_with_stdio(false); C++中cin和stdin因为要保持兼容性所以会进行buffer同步,这里会损耗很多性能这里可以选择关闭!

2018.5.11

 

 

 

 

 

 

 

2:reverse

Given a 32-bit signed integer, reverse digits of an integer.

Example 1:

Input: 123Output: 321

Example 2:

Input: -123Output: -321

Example 3:

Input: 120Output: 21

Note:
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

(又不看题。。。以后做题一定要先想好怎么做再动笔,否则就是浪费时间)

 

Fastes Solution

class Solution {public:

    int reverse(int x) {

        int result = 0;

        while (x)

        {

             pr = result * 10 + x % 10; //保存每一次迭代的结果

            if (result != pr / 10) return 0; //查看是否发生溢出

            result = pr; //作为查看是否溢出的依据

            x /= 10; 

        }

        return result;

    }

};

这个算法很巧妙。

分别算每一位的方法是

123123%10=3 123123/10=12312   pr=3  result=0=pr/10 result=3 记录上次头部数

12312%10=2 12312/10=1231    pr=32  result=3=pr/10 result=32

1231%10=1 1231/10=123      pr=321 result=32=pr/10 result=321

123%10=3 123/10=12         pr=3213  result=321=pr/10 result=3213

12%10=2 12/10=1          pr=32132  result=3213=pr/10 result=32132

1%10=1 1/10=0      pr=321321   result=32132=pr/10 result=321321   停止!

而我之前写的就是 一个很傻的方法,用除法来求最后一位就很脑残了

2018.5.11

3:roman to integer

 

Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.

Symbol       Value

I             1

V             5

X             10

L             50

C             100

D             500

M             1000

For example, two is written as II in Roman numeral, just two one's added together. Twelve is written as, XII, which is simply X + II. The number twenty seven is written as XXVII, which is XX + V + II.

Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as IX. There are six instances where subtraction is used:

  • I can be placed before V (5) and X (10) to make 4 and 9. 
  • X can be placed before L (50) and C (100) to make 40 and 90. 
  • C can be placed before D (500) and M (1000) to make 400 and 900.

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.

HOW to solve it:

Just to notice the front and behind  relationship ,and you will find the tricks.

 

class Solution {

public:

    int romanToInt(string s)

    {

     int sum=0;

     int len=s.length();

        for(int i=0;i<len;i++)

        {

         if(i>0)

         {

         if(Getvalue(s[i])-Getvalue(s[i-1])>0)

         {

         sum-=2*Getvalue(s[i-1]);

         sum+=Getvalue(s[i]);

        

}

else

{

sum+=Getvalue(s[i]);

}

}

else

{

sum+=Getvalue(s[i]);

}

}

return sum;

    }

};

4 Nondecreasing array;

Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.

We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i (1 <= i < n).

Example 1:

Input: [4,2,3]Output: TrueExplanation: You could modify the first 4 to 1 to get a non-decreasing array.

Example 2:

Input: [4,2,1]Output: FalseExplanation: You can't get a non-decreasing array by modify at most one element.

Note: The n belongs to [1, 10,000].

这道题除想起来好像很简单,但是问题在于如何理清一个很好的思路

问题一:

如果出现一个两个及两个以上的错序,则能否在调整一个数字的情况下恢复正序?

NOWhY:两个连续的错序很明显是无法一次纠正的,离得很远的也一样。

问题二:

当只出现一个错误的时候,如何确认能够恢复?

这里就要分类讨论了

Abcdefg 假设d这里出现了d>e情况。C<=d f>=e

所以cf是不会变的。为什么他们两个不会变?因为他们已经符合规则,如果有了有效变化,那么必然会导致更多的错序。所以他们不会变。对于

de如果变de>=c必须成立,如果变e则,f>=d必然成立所以这里就完成了讨论了。代码就不贴了很长。。

5:

今天做了一个很简单的就不贴了一次通过了。

学到了一个很好用的函数:到时候研究一下IO库的使用吧。

 

2018/5/15

 

6:日常刷了两道简单题,不说了。今天搞日语!

7:hammingDistance找二进制的不同位的个数

class Solution {public:

    int hammingDistance(int x, int y) {

        unsigned int r = x ^ y;

        int b = 0;

        while(r) {

            if(r & 1) b++;

            r = (r >> 1);

        }

        return b;

    }

};

自己做的答案很蠢,就是先转换为二进制然后再一位一位比较。这样是非常慢的。

以上的最快答案是直接异或操作然后计算结果中的1的个数即可

数字进行左右移位的时候是返回左值的。

8:judgeCircle

题目很简单就是判断LR以及UD是否成对出现。

class Solution {

public:

    bool judgeCircle(string moves) {

        int count [1 + 'U' - 'D'];

        count['D' - 'D'] = 0;

        count['U' - 'D'] = 0;

        count['L' - 'D'] = 0;

        count['R' - 'D'] = 0;

        for (int i = 0; i < moves.size(); ++i) {

            ++count[moves[i] - 'D'];

        }

        return (count['D' - 'D'] == count['U' - 'D'] && count['L' - 'D'] == count['R' - 'D']);

    }

};

这里是最快的solution。而我的方法则是

这里算一下平均所需要的时间吧:1/4*1+2+3+4=2.5

而最快的答案则是1;速度的区别就在于2.5nn的区别了,所以最快的速度为5ms而我的则是16ms

最快的速度的思想是桶的思想,Dacll值最小所以分类为DULR。每次都不需要进行==的判断直接填入个数,最后分别一个判断式就搞定,妙妙秒。

2018/5/18

 

2018/5/20 :

刷了两道题很简单没什么好说的啦

2018/5/21:

Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as possible.

Example 1:

Input: [1,4,3,2]

Output: 4Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).

使用贪心定理进行推导即可

这道题很奇怪,简单是简单但是最快的答案让我一头雾水

int x=[](){

   std::ios::sync_with_stdio(false);

    cin.tie(NULL);

    return 0;

}();

class Solution {

private:

    inline

    int count(int n)

    {return (n >> 1) + (n % 2);

    }

public:

int arrayPairSum(vector<int>& nums)

{array<int, 20001> ary{0};

      for (auto&& it: nums)

        ++ary[it + 10000];

        int answer = 0;

        bool carry = false;

        for (int i = 0; i < 20001; ++i)

        {

            if (!ary[i]) continue;

            answer += carry ? count(ary[i] - 1) * (i - 10000) :

            count(ary[i]) * (i - 10000);

            carry ^= ary[i] & 0b1;}return answer;}};

 

 

这里的arrayC++ 11的新特性。Array是一个容器,和数组不同的是,它可以进行赋值拷贝,而数组时不行的。Array<int,100> st;

2018/5/22:

Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.

You need to merge them into a new binary tree. The merge rule is that if two nodes overlap, then sum node values up as the new value of the merged node. Otherwise, the NOT null node will be used as the node of new tree.

Example 1:

Input: 

Tree 1                     Tree 2                  

          1                         2                             

         / \                       / \                            

        3   2                     1   3                        

       /                           \   \                      

      5                             4   7                  Output: 

Merged tree:

     3

    / \

   4   5

  / \   \

 5   4   7

Note: The merging process must start from the root nodes of both trees.

递归即可解决 简而言之就是合并两个二叉树

 

2018/5/23

A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com", and at the lowest level, "discuss.leetcode.com". When we visit a domain like "discuss.leetcode.com", we will also visit the parent domains "leetcode.com" and "com" implicitly.

Now, call a "count-paired domain" to be a count (representing the number of visits this domain received), followed by a space, followed by the address. An example of a count-paired domain might be "9001 discuss.leetcode.com".

We are given a list cpdomains of count-paired domains. We would like a list of count-paired domains, (in the same format as the input, and in any order), that explicitly counts the number of visits to each subdomain.

Example 1:Input: 

["9001 discuss.leetcode.com"]Output: 

["9001 discuss.leetcode.com", "9001 leetcode.com", "9001 com"]Explanation: 

We only have one website domain: "discuss.leetcode.com". As discussed above, the subdomain "leetcode.com" and "com" will also be visited. So they will all be visited 9001 times.

 

Example 2:Input: 

["900 google.mail.com", "50 yahoo.com", "1 intel.mail.com", "5 wiki.org"]Output: 

["901 mail.com","50 yahoo.com","900 google.mail.com","5 wiki.org","5 org","1 intel.mail.com","951 com"]Explanation: 

We will visit "google.mail.com" 900 times, "yahoo.com" 50 times, "intel.mail.com" once and "wiki.org" 5 times. For the subdomains, we will visit "mail.com" 900 + 1 = 901 times, "com" 900 + 50 + 1 = 951 times, and "org" 5 times.

 

Notes:

  • The length of cpdomains will not exceed 100. 
  • The length of each domain name will not exceed 100.
  • Each address will have either 1 or 2 "." characters.
  • The input count in any count-paired domain will not exceed 10000.
  • The answer output can be returned in any order.

 

 

题目倒是不难,但是因为对stringsubtr的陌生导致没发现问题。

其次是map的使用依然不熟练。

2018/5/24

今天做了一道很傻吊的题就不谈了,答案都是错的。

2018/5/27

Number Complement

题目意思很明确就是把各个位取反就ok

using namespace std;int x=[](){

    ios::sync_with_stdio(false);

    cin.tie(NULL);

    return 0;

}();

class Solution {public:

    int findComplement(int num) {

        unsigned mask = ~0;

        while(mask & num)

            mask <<= 1;

        return ~mask & ~num;

    }

};

不知道取反操作真的是丢人了。。。。~就是取反操作。。然后这道题我相信会很简单。。

后面又做了一道revease string k的题目就是隔k个反转字符串

两天没做脑袋就蒙蔽了。。。果然还是的天天刷题啊。。。维持热度

2018/5/28

Char类型中’\0’’’不是一个东西啊。一个是空ascll值为0,一个是空格ascll码值为32

Reverse Words in a String III

题目很简单就是给你一个带有空格的字符串把他们反过来即可,空格保留。

以下是最佳答案

 

这个答案的很漂亮,亮点是swap函数的使用,以及字符串的reverse方法。

2018/5/29

今天看了一篇关于new关键字的讲解:

A *a=new A();

大致相当于 A * a=A*new malloc(sizeof(A));

a->A::A();

Return a;

New符号是可以重载的同理delete也是可以重载的,如果重载new改变分配内存的时候的一些设置和属性,那么delete也最好重载一下这是良好的编程习惯.

new operator:获得一块内存空间、调用构造函数、返回正确的指针。

operator new:获得空间返回指针(即我们可以进行new重载)

placement new:在指定内存位置进行构造对象(可以进行构造操作自定义,不过这里需要引用new.h

  • char s[sizeof(A)];  
  • A* p = (A*)s;  
  • new(p) A(3); //p->A::A(3);  
  • p->Say(); 

new(p) A(3)这种奇怪的写法便是placement new了,它实现了在指定内存地址上用指定类型的构造函数来构造一个对象的功能,后面A(3)就是对构造函数的显式调用。看得出来,这块指定的地址既可以是栈,又可以是堆.

但是,除非特别必要,不要直接使用placement new ,这毕竟不是用来构造对象的正式写法,只不过是new operator的一个步骤而已。使用new operator地编译器会自动生成对placement new的调用的代码,因此也会相应的生成使用delete时调用析构函数的代码。

如果是像上面那样在栈上使用了placement new,则必须手工调用析构函数,这也是显式调用析构函数的唯一情况:

P->~A();

 

一定要注意异常安全的问题,就是要考虑某项操作失败了会如何的问题。尤其是需要新分配内存的时候。

 

C/C++在分配内存时已经记录了足够充分的信息用于回收内存,只不过我们平常不关心它罢了。

 

#include<sstream>

stringstream对象用以转换int和string是非常快速和方便的

String p;

 stringstream res;

int tmp;

      res<<p;

      res>>tmp;

这样几步操作即可。

后面还做了一道关于栈的题目,感觉还算简单。就不说了。

2018/5/30

做了一道求边界长度的题目,原理跟之前写过的扫雷很类似。就不多说了。今天真的忙啊。。。

2018/5/31

做了一道题,很简单就是在规定的个数中找最多的种类而已。

最佳答案:

 int distributeCandies(vector<int>& candies) {

        bitset<200001> v;

        size_t cnt = 0;

        for (int i : candies) {

           cnt += !v.test(i + 100000);

           v.set(i + 100000);

        }

        return min(cnt, candies.size() / 2);

}

最佳答案利用的是桶的思想

bitset存储二进制数位。

bitset就像一个bool类型的数组一样,但是有空间优化——bitset中的一个元素一般只占1 bit,相当于一个char元素所占空间的八分之一。

bitset中的每个元素都能单独被访问,例如对于一个叫做foobitset,表达式foo[3]访问了它的第4个元素,就像数组一样。

bitset有一个特性:整数类型和布尔数组都能转化成bitset

bitset的大小在编译时就需要确定。如果你想要不确定长度的bitset,请使用(奇葩的)vector<bool>

test(size_t pos)
pos处的二进制位是否为1?

oo.size() 返回大小(位数)
foo.count() 返回1的个数
foo.any() 返回是否有1
foo.none() 返回是否没有1
foo.set() 全都变成1
foo.set(p) 将第p + 1位变成1
foo.set(p, x) 将第p + 1位变成x
foo.reset() 全都变成0
foo.reset(p) 将第p + 1位变成0
foo.flip() 全都取反
foo.flip(p) 将第p + 1位取反
foo.to_ulong() 返回它转换为unsigned long的结果,如果超出范围则报错
foo.to_ullong() 返回它转换为unsigned long long的结果,如果超出范围则报错
foo.to_string() 返回它转换为string的结果

什么时候用bitset呢?只需要统计是否出现的问题而不涉及出现的次数的时候。

2018/6/3

由于天气太炎热,所以摸了三天今天补了三道题

 

都很简单没必要说了。

2018/6/10

上周由于游戏设计的课程导致没时间刷leetcode

今天做了四道题但是树的一道题不太会等我课程结束了再好好恶补树。。、

今天有道题还蛮有趣的。

就是在一堆成对的数里找出唯一一个单独的数。这里要求为O(n)的复杂度。

一开始可以想到很多非On)的做法,例如使用哈希表。

但是这里的最佳答案是全部一起求异或就可以得到实在是妙不可言。

Reverse bits of a given 32 bits unsigned integer.

Example:

Input: 43261596Output: 964176192Explanation: 43261596 represented in binary as 00000010100101000001111010011100,

             return 964176192 represented in binary as 00111001011110000010100101000000.

还有这道题让我纠结了很久。

我的错误答案就一步之遥:res<<=1;

             res+=(n&1);

我写反了,问题在哪呢?很明显最后一位的赋值被提前移位了。

举一个简单的例子,如果res=0

n=10001)时在第一个循环中res移位在前则结果为为1

在后则为2 所以这里就将1往左多移了一位所以结果就出错了

然后做了一道很智障的题目,,,mdzz

2018/6/11

今天做了一道树的求深度的题目,使用递归很快就求得。

class Solution {

public:

    int maxDepth(TreeNode* root)

    {

       if(root==NULL)

       {

           return 0;

       }

        else

        {

            return max(maxDepth(root->left),maxDepth(root->right))+1;

        }

        

    }

};

就很简单23333333

2018/6/16

这几天一直都没怎么做题。即使是做了也没什么难度,啊赶紧把日语考试考了吧。。很难,但是应该能过加油吧!23333

2018/6/17

今天一天就把信息检索系统的论文报告写了啊啊啊啊,累死了。

2018/6/19

签证材料交上去了听天由命中,其次,今天就做了一道题挺简单的。

2018/6/21

又遇到了应用桶的思想的题目,但是原题说了不准使用额外的space啊。。。。

2018/6/24

今天做了一道稍微需要想一下但仔细一想其实也很简单的题目,简而言之就是一个字符串的字母进行二元替换的所有可能,其实这个很简单,但是实现起来就有两种做法,一便是递归,二则是我这种非递归,其实两者时间复杂差不多

 

2018/9/5

需要使用某个指针指向位置的信息时最好新建另外一个指针指向其进行操作,避免指针使用混乱导致超时

2018/9/8

今天碰到了很有意思的一道题目

如何用位运算得到和。

a+b

其实主要还是自己对于位运算依旧不太熟悉。

方法很简单。

使用任意一个数作为循环控制数值

当然这个数在下面要充当进位数

实际上加法的本质就是先按位不管进位加起来。然后计算进位数再加上。再得到新的和。继续循环得到新的进位数重复往下就可以了。当进位数到数字的最左边时,右端全为0这时再进行与运算会将进位数置零结束循环。

A^b 不进位加法

A&b <<1计算进位数 只有两个一才能为1此时进位所以左移一位

掌握这两点就很简单了

 接下来的是一道昨天的题目。

 

从一开始就想复杂了,实际上这个问题就是数连续序列的数字个数以及取min

Prev 表示前一个序列的个数初始化为0

Cur表示现在所在序列的数字个数 初始化为1 因为是从i=1开始遍历的i=0的数字已经是一个

所以一直遍历下去,如果前后相同则cur+1

不相同则说明到了两个序列的交界,Ans+=minprevcur)就自动加0了。

此时让prev获得cur的值记住前一个序列的数字个数。那么cur就又变成1了因为cur所在的序列变成了另一个序列所以得重新计数。原理就是这样答案也很简单。

Int pre=0,ans=0,cur=1;

For(int i=1;i<len;i++)

{

If(s[i-1]!=s[i])

{

到达交界处

Ans+=min(prev,cur);

Prev=cur;

Cur=1;
}

Else

Cur++;

}

由于最后的时候到达临界点没有ans没有加上最后一个。

所以return ans+minprevcur);

leetcodetm有意思。。2333333333

2018/9/17

脑壳已经很僵硬了连在链表中删除元素都不会了

/**

 * Definition for singly-linked list.

 * struct ListNode {

 *     int val;

 *     ListNode *next;

 *     ListNode(int x) : val(x), next(NULL) {}

 * };

 */

class Solution {

public:

    ListNode* removeElements(ListNode* head, int val)

    {

        ListNode *fake=new ListNode(0);

        fake->next=head;

        ListNode *cur=fake;

        while(cur)

        {

            if(cur->next&&cur->next->val==val)

                cur->next=cur->next->next;

            else

                cur=cur->next;

        }

        return fake->next;

      

    }

};

这里的解答很巧妙在为了避免检查自身而设置的虚假头。只需要检查下一个是否与val相等即可,不用检查本身是否与val相等。

2018/10/6

Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.

Note:

  • The number of elements initialized in nums1 and nums2 are m and n respectively.
  • You may assume that nums1 has enough space (size that is greater or equal to m + n) to hold additional elements from nums2.

Example:

Input:

nums1 = [1,2,3,0,0,0], m = 3

nums2 = [2,5,6],       n = 3

Output: [1,2,2,3,5,6]

题目倒是不难但是最佳答案确实很美丽

class Solution {

public:

    void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) {

        int i = m - 1, j = n - 1, tar = m + n - 1;

        while(j>=0)

        {

            nums1[tar--]=i>=0&&nums1[i]>nums2[j]?nums1[i--]:nums2[j--];

        }

    }

};

利用已经排序好了的特性一个一个把nums2的数放进去即可。

2018/12/6:

困扰很长时间的DXUT框架无法调试报错的问题终于解决了,解决方法其实很简单,两步即可完成

第一步:

 

在附加依赖项里添加legacy_stdio_definitions.lib.

 

第二步:

将报错地点的abs函数改为fabs即可解决。

 

至此DXUT框架就可以正常的跑起来了。

2018/12/7

Vs2017 注释快捷键:ctrl+k 然后再ctrl+C ccomment的意思

今天解决了DXUTskinned动画实例的解读工作成功移植到自己的程序中了。

2018/12/9

研究明白了xAudio 2的用法并且成功封装成类,实现了播放,但是游戏需要的实时播放却无法实现,看了看源码,发现mastervoice实际上使用了多线程导致了阻塞。

2018/12/10

针对昨天的线程阻塞问题发现了官方给出的源代码中在播放完毕后会有一个sleep过程,这个导致了阻塞。

Sourcevoice

The final useful thingIt maintains a buffer queue

Functions

Submitbuffer() means adding a piece of buffer to the queue.

Stop() means stop sending buffer to the audio hardware but the buffer queue is not changed.

Discontinuity() means the buffer is not cleared off,and still sending buffer until the thread is exited.

2018/12/13

Topic:

Understanding the hierarchy of .X file.

 

Number1:Header

This part demonstrates the type of this file,the edition of this file hierarchy,and finally 32bits or 64bits edition of data.

Example:

Xof 0303txt 0032

32 bits file.

which means this is a .X format file and rule edition is 3.3 ,the codes behind is stored in the form of txt coding .

Number 2:Template Definition

template <template-name>{        <UUID>                                

      <member 1>,                ………                                

      <member n>,                [restrictions]     

}

UUID means global Universally unique identifier!

Such as <10dd46a9-775b-11cf-8f52-0040333594a3>

The last phase [] means the restriction of this template!

[...] identifies that you can add some more variants of any type

[<name1><type1>,<name2>,type2>]which means you have to add variants under those limited types if necessary.

Number 3:Some conventional templates

AnimationSet the combination of animation including one or more Animations.

Animation demonstrates one animation including one or more Animation Key.

AnimationKey definitions of specific movement data including revolving ,transforming,scalling

ColorRGB overlook.

ColorRGBA overlook

Coords2d u,v coordinate

FloatKeys animation key data including number of float,list of floats

Material :

Facecolor means ambient

Power of the specular

And its color

Martix4X4

Mesh

....ETC the remains can be comprehended by its name.

2018/12/17

这几天解决了多轨动画的混合和设置以及dds文件导入错误的问题。

实际上是mesh文件本身把贴图位置设置为了其他的文件夹,所以才找不到贴图

2018/12/19

利用静态变量和私有化构造函数的特性来实现单例模式。搞一个静态的自身类指针,然后把构造函数私有化,这样new的时候就只能让本类中的成员调用,然后不择手段在类内部new出这个对象,并提供一种方法供外部得到这个对象的地址。

2018/12/20

Today some functions should be memerized and manipulated well by myself ,which are quiet useful

D3DXVec3TransformCoord this only transform one coordinate .

D3DXVec3TransformCoord(&OriginRayPos, &OriginRayPos, &re);

The last param is output;

D3DXVec3TransformNormal this only transforms one vector3,The same output order.

D3DXMatrixInverse(&re, 0, &objworld); this will produce an inverse matrix of objworld

BaryCentric coordinate summary:

 

figure1

To represent a barycentric coordinate in a triangle.

P=w*C+v*b+w*C;

Or

U=Scap/Sabc;

V=Sabc/Sabc;

W=1-v-u;

And remember Sabc=|ABxAC|=|AB|x|AC|xsin(angle(CAB));

 

 

Never change any of the camera parameter after it has calculated the ViewMatrix or sth else.

You should abide the philosophy that move and set,which means after thorough reconfiguration,Then just Set it tight,And do not ever change it aftr that!!!!

Then lets talk about the algorithm about how to detect whether a triangle is hit by the Given Ray.

 

First Detect Whether the ray is parallel to the triangle .

Use Cross(out,dir,v0v1);

Then Dot(result,out,v0v2);

If result is nearly zero then you can determinate the result roughly.

Second compute the point of the intersection.

Third according to point of intersection ,calculate the u,v coordinate

Using volume ratio.

But the directx used a optimized version of itBut the sense is the same

2018/12/26

Direct3D中的广告板(Billboard)技术,也叫公告版技术。公告版技术的基本原理在这里也提一下吧,后面有机会就专门用一次更新来讲解。公告版技术的基本原理就是在渲染一个多边形时,首先根据观察方向构造一个旋转矩阵,利用这个旋转矩阵旋转多边形让这个多边形始终是面向观察者的,如果观察方向是不断变化的,那么我们这个旋转矩阵也要不断进行调节。这样,我们始终看到的是这个多边形“最美好”的一面。这样先让多边形面向观察者,然后再渲染的技术,就是传说中的广告板(Billboard)技术。

 

2018/12/27

Drawing Point Lists is also constrained by WORLD matrix...please remember this.It has taken you a lot of time to figure out .As Long as the FVF includes D3DFVF_XYZ ,the primitive is always controlled by The FOUR transformation.

 

Today i finally finished the Gun part developing.

Next part is p2p correspondence!

2019/1/1

After my new year vacation,time to come back to my work now.

Note,WSAStartup() is a neccessary procedure before we call other socket apis.

2019/1/5

How to transform string to int or float?

TO int:

int i=atoi(str.c_str());

To FLoat:

float f=atof(str.c_str());

Easy enough.

 

Two cmd command

Netstat -ano to seek the circumstances of the occupied port and it’s corresponding pid.

Arp -a to see the ips.

 

2019/1/6

One add_in point can only be bond once。

Connect can only be called once。

Why ?

Because when you connect successfully to the server,you socket will be distributed a add_in potentially unique.

2019/1/7

When you called the function bind and listen to the local addr_in ,the server will be ready to receive tcp connection request then any request coming to our host will be placed in the queue of established connection ,and accept function is an I\O-Blocking function ,so if there is no connection  the accept function will be blocked for a long time up bout 75 seconds.

 

When you are inflicted by the trouble of blocking of recv and recv from

Functions ,

timeval tv = { 10,0 };

setsockopt(castsock, SOL_SOCKET, SO_RCVTIMEO, (char*)&tv, sizeof(tv));

Try codes above,which will help you to deal with time_out;

2019/1/8

F_Ui_Item is distinguished by the Rect data,Prepared Rectangle design is recommended for exact UI EVENT signal discerning .

2019/2/14

Communication system development finished.

The mission for next semester: optimize online experiences,finish the bullet interaction with animated model problem,and finish the whole game development.

posted @ 2019-08-27 18:19  Tonarinototoro  阅读(208)  评论(0编辑  收藏  举报