ZJU 2420 解题报告

Calendar

Time Limit: 1 Seconds Memory Limit: 32768 KB

A calendar is a system for measuring time, from hours and minutes, to months and days, and finally to years and centuries. The terms of hour, day, month, year and century are all units of time measurements of a calender system.

According to the Gregorian calendar, which is the civil calendar in use today, years evenly divisible by 4 are leap years, with the exception of centurial years that are not evenly divisible by 400. Therefore, the years 1700, 1800, 1900 and 2100 are not leap years, but 1600, 2000, and 2400 are leap years.

Given the number of days that have elapsed since January 1, 2000 A.D, your mission is to find the date and the day of the week.

Input

The input consists of lines each containing a positive integer, which is the number of days that have elapsed since January 1, 2000 A.D. The last line contains an integer -1, which should not be processed. You may assume that the resulting date won’t be after the year 9999.

Output

For each test case, output one line containing the date and the day of the week in the format of “YYYY-MM-DD DayOfWeek”, where “DayOfWeek” must be one of “Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday” and “Saturday”.

[……]

Continue

《C程序设计语言》习题解

T1.15,重新编写1.2节中的温度转换程序,使用函数实现温度转换。

#include
int fahrToCel(int fahr)
{
  return 5 * (fahr - 32) / 9;
}
int main()
{
  int fahr, cel;
  int lower, upper, step;
  lower = 0;
  upper = 300;
  step = 20;
  fahr = lower;
  while (fahr < upper) {
      cel = fahrToCel(fahr);
      printf("%d\t%d\n", fahr, cel);
      fahr += step;
  }
  return 0;
}

T1.16,修改打印最长文本行的程序的主程序main,使之可以打印任意长度的输入行的长度,并尽可能多的打印文本。

#include
#define MAXLEN 1000
int getLine(char *s);
void copy(char *to, char *from);
int main()
{
  int len, maxLen;
  char line[MAXLEN], maxLine[MAXLEN];
  maxLen = 0;
  while((len = getLine(line)) != 0) {
      printf("%d %s\n", len, line);
      if(len > maxLen) {
          copy(maxLine, line);
          maxLen = len;
      }
  }
  if(maxLen > 0) printf("%s\n", maxLine);
  return 0;
}
int getLine(char *s)
{
  int i = 0;
  while((s[i] = getchar()) != '\n') i++;
  s[i] = '\0';
  return i;
}
void copy(char *to, char *from)
{
  int i = 0;
  while((to[i] = from[i]) != '\0') i++;
}

[......]

Continue

SDCC第一章手册翻译

最近开始使用SDCC编译器,本来想详细写点SDCC的文章,不过一直没有解决单片机在Linux平台下的烧录问题,所以计划暂时停止了.没事干,先翻译一下 SDCC Manual 第一章的内容!希望对大家有所帮助.不过我这人做事常常有头无尾,所以不太可能把整个手册都翻译好!

SDCC开发比较活跃,不同时期的Manual可能会有些变化,我这翻译的时候Revision是6253.新版本可能会略有一些变化,总体变化不会很大.我的英语不是很好,既不是英语专业的也不是计算机专业的,还不是电气专业的,翻译中难免(可能性很大)会出现的错误,优先建议你去读SDCC Manual的原文,英语不好再考虑对照这篇文章读原文,迫不得已再直接读我的中文翻译.

Chapter 1

简介

1.1 关于SDCC

SDCC(Small Device C Compiler)是 Sandeep Dutta 为8位微处理器设计的开源,可重用,经过优化的ANSI-C交叉编译器.当前版本的目标平台为Intel MCS51兼容单片机(8031, 8032, 8051, 8052系列), Dallas 的 DS80C390 及其衍生产品, Freescale(原属于 Motorola)的 HC08 和基于 Zilog Z80 的兼容单片机.SDCC 也可支持其他单片机,PIC 支持正在开发中.整个编译器源代码在GNU通用公共许可证(GPL)下发布. SDCC 使用 ASXXXX 和 ASLINK 的修改版本作为交叉编译工具和链接工具. SDCC 针对各种单片机进行有效的拓展,可以更好的使用基本的硬件资源.

此外,SDCC 对单片机做了大量标准优化,例如:

  • 全局表达式消除
  • 循环优化(无操作循环优化,归纳变量循环优化,你循环优化)
  • 重复常量合并
  • 复制传播
  • 无效代码清楚
  • switch语句的跳转优化

[……]

Continue

最短路寻线智能小车(智能出租车)

前几周和舍友一起参加学院的电子设计大赛。这是为我们的小车写的报告。这是我第一次比较规范的写代码,做点有项目性质的东西,也是第一次做单片机上的编程,整体比较粗糙。高手看了别见笑。如果有什么错误欢迎大家指出来,交流使人进步!

一.系统方案选择与论证

1.1.设计要求

1.1.1.任务

设计制作一个智能小车模型,在一份已知地图上从指定起点出发通过计算最短路径选择最佳路线到达终点。每个节点为一个“十”字交叉路口。

1.1.2.要求

根据任务要求我们为自己的设计确定了以下目标:

基本部分:

  1. 计算从起点到终点的最短路径。
  2. 在每个节点通过转向选择一条路线到达下一个节点。
  3. 从一个节点到下一个节点进行寻线操作。
  4. 到达一个节点能够自动停车。

1.2.系统方案对比论证

1.2.1.系统总体方案设计论证

本系统大体上分为四个基本模块,它们的关系可由如下方框图示意

