书感

书感

入大学四月有余,不觉中从图书馆借来了50多本书充实自己的大学生活。大约统计了一下,其中四成是计算机书籍,三成是人文社科书籍,另外三成是数学等其他书籍。这些书里面,正在读的有14本,认认真真读完的约有10多本,剩下的那二十多本不是草草读完,就是读了三两章后弃置一旁,等待着顺便还回图书馆。现在想想,那些草草读完的书,大多都是毫无养料、大话连篇的废书。而那些我只读了两三章的书则是高深难懂,技术味十足的专业书,读不完不是我不能持之以恒,而是知识缺失太多,无法跟着作者大步向前。即便这样,我觉得那十多本细读的书和手中这14本正在阅读中的书依然给了我极大的收获,甚至大于这四个月大学所给予我的总和。
高中时期,每日摆在书架上的尽是教辅书籍和练习册,很少有时间能够沉浸在自己的世界里,阅读自己想了解的万千世界。而大学则不同,尽管大一新生总是会被拉去出观众,总是会被强制自习,依然能够腾出时间去阅读。为什么我说读书的收获会大于我的大学生活?来到大学之后,我发现学得很多东西都跟本没有用。例如普通化学,学的什么反应速率,溶解平衡什么的,谁将来没事每天算那个啊……
鉴于总是有那些特别的书(指的是那些读了一半就读不下去和草草读完的书),我在最近的图书选择中参考了一些大神们的阅读目录,比如说《暗时间》参考了http://definiter.net/archives/2787.html,《影响力》参考了http://www.ruanyifeng.com/blog/2013/08/influence_the_psychology_of_persuasion.html等等。
下面列出了我细读的书目名录,和正在阅读中的书目名录:

正在阅读书单:
Python编程入门经典 / (美) James Payne著
梦断代码 / (美) Scott Rosenberg著
普林斯顿微积分读本 / (美) Adrian Banner著
浪潮之巅.上册.第2版 / 吴军著
浪潮之巅.下册.第2版 / 吴军著
计算机程序设计艺术.第1卷.第1册.Volume 1.Fascicle 1,MMIX:新千年的RISC计算机,MMIX: a risc computer fo / (美) Donald E.Knuth著
影响力:the psychology of persuasion / (美) 罗伯特·西奥迪尼著
编程珠玑 / (美) Jon Bentley著
程序员的数学 / (日) 结城浩著
暗时间 / 刘未鹏著
黑客与画家:来自计算机时代的高见 / (美) Paul Graham著
算法竞赛入门经典训练指南 / 刘汝佳, 陈锋编著
(我列出的书单少于14本,是因为其中有几本我觉得写的不太好,就没列出来)

细读书单:
三体 / 刘慈欣著
大话处理器:处理器基础知识读本 / 万木杨编著
黑客的代码 / (美) 马克·拉希诺维奇著
天使与魔鬼.第2版 / (美) 丹·布朗著
C++ Primer Plus(第6版)中文版 / (美) Stephen Prata著
ACM国际大学生程序设计竞赛:题目与解读 / 俞勇主编
Linux C编程从入门到精通 / 刘学勇编著(这本书里面有些代码有点问题,不知道为什么)
数学之美 / 吴军著
Linux/Unix设计思想 / (美) Mike Gancarz著
ACM国际大学生程序设计竞赛亚洲区预选赛真题题解 / 郭炜, 姚金宇, 陈峰宏著

改造HUSTOJ

前些日子高中的竞赛老师想让我准备一套oj的搭建方案,准备给我的学弟们用,要求是有认证过的登录帐号的同学才能访问试题等内容。
综合考虑之后,提出了以下几种方案:
1.hustoj+修改端口
2.hustoj+php更改
由于没有php经验,觉得第一种方案比较合适,第二种方案可以试一试。于是着手php的修改。经过实验,需要修改如下几个文件:

/oj-header.php
/register.php
/admin/privilege_add.php
/admin/privilege_checkin.php
/admin/privilege_list.php

首先是oj-header.php的修改,在里面添上这么一段:
after line 1:

if (!(isset($_SESSION['administrator'])||
      isset($_SESSION['contest_creator'])||
      isset($_SESSION['problem_editor'])||
      isset($_SESSION['student']))&&
      $_SERVER['PHP_SELF']!='/loginpage.php'&&$_SERVER['PHP_SELF']!='/registerpage.php'){
     echo "<a href='../loginpage.php'>Please Login First!</a";  
     echo "<a >   Or   </a>";  
     echo "<a href='../registerpage.php'>Register First!</a>";  
     exit(1);  
 }  

作用是全站判断登陆者权限,是否可以访问当前页面;

之后是register.php的修改,同样添上一段:
after line 85:

$sql="insert into `privilege` values('$user_id','checkin','N')";

mysql_query($sql);

作用是默认添加checkin权限,等待管理员审核;

紧接着轮到admin文件夹下的文件修改,其中包括用户的审核和用户的管理。

第一个文件privilege_add.php:
line 23:

$rightarray=array("administrator","problem_editor","source_browser","contest_creator","http_judge","password_setter" );  

改为

$rightarray=array("administrator","problem_editor","source_browser","contest_creator","http_judge","student","password_setter" );

作用是增添一个student用户组;

第二个是一个新文件privilege_checkin.php:
line 1:

<?php require_once("admin-header.php");?>
<?php require_once("../include/check_get_key.php");
if (!(isset($_SESSION['administrator']))){
    echo "<a href='../loginpage.php'>Please Login First</a>";
    exit(1);
}
if(isset($_GET['uid'])){
    $user_id=mysql_real_escape_string($_GET['uid']);
    $rightstr =mysql_real_escape_string($_GET['rightstr']);
    $sql="delete from `privilege` where user_id='$user_id' and rightstr='$rightstr'";
    mysql_query($sql);
    $sql="insert into `privilege` values('$user_id','student','N')";
    mysql_query($sql);
    if (mysql_affected_rows()==1) echo "$user_id $rightstr checkin!";
    else echo "No such privilege!";
}
?>

