Categories
木有技术

SS客户端及使用教程

2016-03-02更新Windows客户端版本至3.0
2017-03-16更新客户端版本

准备工作:

使用步骤:
1.进入SS服务的用户面板,点击左侧“节点列表”
QQ截图20160209102124
2.挑选需要的节点,然后点击“操作”->“二维码”
QQ截图20160209102808
点击后会新开个网页,上面有二维码,不要动它
3.打开SS客户端,此时任务栏右下角会有小飞机图标。鼠标右键,弹出的菜单点击“服务器”,然后“扫描屏幕上的二维码”
QQ截图20160209103239
正常的话就能扫描好屏幕的上的二维码了,就是服务器账户信息
4.还是刚才的右键菜单,点“启动系统代理”
然后“系统代理模式”选择“PAC”模式
最后一步,在“PAC”那边,点击“从GFWList更新本地PAC”
记得定期更新PAC列表,否则请直接使用“全局模式”。
如果过几秒提示“更新PAC成功”,就一切搞定啦!

Categories
生活琐碎

Protected: 玖

This content is password protected. To view it please enter your password below:

Categories
不学无术

LeetCode #237. Delete Node in a Linked List

题目:https://leetcode.com/problems/delete-node-in-a-linked-list/
思路:
因为只给要删去节点的指针,所以就要想点歪办法。
假设我们有节点1,2,3,【4】,5,6,要删去4这个点,那其实只要把后序节点5的值复制给4,然后我们可以把后面原来那个5删掉,把原有的4节点链到6就行了~大致意思就是,通过往前复制一个值,构造出一个新的“4”的前序节点。

使用前:1,2,3,[4],5,6
拷贝值:1,2,3,5,[5],6
删去多于节点(将新的5节点链接到拷贝的5右边的6,删去老的5节点):1,2,3,5,6

代码:

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode(int x) : val(x), next(NULL) {}
 * };
 */
class Solution {
public:
    void deleteNode(ListNode* node) {
        ListNode* nextNode = node->next;
        node->val = nextNode->val; //Copy value
        ListNode* thirdNode = nextNode->next;
        node->next = thirdNode;
        delete nextNode;
    }
};

 

Categories
不学无术

LeetCode #104. Maximum Depth of Binary Tree

题目:https://leetcode.com/problems/maximum-depth-of-binary-tree/
思路:就是个树遍历的东西,很简单地可以用递归实现
代码:

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    int maxDepth(TreeNode* root) {
        // Left - N - Right
        if(root == NULL) {
            return 0;
        } else {
            //Non-empty
            int leftDeep = 1 + maxDepth(root->left);
            int rightDeep = 1 + maxDepth(root->right);
            if(leftDeep > rightDeep)
                return leftDeep;
            else
                return rightDeep;
        }
    }
};

 

Categories
木有技术

Cisco Linksys EA3500 刷入OpenWrt

万万没想到这个路由器现在也有了官方的OpenWrt支持!
可以参考这里(英文):https://wiki.openwrt.org/toh/linksys/ea3500
大致翻译如下:

As of r47458 the EA3500 is completely supported. This model is identified by the board codename “Audi.”
自从版本r47458开始,EA3500已被OpenWrt完整支持了。这个机型的固件可以用识别码 “Audi”查找

访问这里可以得到最新的编译版本:https://downloads.openwrt.org/snapshots/trunk/kirkwood/generic/
需要查找带有

openwrt-kirkwood-linksys-audi-squashfs-factory.bin

字样的,是可以直接用思科原版固件刷入的;而

openwrt-kirkwood-linksys-audi-squashfs-sysupgrade.tar

是从旧版本OpenWrt升级用的。
注意:刷好之后默认没有开启无线的,也没有装luci图形界面,需要用ssh(可通过putty软件)用有线的方式连接到管理界面。路由器默认的IP地址应该是192.168.1.1
连接SSH时,默认用户是root,然后是空密码。进入后需要用

passwd

命令设置密码。
然后可以更新opkg包进而安装网页管理界面luci

opkg update #更新包信息
opkg install luci #下载并安装luci
opkg install luci-i18n-base-zh-cn #可选,安装中文语言

随后就能通过网页访问http://192.168.1.1来管理啦!
CISCO LinkSys EA3500 OpenWrt

Categories
不学无术

LeetCode #2.Add Two Numbers