1.2.2.各模块方案选择与论证

1.2.2.1.车体设计

方案 1:自己制作电动小车。但自己制作的车体比较粗糙,对于寻线小车,车身重量以及平衡都要有精确的测量,而且也要控制好小车行驶的路线和转弯的力矩及角度,这些都比较难良好地实现。

方案 2:购买具有组装完整的车架车轮。使用两轮驱动并配置万向轮,选用转轴力矩大的减速电机来提供动力及精确调节转弯。 成品的车架车轮由于装配紧凑,使得各种所需电路的安装十分方便,看起来也比较美观。而且这种电动车一般都价格适中。

基于以上分析,我们选择方案2。

[……]

Continue

ZJU 3464 解题报告

Rugby Football

Time Limit: 2 Seconds Memory Limit: 65536 KB

CM is a member of Rugby football club of ZJU. He loves to play the game. Every Friday afternoon there is a club training of skills. CM wants to make it more effective.

In the training, N club members including CM stand at staring line in a row. The maximum velocity of the i-th player is Vi. The distance between the line and touchdown zone is L. The goal is to send the ball to touchdown zone. They can pass the ball to others but forward passing is illegal. If someone reaches touchdown zone with ball, the team scores and it will be an effective training.

This picture illustrate the rule of passing ball.

But the way to scoring is not easy because of crazy opponents. Any player with the ball cannot rush more than T seconds or he will be tackled. And he cannot be passed again because he will be very tired after sprinting; even have not for T seconds enough. At the beginning CM can choose who takes the ball first. Now CM wants to know whether they can score and how fast they can.

[……]

Continue

ZJU 2876 解题报告

Phone List

Time Limit: 5 Seconds Memory Limit: 32768 KB

Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let’s say the phone catalogue listed these numbers:
– Emergency 911
– Alice 97 625 999
– Bob 91 12 54 26

In this case, it’s not possible to call Bob, because the central would direct your call to the emergency line as soon as you had dialled the first three digits of Bob’s phone number. So this list would not be consistent.

Input

The first line of input gives a single integer, 1 <= t <= 40, the number of test cases. Each test case starts with n, the number of phone numbers, on a separate line, 1 <= n <= 10000.Then follows n lines with one unique phone number on each line. A phone number is a sequence of at most ten digits.

Output

For each test case, output “YES” if the list is consistent, or “NO” otherwise.

[……]

Continue

ZJU 2829 解题报告

Beautiful Number

Time Limit: 1 Seconds Memory Limit: 32768 KB

Mike is very lucky, as he has two beautiful numbers, 3 and 5. But he is so greedy that he wants infinite beautiful numbers. So he declares that any positive number which is dividable by 3 or 5 is beautiful number. Given you an integer N (1 <= N <= 100000), could you please tell mike the Nth beautiful number?

Input

The input consists of one or more test cases. For each test case, there is a single line containing an integer N.

Output

For each test case in the input, output the result on a line by itself.

[……]

Continue

ZJU 2723 解题报告

Semi-Prime

Time Limit: 1 Seconds Memory Limit: 32768 KB

Prime Number Definition

An integer greater than one is called a prime number if its only positive divisors (factors) are one and itself. For instance, 2, 11, 67, 89 are prime numbers but 8, 20, 27 are not.

Semi-Prime Number Definition

An integer greater than one is called a semi-prime number if it can be decompounded to TWO prime numbers. For example, 6 is a semi-prime number but 12 is not.

Your task is just to determinate whether a given number is a semi-prime number.

Input

There are several test cases in the input. Each case contains a single integer N (2 <= N <= 1,000,000)

Output

One line with a single integer for each case. If the number is a semi-prime number, then output “Yes”, otherwise “No”.

[……]

Continue

ZJU 2744 解题报告

Palindromes

Time Limit: 1 Seconds Memory Limit: 32768 KB

A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string “ABCDEDCBA” is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left.

Now give you a string S, you should count how many palindromes in any consecutive substring of S.

Input

There are several test cases in the input. Each case contains a non-empty string which has no more than 5000 characters.Proceed to the end of file.

Output

A single line with the number of palindrome substrings for each case.

[……]

Continue

我的Debian GNU/Linux——内核编译篇

距离上一篇”我的Debian GNU/Linux——安装篇“已经过去了快三个月了,本人不但很菜还很懒,加上一堆乱七八糟的考试都在年底,这篇关于内核编译的文章就一拖再拖.自己配置编译了几次内核,觉得对整个过程还是比较熟悉的.虽然对于普通用户编译内核没有多大意义.

在动手编译之前我想说Debian自带的默认内核已经包含了绝大部分配置,完全可以满足一般用户的需求,对于编译自己的内核是否有必要也是一个值得考虑的问题,编译内核是需要大量的时间(取决于您的硬件配置).如果基于以下理由,编译新内核还是很有用的:

  • 支持某些特殊的硬件,或者默认的内核配置和某些硬件冲突
  • 使用某些不为所提供的内核支持的选项
  • 通过删除无用的驱动程序来优化内核,以减少启动时间
  • 创建整体的而不是模块化的内核
  • 运行最新的内核或开发中的内核
  • 深入了解linux 内核

网络上关于编译内核基本是按照linux编译软件三步走的方式(配置,make,make install),我并不喜欢这个,软件包管理起来很不方便.按照Debian的方式编译是个很好的选择,编译结束就生成一个deb软件包,安装卸载都很容易.

[……]

Continue