Categories
不学无术

PAT 1012. The Best Rank (25)

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C – C Programming Language, M – Mathematics (Calculus or Linear Algebra), and E – English. At the mean time, we encourage students by emphasizing on their best ranks — that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.
For example, The grades of C, M, E and A – Average of 4 students are given as the following:

StudentID  C  M  E  A
310101     98 85 88 90
310102     70 95 88 84
310103     82 87 94 88
310104     91 91 91 91

Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.
Input
Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.
Output
For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.
The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.
If a student is not on the grading list, simply output “N/A”.
Sample Input

5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999

Sample Output

1 C
1 M
1 E
1 A
3 A
N/A

===============================================


又回来做PAT题目了,C++都忘得差不多干净了有没有!下次尝试下提交Python的答案吧~诶嘿嘿
这道题没什么难的,因为它时间要求不高。
我做了个链表把学生成绩的节点连起来,这样是因为学号有6位数(其实要是弄个1000000行的矩阵也没什么了不起的嘛哼!),反正之后就是链表查找的问题了,没啥可说。

#include <iostream>
using namespace std;
struct RecordNode
{
	//存放单个学生数据的链表节点
	int studentID;
	int results[4];	//0-A, 1-C, 2-M, 3-E
	RecordNode* nextNode;
	RecordNode(int sid, int c, int m, int e, int a)
	{
		studentID = sid;
		results[0] = a;
		results[1] = c;
		results[2] = m;
		results[3] = e;
		nextNode = NULL;
	}
};
RecordNode* rootNode = NULL;
RecordNode* getNodePointer(int studentID)
{
	//没有则返回NULL
	RecordNode* currNode = rootNode;
	while (currNode != NULL)
	{
		if (currNode->studentID == studentID)
			return currNode;
		currNode = currNode->nextNode;
	}
	return currNode;
}
void getRankInMatrix(int studentID, int* ranks)
//从矩阵中得到某人的all排位
//(subj:  0-C, 1-M, 2-E, 3-A)
{
	//int ranks[4] = { 1, 1, 1, 1 };
	RecordNode* node = getNodePointer(studentID);
	if (node == NULL)
	{
		//ranks = NULL;
		//delete ranks;
		ranks[0] = -1;
		return;
	}
	int* results = node->results;	//所有课的成绩
	RecordNode* opNode = rootNode;
	while (opNode != NULL)
	{
		//遍历
		for (int subj = 0; subj < 4; subj++)
		{
			//subjects
			if (opNode->results[subj] > results[subj])
				ranks[subj] ++;
		}
		opNode = opNode->nextNode;
	}
	//return ranks;
}
char ACME[] = "ACME";
int main()
{
	int M, N;
	cin >> N >> M;
	RecordNode* opNode = rootNode;
	for (int i = 0; i < N; i++)
	{
		int sid, c, m, e, a;
		cin >> sid >> c >> m >> e;
		a = (int)(((c + m + e) / 3.0) + 0.5); //四舍五入
		if (opNode == NULL)
		{
			//新建根节点
			opNode = new RecordNode(sid, c, m, e, a);
			rootNode = opNode;
			continue;
		}
		RecordNode *currNode = new RecordNode(sid, c, m, e, a);
		opNode->nextNode = currNode;
		opNode = opNode->nextNode;  //move forward
	}
	for (int i = 0; i < M; i++)
	{
		int sid;
		cin >> sid;
		int ranks[] = { 1, 1, 1, 1 };
		getRankInMatrix(sid, ranks);
		if (ranks[0] == -1)
		{
			cout << "N/A";
			if (i < M - 1)
				cout << endl;
			continue;
		}
		int bestRank = ranks[0];
		int bestRankSubj = 0;
		for (int x = 1; x < 4; x++)
		{
			if (ranks[x] < bestRank)
			{
				bestRank = ranks[x];
				bestRankSubj = x;
			}
		}
		cout << bestRank << " " << ACME[bestRankSubj];
		if (i < M - 1)
			cout << endl;
	}
	return 0;
}

 
 

Categories
生活琐碎

转运JAPAN JSHOPPERS实时监控录像


 
刷新一下就能看到最新的图啦~

Categories
不学无术

以用户为中心的设计

摘自《设计心理学》(中文)第194页
在设计中,应当考虑到以下几个方面:

  • 保证用户能够随时看出哪些是可行的操作(利用各种限制类因素)
  • 注重产品的可视性,包括系统的概念模型、可供选择的操作和操作的结果
  • 便于用户评估系统的工作状态
  • 再用户意图和所需操作之间、操作与结果之间、课件信息与对系统状态的评估之间建立自然匹配关系

换言之,设计人员要确保:1.用户能弄明白操作方法;2.用户能够看出系统的工作状态

Categories
不学无术

与差错相关的设计原则

以下是设计人员应该注意的事项:

  1. 了解各种导致差错的因素,在设计中,尽量减少这些因素;
  2. 使操作者能够撤销以前的指令,或是增加那些不能逆转的操作的难度;
  3. 使操作者能够比较容易地发现并纠正错误;
  4. 改变对差错的态度。要认为操作者不过是想完成某一任务,只是采取的措施不够完美,不要认为操作者是在犯错误。

…一旦你设身处地地想明白人们出错的原因,就会发现大多差错都是可以理解的,而且合乎逻辑。…想办法设计出可以容错的系统,人们正常的行为并非总是准确无误的,要尽量让用户很容易的发现差错,…

——摘自《设计心理学》

Categories
木有技术