<script language=javascript>
    window.setTimeOut(1000,"history.go(-1)");
</script>

作用是删除用户的默认checkin权限,增添student权限;
第三个文件privilege_list.php:
line 9:

$sql="select * FROM privilege where rightstr in ('administrator','source_browser','contest_creator','http_judge','problem_editor') ";

改为:

$sql="select * FROM privilege where rightstr in ('administrator','source_browser','contest_creator','checkin','student','http_judge','problem_editor') ";

after line 20:

if($row->rightstr=='checkin')echo "<td><a href=privilege_checkin.php?uid=$row->user_id&rightstr=$row->rightstr&getkey=".$_SESSION['getkey'].">Checkin</a>";

作用是显示用户权限列表,增添一个Checkin链接;

至此,第二种方案的文件更改完成。可惜的是高中服务器不让使用数据库,没法自己搭建oj了……坑爹的教育局……

HDU 1159

Common Subsequence

Problem Description

A subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, …, xm > another sequence Z = < z1, z2, …, zk > is a subsequence of X if there exists a strictly increasing sequence < i1, i2, …, ik > of indices of X such that for all j = 1,2,…,k, xij = zj. For example, Z = < a, b, f, c > is a subsequence of X = < a, b, c, f, b, c > with index sequence < 1, 2, 4, 6 >. Given two sequences X and Y the problem is to find the length of the maximum-length common subsequence of X and Y.
The program input is from a text file. Each data set in the file contains two strings representing the given sequences. The sequences are separated by any number of white spaces. The input data are correct. For each set of data the program prints on the standard output the length of the maximum-length common subsequence from the beginning of a separate line.

Sample Input

abcfbc abfcab
programming contest
abcd mnp

Sample Output

4
2
0

题解:

经典动态规划,最长公共子序列。

动态转移方程:

1
2
3
4
5
if(a[i-1]==b[j-1])
{
f[i][j]=f[i-1][j-1]+1;
}
else f[i][j]=max(f[i][j-1],f[i-1][j]);

源代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int maxx(int a,int b)
{

return a>b?a:b;
}
int main()
{

char a[502],b[502];
int i,j,k;
int f[502][502];
while(scanf("%s%s",a,b)!=EOF)
{
int lena,lenb;
lena=strlen(a);
//printf("%d--\n",lena);
lenb=strlen(b);
//printf("%d---\n",lenb);
memset(f,0,sizeof(f));
for(i=1;i<=lena;i++)
{
for(j=1;j<=lenb;j++)
{
if(a[i-1]==b[j-1])
{
f[i][j]=f[i-1][j-1]+1;
}
else f[i][j]=maxx(f[i][j-1],f[i-1][j]);
}
}
printf("%d\n",f[lena][lenb]);
}
return 0;
}

开始刷题了

准备开始刷题了~~刷hdu题库!!目标:春节前刷够150题。争取这段时间能够把所有A过的题的题解和标程都发上来~~就从hdu的1000开始吧!

HEU日常训练10.02

这套题就看了两道,先发上来这两个最水的题解

第一题

H - H

Time Limit:3000MS Memory Limit:0KB

Description

Trung is bored with his mathematics homeworks. He takes a piece of chalk and starts writing a sequence of consecutive integers starting with 1 to N(1 < N < 10000) . After that, he counts the number of times each digit (0 to 9) appears in the sequence. For example, with N = 13 , the sequence is:
12345678910111213
In this sequence, 0 appears once, 1 appears 6 times, 2 appears 2 times, 3 appears 3 times, and each digit from 4 to 9 appears once. After playing for a while, Trung gets bored again. He now wants to write a program to do this for him. Your task is to help him with writing this program.

Input

The input file consists of several data sets. The first line of the input file contains the number of data sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.
For each test case, there is one single line containing the number N .

Output

For each test case, write sequentially in one line the number of digit 0, 1,…9 separated by a space.

Sample Input

2
3
13

Sample Output

0 1 1 1 0 0 0 0 0 0
1 6 2 2 1 1 1 1 1 1

思路:
枚举加统计
代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>
int freq[10];
void count(int n)
{

do
{
freq[n%10]++;
n/=10;
}while(n!=0);
}
int main()
{

int i,t,n;
scanf("%d",&t);
while(t--)
{
for (i=0;i<10;i++)
freq[i]=0;
scanf("%d",&n);
for (i=1;i<=n;i++)
count(i);
for (i=0;i<10;i++)
if (i!=9)
printf("%d ",freq[i]);
else
printf("%d\n",freq[i]);
}
return 0;
}

第二题

J - J

Time Limit:2000MS Memory Limit:262144KB

Description

Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.

Input

The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line contains N space-separated integers li — the lengths of th无标题文档e bars. All the lengths are natural numbers not exceeding 1000.

Output

In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.

Sample Input

Input

3
1 2 3

Output

1 3

Input

4
6 5 6 7

Output

2 3
思路:
排序加统计
代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

int main()
{

int n,i,j,temp;
int a[1001];
int max;
int sum;
sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[j]<a[i])
{
temp=a[j];
a[j]=a[i];
a[i]=temp;
}
}
}
max=1;
for(i=0;i<n;i++)
{
sum++;
temp=1;
for(j=i+1;j<n;j++)
{
if(a[j]==a[i])
{
temp++;
}
else
{
break;
}
}
if(temp>max)
{
max=temp;
}
i=j-1;
}
printf("%d %d\n",max,sum);
return 0;
}