Считываем показания весов adam hcb 1002 под Linux

Есть весы, есть линукс, надо научиться получать с них показания и использовать в своей программе.

Шаг 1 — настройка весов — они должны находиться в счетном режиме, что бы мы получали данные один раз, после стабилизации. Прикладываю скрин из инструкции (кликабельно)

adamШаг 2 — подключение. Есть два варианта — USB и RS232. Работают оба. Особых параметров после подключения выставлять не надо, должно работать, может не помешать выставление рейта — stty -F /dev/ttyS0 ispeed 4800 ospeed 4800 . В данном случае скорость передачи 4800, нужно выставить такую же на весах, а также выставить тип подключения, USB или RS. Читать далее Считываем показания весов adam hcb 1002 под Linux


An interesting one. Amazingly, you can solve it with a little effort.


Alice and Bob have a lawn in front of their house, shaped like an N metre by M metre rectangle. Each year, they try to cut the lawn in some interesting pattern. They used to do their cutting with shears, which was very time-consuming; but now they have a new automatic lawnmower with multiple settings, and they want to try it out.

The new lawnmower has a height setting — you can set it to any height h between 1 and 100 millimetres, and it will cut all the grass higher than h it encounters to height h. You run it by entering the lawn at any part of the edge of the lawn; then the lawnmower goes in a straight line, perpendicular to the edge of the lawn it entered, cutting grass in a swath 1m wide, until it exits the lawn on the other side. The lawnmower’s height can be set only when it is not on the lawn.

Alice and Bob have a number of various patterns of grass that they could have on their lawn. For each of those, they want to know whether it’s possible to cut the grass into this pattern with their new lawnmower. Each pattern is described by specifying the height of the grass on each 1m x 1m square of the lawn.

The grass is initially 100mm high on the whole lawn.


The first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with a line containing two integers: N and M. Next follow N lines, with the ith line containing M integers ai,j each, the number ai,j describing the desired height of the grass in the jth square of the ith row.


For each test case, output one line containing «Case #x: y», where x is the case number (starting from 1) and y is either the word «YES» if it’s possible to get the x-th pattern using the lawnmower, or «NO», if it’s impossible (quotes for clarity only).


1 ≤ T ≤ 100.

Small dataset

1 ≤ N, M ≤ 10.
1 ≤ ai,j ≤ 2.

Large dataset

1 ≤ N, M ≤ 100.
1 ≤ ai,j ≤ 100.


Input Output
3 3
2 1 2
1 1 1
2 1 2
5 5
2 2 2 2 2
2 1 1 1 2
2 1 2 1 2
2 1 1 1 2
2 2 2 2 2
1 3
1 2 1
Case #1: YES
Case #2: NO
Case #3: YES

Читать далее Lawnmower

Om-nom-nom-nom, I need a palindrome

In fact, I needed a number that is a palindrome and the square of a palindrome for Google Code Jam.  The task was to find all such numbers in the given interval.


Little John likes palindromes, and thinks them to be fair (which is a fancy word for nice). A palindrome is just an integer that reads the same backwards and forwards — so 6, 11 and 121 are all palindromes, while 10, 12, 223 and 2244 are not (even though 010=10, we don’t consider leading zeroes when determining whether a number is a palindrome).

He recently became interested in squares as well, and formed the definition of a fair and square number — it is a number that is a palindrome and the square of a palindrome at the same time. For instance, 1, 9 and 121 are fair and square (being palindromes and squares, respectively, of 1, 3 and 11), while 16, 22 and 676 are not fair and square: 16 is not a palindrome, 22 is not a square, and while 676 is a palindrome and a square number, it is the square of 26, which is not a palindrome.

Now he wants to search for bigger fair and square numbers. Your task is, given an interval Little John is searching through, to tell him how many fair and square numbers are there in the interval, so he knows when he has found them all.

Solving this problem

Usually, Google Code Jam problems have 1 Small input and 1 Large input. This problem has 1 Small input and 2 Large inputs. Once you have solved the Small input, you will be able to download any of the two Large inputs. As usual, you will be able to retry the Small input (with a time penalty), while you will get only one chance at each of the Large inputs.


The first line of the input gives the number of test cases, T. T lines follow. Each line contains two integers, A and B — the endpoints of the interval Little John is looking at.


For each test case, output one line containing «Case #x: y», where x is the case number (starting from 1) and y is the number of fair and square numbers greater than or equal to A and smaller than or equal to B.


Small dataset

1 ≤ T ≤ 100.
1 ≤ AB ≤ 1000.

First large dataset

1 ≤ T ≤ 10000.
1 ≤ AB ≤ 1014.

Second large dataset

1 ≤ T ≤ 1000.
1 ≤ AB ≤ 10100.

Читать далее Om-nom-nom-nom, I need a palindrome

Summarizing binary numbers



Bytelandian gold coins


In Byteland they have a very strange monetary system.

Each Bytelandian gold coin has an integer number written on it. A coin n
can be exchanged in a bank into three coins: n/2, n/3 and n/4.
But these numbers are all rounded down (the banks have to make a profit).

You can also sell Bytelandian coins for American dollars. The exchange
rate is 1:1. But you can not buy Bytelandian coins.

You have one gold coin. What is the maximum amount of American dollars
you can get for it?


The input will contain several test cases (not more than 10). Each
testcase is a single line with a number n, 0 <= n <= 1 000 000 000.
It is the number written on your coin.


For each test case output a single line, containing the maximum amount
of American dollars you can make.




You can change 12 into 6, 4 and 3, and then change these into
$6+$4+$3 = $13.

If you try changing the coin 2 into 3 smaller coins, you will get
1, 0 and 0, and later you can get no more than $1 out of them.
It is better just to change the 2 coin directly into $2.

Time Limit: 9 sec
Source Limit: 50000 Bytes



Читать далее Bytelandian gold coins