链接:https://leetcode.com/problems/add-two-numbers/
思路:
两条链表,从其中一段开始修改,直接在原有节点上做加法。碰到其中一条结束的时候,如果另一条还在继续,则把next指向另一条链表往后一个节点(感觉像是铁轨并轨一样)。
注意如果加起来还有多,要新建一个节点存放。
代码:

class Solution {
public:
	ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
		ListNode* retNode = l1;
		ListNode* prevNode = NULL;
		int res = 0;
		while (l1 != NULL && l2 != NULL) {
			l1->val += (l2->val + res);
			res = 0;
			while (l1->val >= 10) {
				l1->val -= 10;
				res += 1;
			}
			prevNode = l1;
			l1 = l1->next;
			l2 = l2->next;
		}
		if (res == 0 && l1 == NULL && l2 == NULL)
			return retNode;
		ListNode* currNode = l1;
		if (l1 == NULL) {
		    prevNode->next = l2;
			currNode = l2;
		}
		while (currNode != NULL && res != 0) {
			currNode->val += res;
			res = 0;
			while (currNode->val >= 10) {
				currNode->val -= 10;
				res += 1;
			}
			prevNode = currNode;
			currNode = currNode->next;
		}
		if (res > 0) {
			//Add Node
			ListNode* endNode = new ListNode(res);
			prevNode->next = endNode;
		}
		return retNode;
	}
};

结果:
LeetCode002

Categories
不学无术

LeetCode OJ #292. Nim Game

原题地址:https://leetcode.com/problems/nim-game/
思路:
这题目是个找规律的题,号称全OJ最简单….通过找规律可以发现,当n为4的倍数时,无论如何自己都赢不了…然后搞定了
代码:

class Solution {
public:
    bool canWinNim(int n) {
        if(n%4 == 0)
            return false;
        return true;
    }
};

 

Categories
不学无术

LeetCode OJ #1 Two Sum

恩,据说刷LeetCode比较好玩,于是乎从第一题开始吧。
题目:
Given an array of integers, find two numbers such that they add up to a specific target number.
The function twoSum should return indices of the two numbers such that they add up to the target, where index1 must be less than index2. Please note that your returned answers (both index1 and index2) are not zero-based.
You may assume that each input would have exactly one solution.
Input: numbers={2, 7, 11, 15}, target=9
Output: index1=1, index2=2
思路:
这道题给的Hint是二叉树,我有点不太懂,用二叉树实现了一个版本,不过会超时。想了下还是用map的黑科技吧,反正没限制内存大小。(再黑科技一点可以直接用数组,就是数据多的话要找到最小/最大值做好映射)
代码:

class Solution {
private:
	map<int, int> valTable;
public:
	vector<int> twoSum(vector<int>& nums, int target) {
		for (int i = 0; i < nums.size(); i++) {
			int val = nums[i];
			valTable[val] = i + 1;
		}
		for (int i = 0; i < nums.size(); i++) {
			int ne = target - nums[i];
			map<int, int>::iterator result = valTable.find(ne);
			if (result != valTable.end()) {
				int nextIndex = result->second;
				int currIndex = i + 1;
				if (currIndex == nextIndex)
					continue;
				vector<int> retIndices;
				if (currIndex > nextIndex) {
					retIndices.push_back(nextIndex);
					retIndices.push_back(currIndex);
				}
				else {
					retIndices.push_back(currIndex);
					retIndices.push_back(nextIndex);
				}
				return retIndices;
			}
		}
	}
};

运行结果:
我只超过了30.19%的队友,哈哈~
LeetCode_Twp_Sum
 
 
2018 refined (beats 92.29%):

class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        unordered_map<int, size_t> num_indices; // <number, indices>
        for (size_t i = 0; i < nums.size(); ++i)
        {
            auto num = nums[i];
            if (num_indices.count(target - num) > 0)
            {
                return {num_indices[target - num], i};
            }
            num_indices[num] = i;
        }
        return {-1, -1};
    }
};

 

Categories
木有技术

删除Word中的水平线(分割线)

