Các bạn vui lòng dùng từ ngữ lịch sự và có văn hóa,sử dụng Tiếng Việt có dấu chuẩn. Chúc các bạn vui vẻ!
20/12/2013 08:12 # 1
Cấp độ: 13 - Kỹ năng: 8

Kinh nghiệm: 5/130 (4%)
Kĩ năng: 39/80 (49%)
Ngày gia nhập: 21/03/2011
Bài gởi: 785
Được cảm ơn: 319
[code- solv] two gangster

1409. Two Gangsters

Time limit: 1.0 second
Memory limit: 64 MB
Two gangsters Harry and Larry had a rest at countryside. They decided to spend some time shooting, so they put several beer cans (no more than 10) on a log. Harry started to shoot cans one after another from the leftmost to the right and Larry – from the rightmost to the left. At some moment it happened so that they shot one and the same can.
Harry got indignant and claimed that Larry owed him a considerable sum of money because Larry deprived him of shooting some more cans. Larry became furious and told Harry that he owed even greater sum of money to Larry because of the same reason. They started to argufy but nobody remembered how many cans there were at the very beginning. And no one of them was going to search cans which was shot. Anyway, each of them remembered exactly how many cans he shot.
Determine how many cans were not shot by Harry and how many cans were not shot by Larry.


The only input line contains two integers — the number of cans shot by Harry and by Larry respectively.


two integers — the number of cans that were not shot by Harry and the number of cans that were not shot by Larry, respectively.


input output
4 7
6 3

Again, this problem is marked as for ‘High School Pupils’, which means it very easy. However, just try to read through the problem description before looking for answers. This will improve your ability of problem solving/analysis.

The two gangsters shooting from both directions, one from left, the other from the right. They will eventually shoot the same one in the middle. Therefore, the total number of beer cans equal to two numbers (shots by both) minus one.

H H H H (HL) L L L L L

The total number = 5 (H) + 6 (L) – 1 = 10

The questions asks for the cans not shot by each other.

Answer for ‘cans not shot by Harry’ is L – 1, Answer for ‘cans not shot by Larry’ is is H – 1.

The solution is to print L – 1, H – 1 (given numbers minus one, reverse order)

#include <iostream>
using namespace std;
int main()
  int a, b;
  cin >> a >> b;
  cout << b - 1 << a - 1;
  return 0;

Or, if you prefer pure C.

#include <stdio.h>
int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d %d", b - 1, a - 1);
    return 0;


----source : codecrazy -----


Cuộc đời là một dòng sông. Ai không bơi thì chết. 

Name: Tien (Tory) TRAN

Copyright© Đại học Duy Tân 2010 - 2019