Word中不同样式的内容如何强制在同一行上 样式分隔符 正文接排

论文排版中说要“后面正文接排”,就是这种样子
Word正文接排
 
 
 
不同样式的文本内容强制在同一行中
可以使用样式分隔符来隔开。方法是按快捷键ctrl+alt+enter

Categories
木有技术

联想 Thinkpad 4337 扩展坞 底座拆解 拆挡板 教程

亲身时间经历,不过偷懒没有拍照,就挪用别人的照片啦~

 照片来自http://bbs.mydigit.cn/read.php?tid=845798

1.拆掉背面的螺丝(下图红圈处)
1
2.拆掉上测的一颗螺丝(下图红圈处)
2
3.拆掉左上侧的一颗螺丝(红圈)
3
5.用螺丝刀或者其他什么东西,翘下图上方两个绿色箭头所示的位置,把突出的改版翘起,然后沿黄色箭头方向拔出改版
46.盖板掀起后移除下面几个螺丝
57. 掀开整个上部份,下图所示红圈处是挡板的螺丝之一,不远处还有个螺丝。拆掉这两个螺丝后,挡板就自动掉下来了~
6
8.拆挡板到此结束。其他过程参考我上面给的链接。
装回后千万注意那个弹出按钮的可用性,我第一次装回没有调试好,结果本本插上去,那个弹出的按钮按下没反应了,折腾了好久才把本本和底座分离掉。拆解前记住按下按钮是怎么样个机械动作,装回后看看是否是一样的,某个卡扣没按紧或者什么的就容易有问题咯。。
 
 

Categories
木有技术

WNDR3800 openWrt: Enable WiFi toggle

We could just follow the wiki page of WNDR3700 to enable Wifi switch button 🙂
http://wiki.openwrt.org/toh/netgear/wndr3700#activate.the.buttons
Here are the commands for SSH terminal:

opkg update
opkg install wifitoggle
uci set wifitoggle.@wifitoggle[0].button=BTN_2
uci set wifitoggle.@wifitoggle[0].timer=0
uci commit wifitoggle

BTW, these are hardware button keystrokes:

Reset WPS WiFi
Backfire BTN_0 BTN_1 BTN_2
Trunk reset wps BTN_2
Categories
生活琐碎

杭州驾驶证从外地迁入的流程|杭州车管所电话

先是杭州车管所的电话96345转3,或者88945680。
这个电话工作日才有人回复,而且人家中午休息,并且需要等待好久好久才能接通,做好心理准备!


 
需要携带:本人身份证原件,原驾驶证原件,3张一寸白色背景照(现场办理20元一套),身份证复印件一份(现场复印0.5元一份)
另外,户口不在杭州本地的,需携带杭州的暂住证明(且需要在杭州已暂住6个月以上)
流程:

  1. 前往河坊街33号/白石巷1号办理体检及领取换证单。我去河坊街33号办理的,工作时间是周一至周五8:30-11:30,13:30-16:30;此外,县级以上医院也可体检,但是请先前往上述两个地点或车管所领体检单子。体检费收15元。
  2. 弄好之后去古墩路699号的机动车辆管理所继续办理(目前需要找前台预约,我9月5日的预约至10月13日了)
  3. 到预约时间之后,去车管所领号,然后给工作人员办理(5分钟),办理后会把你原来的驾驶证收走;
  4. 接着去25/25号窗口付10元钱工本费,然后在17号窗口等叫到你的名字拿证即可。

还有就是,现在已经不用重新考核科目三之类的东西了。

Categories
不学无术 木有技术

matplotlib 存储到内存文件 save to memory file(buffer) instead of disk file / PyQt4

References:
http://stackoverflow.com/questions/4330812/how-do-i-clear-a-stringio-object
http://stackoverflow.com/questions/8598673/how-to-save-a-pylab-figure-into-in-memory-file-which-can-be-read-into-pil-image
 
In fact Python have a StringIO module to deal with this problem, it works pretty fine with PyQt and matplotlib.
Procedures:
1. [SAVE] Create a StringIO object (or cStringIO which have faster speed)
2. [SAVE] Call savefig method of matplotlib and use the StringIO object instead as the input variable
3. [LOAD] Use QImage to read from StringIO object (via fromData method)
4. [LOAD] Use QPixmap and blabla to show the image….
 
Code:
 

# StringIO with matplotlib test
import matplotlib.pyplot as plt
import cStringIO
from PyQt4 import QtCore, QtGui
import sys
import cPickle
fig = plt.figure()
plt.plot([1, 2])
buf = cStringIO.StringIO()
plt.savefig(buf, format='png')
buf.seek(0)
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.resize(250, 150)
widget.setWindowTitle('simple')
qimg = QtGui.QImage.fromData(buf.getvalue())
pixmap = QtGui.QPixmap.fromImage(qimg)
label = QtGui.QLabel(widget)
label.setPixmap(pixmap)
label.setGeometry(0, 0, 250, 150)
widget.show()
sys.exit(app.exec_())

 
 

Categories
不学无术

PyQt使用线程更新GUI

给几个参考文章:
http://stackoverflow.com/questions/9957195/updating-gui-elements-in-multithreaded-pyqt
http://stackoverflow.com/questions/2585442/sending-custom-pyqt-signals
http://stackoverflow.com/questions/14090353/sending-messages-between-two-widgets-using-signals-and-slots
http://themkbytes.blogspot.com/2012/06/pyqt-qthread-signal-gui-examples.html

Threading with PyQt4