在Word种有个很SB的东西叫做水平线/分割线,就是按连续3个-或者=或者~之类的字符后回车会生成的水平线。具体效果见“Word中简单快速插入各种分隔线及删除分割线的方法”
问题来了,当你想要删去他们的时候,有时候按del键完全不起作用。
这个时候,有个办法,就是用VBA代码(对,那个古老的VB),具体如下:

  1. 按下Alt+F11键打开VBA编辑器;
  2. 双击下图中红圈部分(ThisDocument)vba_editor_word
  3. 在打开的代码编辑器中,粘贴这个代码
    Sub removehline()
        Dim ils As Paragraph
        For Each ils In ActiveDocument.Paragraphs
            ils.Borders(wdBorderBottom).LineStyle =wdLineStyleNone
        Next ils
    End Sub

     

  4. 点击绿色的小箭头,或按F5键运行代码。搞定!
  5. 记得运行完后把VBA代码删了,不然保存的时候会提示宏啊什么的…突然想到Word97时候的宏病毒~

 
参考资料:How to remove all horizontal lines from Word document?

Categories
不学无术

PAT1037 Magic Coupon (25)

The magic shop in Mars is offering some magic coupons. Each coupon has an integer N printed on it, meaning that when you use this coupon with a product, you may get N times the value of that product back! What is more, the shop also offers some bonus product for free. However, if you apply a coupon with a positive N to this bonus product, you will have to pay the shop N times the value of the bonus product… but hey, magically, they have some coupons with negative N’s!
For example, given a set of coupons {1 2 4 -1}, and a set of product values {7 6 -2 -3} (in Mars dollars M$) where a negative value corresponds to a bonus product. You can apply coupon 3 (with N being 4) to product 1 (with value M$7) to get M$28 back; coupon 2 to product 2 to get M$12 back; and coupon 4 to product 4 to get M$3 back. On the other hand, if you apply coupon 3 to product 4, you will have to pay M$12 to the shop.
Each coupon and each product may be selected at most once. Your task is to get as much money back as possible.
Input Specification:
Each input file contains one test case. For each case, the first line contains the number of coupons NC, followed by a line with NC coupon integers. Then the next line contains the number of products NP, followed by a line with NP product values. Here 1<= NC, NP <= 105, and it is guaranteed that all the numbers will not exceed 230.
Output Specification:
For each test case, simply print in a line the maximum amount of money you can get back.
Sample Input:

4
1 2 4 -1
4
7 6 -2 -3

Sample Output:

43

 
=====================================================
这道题也没什么技术含量,就是给你一个X列一个Y列,里面要凑出最大的积的和。有个限制条件,就是商品数量有限,所以可以从商品入手。将商品、优惠券全部排序后,从商品的一段开始匹配能产生最大积的优惠券,累计和,如果碰到乘出负数的就掉个头,从末端往回找。因为求快,所以代码写的多了点,估计还能精简…

#include <iostream>
using namespace std;
int compare(const void *a, const void *b)
{
	return (*(long*)a > *(long*)b) ? -1 : 1;
}
int main()
{
	int NC, NP;
	cin >> NC;
	long * coupons = new long[NC];
	for (int i = 0; i < NC; i++)
	{
		cin >> coupons[i];
	}
	cin >> NP;
	long * products = new long[NP];
	for (int i = 0; i < NP; i++)
	{
		cin >> products[i];
	}
	qsort(coupons, NC, sizeof(long), compare);
	qsort(products, NP, sizeof(long), compare);
	int nc_index = 0;
	long bonussum = 0;
	for (int i = 0; i < NP; i++)
	{
		if (nc_index >= NC)
			break;
		if (products[i] < 0)
			break;
		long bonus = coupons[nc_index] * products[i];
		if (bonus < 0)
			break;
		bonussum += bonus;
		nc_index++;
	}
	nc_index = NC - 1;
	for (int i = NP - 1; i >= 0; i--)
	{
		if (nc_index < 0)
			break;
		if (products[i] > 0)
			break;
		long bonus = coupons[nc_index] * products[i];
		if (bonus < 0)
			break;
		bonussum += bonus;
		nc_index--;
	}
	cout << bonussum;
	return 0;
}

里面可以看到,某个监测点耗时还挺长的…不过我的原则是够用就好。如果优惠券数量远多于商品的话,考虑只对商品排序,然后找优惠券就行了;反之亦然。

测试点

测试点 结果 用时(ms) 内存(kB) 得分/满分
0 答案正确 1 256 10/10
1 答案正确 1 256 3/3
2 答案正确 1 352 3/3
3 答案正确 1 348 3/3
4 答案正确 53 2560 3/3
5 答案正确 1 356 3/3