小鸡的小车

from __future__ import *

My Links

Blog统计

公告

吃好,喝好,玩好

文章

收藏

相册

朋友blog

其他

图形学相关

存档


正在读取评论……

2005年11月


Problem Statement
    
When editing a single line of text, there are four keys that can be used to move the cursor: end, home, left-arrow and right-arrow. As you would expect, left-arrow and right-arrow move the cursor one character left or one character right, unless the cursor is at the beginning of the line or the end of the line, respectively, in which case the keystrokes do nothing (the cursor does not wrap to the previous or next line). The home key moves the cursor to the beginning of the line, and the end key moves the cursor to the end of the line.  You will be given a int, N, representing the number of character in a line of text. The cursor is always between two adjacent characters, at the beginning of the line, or at the end of the line. It starts before the first character, at position 0. The position after the last character on the line is position N. You should simulate a series of keystrokes and return the final position of the cursor. You will be given a string where characters of the string represent the keystrokes made, in order. 'L' and 'R' represent left and right, while 'H' and 'E' represent home and end.
Definition
    
Class:
CursorPosition
Method:
getPosition
Parameters:
string, int
Returns:
int
Method signature:
int getPosition(string keystrokes, int N)
(be sure your method is public)
    

Constraints
-
keystrokes will be contain between 1 and 50 'L', 'R', 'H', and 'E' characters, inclusive.
-
N will be between 1 and 100, inclusive.
Examples
0)

    
"ERLLL"
10
Returns: 7
First, we go to the end of the line at position 10. Then, the right-arrow does nothing because we are already at the end of the line. Finally, three left-arrows brings us to position 7.
1)

    
"EHHEEHLLLLRRRRRR"
2
Returns: 2
All the right-arrows at the end ensure that we end up at the end of the line.
2)

    
"ELLLELLRRRRLRLRLLLRLLLRLLLLRLLRRRL"
10
Returns: 3

3)

    
"RRLEERLLLLRLLRLRRRLRLRLRLRLLLLL"
19
Returns: 12

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

我的程序:

#include <string>
#include <iostream>

using namespace std;

class CursorPosition
{
public:
 int getPosition(string keystrokes, int N)
 {
  int result = 0;
  size_t len = keystrokes.length();
  if (len>50 || N<1 || N>100)
  {
   return result;
  }
  for (unsigned int i=0; i<len; ++i)
  {
   switch(keystrokes.at(i))
   {
   case 'L':
    result = result==0 ? 0 : result-1;
    break;
   case 'R':
    result = result==N ? N : result+1;
    break;
   case 'H':
    result = 0;
    break;
   case 'E':
    result = N;
    break;
   }
  }
  return result;
 }
};




Problem Statement
    
A square matrix is a grid of NxN numbers. For example, the following is a 3x3 matrix:
 4 3 5
 2 4 5
 0 1 9
One way to represent a matrix of numbers, each of which is between 0 and 9 inclusive, is as a row-major string. To generate the string, simply concatenate all of the elements from the first row followed by the second row and so on, without any spaces. For example, the above matrix would be represented as "435245019".  You will be given a square matrix as a row-major string. Your task is to convert it into a vector <string>, where each element represents one row of the original matrix. Element i of the vector <string> represents row i of the matrix. You should not include any spaces in your return. Hence, for the above string, you would return {"435","245","019"}. If the input does not represent a square matrix because the number of characters is not a perfect square, return an empty vector <string>, {}.
Definition
    
Class:
MatrixTool
Method:
convert
Parameters:
string
Returns:
vector <string>
Method signature:
vector <string> convert(string s)
(be sure your method is public)
    

Constraints
-
s will contain between 1 and 50 digits, inclusive.
Examples
0)

    
"435245019"
Returns: {"435", "245", "019" }
The example above.
1)

    
"9"
Returns: {"9" }

2)

    
"0123456789"
Returns: { }
This input has 10 digits, and 10 is not a perfect square.
3)

    
"3357002966366183191503444273807479559869883303524"
Returns: {"3357002", "9663661", "8319150", "3444273", "8074795", "5986988", "3303524" }

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

我的程序:

#include <algorithm>
#include <string>
#include <vector>
#include <iostream>

using namespace std;

class MatrixTool
{
public:
 vector<string > convert(string s)
 {
  int sqt[7] = {1, 4, 9, 16, 25, 36, 49};
  vector<string > result;
  int* p = find(sqt, sqt + 7, s.length());
  if (p != sqt + 7)
  {
   unsigned int n = (unsigned int)(p - sqt) + 1;
   size_t len = s.length();
   for (unsigned int i=0; i<len; i+=n)
   {
    result.push_back(s.substr(i, n));
   }
  }
  return result;
 }
};





    摘要:

Problem Statement
    
A simple line drawing program uses a blank 20 x 20 pixel canvas and a directional cursor that starts at the upper left corner pointing straight down. The upper left corner of the canvas is at (0, 0) and the lower right corner is at (19, 19). You are given a vector <string>, commands, each element of which contains one of two possible commands. A command of the form "FORWARD x" means that the cursor should move forward by x pix    (全文共11119字)——点击此处阅读全文





    摘要:

著名的ASCII动画。

观看方法:telnet towel.blinkenlights.nl

    (全文共59字)——点击此处阅读全文




    摘要:北航保安    (全文共494字)——点击此处阅读全文




    摘要:

从九月份开始去张贝,已经两个月了,这两个月,去了不到20次吧,但是感觉效果还是不错的,每次都坚持一个流程,这段时间下来,感觉身上的肉明显硬了许多,而且也感觉精力更旺盛了。

虽然说晚上下班了去折腾,应该会更累,但是我一直没感觉影响我白天的精神,相反,感觉精神更好了,人就是这样,越待着,就会越没精神,累一点,反而充满活力了。

张贝比浩沙最大的好处,就是离家比较近,下班了,先去吃个饭,然后上上网消化消化,再慢悠悠骑车过去,感觉非常爽,如果下班直接去健身,会感觉非常累,休息这么一小会,感觉好多了。

每次去之前,都有点不想,因为懒得出去,但是如果挣扎过来,到了那里,就会很兴奋,不想回来了,每次都是这样,这就叫做坚持吧,只要坚持下去,就会获得好的回报。

坚持,还是坚持,天气慢慢冷了,我一定要坚持下去。争取半年后,让身上的赘肉滚蛋,有个比较不错的身材。嗯。

    (全文共407字)——点击此处阅读全文




    摘要:接着上篇文章继续说    (全文共123字)——点击此处阅读全文




    摘要:本人主要从事图形图象工作,空闲之余接触了一些游戏编程,特写一些编程心得,本文适合没有接触过人物动画编程的初学者,希望游戏制作的大虾们指点,交流。    (全文共152字)——点击此处阅读全文