Ugly number II

Write a program to find the n-th ugly number.
Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers.
Note that 1 is typically treated as an ugly number.

class Solution(object):
    def min_three(self, a, b, c):
        minNum = min(a,b)
        return min(minNum,c)
    def nthUglyNumber(self, n):
        ugly = [1]
        factor2 = 2
        factor3 = 3
        factor5 = 5
        index2 = index3 = index5 = 0
        for i in range(1,n):
            minNum = min(factor2, factor3, factor5)
            ugly.append(minNum)
            if(factor2 == minNum):
                factor2 = 2 * ugly[index2+1]
                index2 += 1
            if(factor3 == minNum):
                factor3 = 3 * ugly[index3+1]
                index3 += 1
            if(factor5 == minNum):
                factor5 = 5 * ugly[index5+1]
                index5 += 1
        return ugly[n-1]

Bulls and Cows

You are playing the following Bulls and Cows game with your friend: You write down a number and ask your friend to guess what the number is. Each time your friend makes a guess, you provide a hint that indicates how many digits in said guess match your secret number exactly in both digit and position (called “bulls”) and how many digits match the secret number but locate in the wrong position (called “cows”). Your friend will use successive guesses and hints to eventually derive the secret number.
For example:

Secret number: “1807”
Friend’s guess: “7810”

Hint: 1 bull and 3 cows. (The bull is 8, the cows are 0, 1 and 7.)
Write a function to return a hint according to the secret number and friend’s guess, use A to indicate the bulls and B to indicate the cows. In the above example, your function should return “1A3B”.
Please note that both secret number and friend’s guess may contain duplicate digits, for example:

Secret number: “1123”
Friend’s guess: “0111”

In this case, the 1st 1 in friend’s guess is a bull, the 2nd or 3rd 1 is a cow, and your function should return “1A1B”.
You may assume that the secret number and your friend’s guess only contain digits, and their lengths are always equal.

class Solution {
public:
    string getHint(string secret, string guess)
    {
        int cntA = 0, cntB = 0;
        unordered_map<char, int> hash;
        vector<bool> tag(secret.size(), false);
        
        for (auto a : secret)
        {
            ++hash[a];
        };
        
        for (int i = 0; i < secret.size(); ++i)
        {
            if (secret[i] == guess[i])
            {
                ++cntA;
                --hash[secret[i]];
                tag[i] = true;
            }
        }
        for (int i = 0; i < guess.size(); ++i)
        {
            if (!tag[i] && hash[guess[i]] > 0)
            {
                ++cntB;
                --hash[guess[i]];
            }
        }
        return to_string(cntA) + "A" + to_string(cntB) + "B";
    }
};

Google镜像站列表

网址转载自: http://www.itechzero.com/google-mirror-sites-collect.html
感谢Techzero为天朝人民所做的贡献。
以下是直接使用谷歌的方法,如需科学上网戳这里(VPN | Shadowsocks

原版镜像:

[推荐]https://www.psea.in/
[推荐]https://www.guge.link/
[推荐]https://www.guge.click/
[推荐]https://www.souguge.com/
http://pds.gs/
http://g.kvm.la/
https://g1.wen.lu/
https://opennet.xyz/
https://gg.knight.ren/
http://guge.cytbj.com/
http://www.fcczp.com/
https://i.xueshugu.com/
https://search.chun.pro/
http://tokillgoogle.com/
https://google.xface.me/
http://www.baidu.com.se/
https://google.checkme.com.cn/
http://google.sidney-aldebaran.me/

非原版镜像:

[推荐]微搜:http://www.wesou.org/
[推荐]谷歌363:http://www.g363.com/
[推荐]图灵搜索:https://www.tulingss.com/
G搜索:http://www.xpan.so/
Ask:http://home.tb.ask.com/
AOL:http://m.search.aol.com/
谷歌婊:http://www.gugebiao.com/
Avira:https://safesearch.avira.com/
丸子138:http://www.wanzi138.com/
谷粉138:http://www.gufen138.com/
丸子163:http://www.wanzi163.com/
谷粉163:http://www.gufen163.com/
Babylon:http://isearch.babylon.com/
Disconnect:https://search.disconnect.me/

谷歌学术

[推荐]https://www.scholar.live/
[推荐]http://guge.cytbj.com/scholar/
[推荐]https://www.souguge.com/scholar/
http://g.linkscholar.org/
https://www.roolin.com/
http://scholar.g363.com/
http://www.scholarnet.cn/
http://scholar.searcher.top/
https://www.psea.in/scholar/

谷歌图片

[推荐]https://www.psea.in/imghp
[推荐]https://www.guge.link/imghp
[推荐]https://www.souguge.com/imghp
http://guge.cytbj.com/imghp
http://www.fcczp.com/imghp
https://www.guge.click/imghp
https://google.xface.me/imghp

美好时光

今年学校放假确实放的挺早的,再加上我的室友们一个个归心似箭,目前我已经成功进入假期单刷的副本了。
虽然每年寒暑假都要留校,但总有那么几天需要适应一下的。于是打算给自己找点事情做,以下是我之前臆想的清单,然而我觉得应该做不完~

  • 再刷一遍算法导论和C++ Primer(后来想了想,detour…)
  • 搞一个扎古拼起来(唔,这个可能耗时会有点长,而且我还没有喷枪,暂时搁浅…)
  • 程序员面试宝典(本来以为很精深,结果…..写本文的时候已刷完)
  • 骑车去洋湖湿地(自从换了不怎么兼容的影子后拨,掉链子简直家常便饭~)
  • 如果回成都的话,打算去鹅厂搅基(这个愿望,我为什么要去搅基啊!)
  • 去看GIF,膜拜大神,顺便给信仰充个值(即将实现,明天就杀去帝都.)
  • MCM大爷求给个M奖(当然,你要是想给O或者F,我也笑纳)
  • 去酒仙桥找HackRF(就算找到了,那么贵我也买不起~)
  • 单刷一只烤鸭(一个食科生的尊严)
  • 看看双十一作死买的那些书(顺便谁能告诉我,哪里有收书的~)

其实还有好多想要去做的事情,真的只能一点一点去完成了。昨天晚上搭了这个站,希望可以记录我假期的生活,我也会坚持每天都写点东西出来的。
Continue reading