lovro-sinda's blog

By lovro-sinda, 10 years ago, In English
  1. In certain problems we can use an array of integers to solve the problem. But those can also be solved by using array of vectors. On which factors should I decide whether to use plain array of integers or array of vectors? If vectors, then what are the advantages?

  2. Can function write in C++ return more than one values?

  3. Can anyone tell me whats exact stack limit for c++ and can we increase it in some way from code?

  4. Is true that vector increasing size by 2,4,8,16...? If it is are vector still increasing after will write resize?

  5. What is complexity of memset(C++)? Is that faster then BF method?

  6. In what type of data do you keep binary tree at your C++ program? And what is the best way to do it?

  7. Is there any difference between char, string, vector in time complexity of processing(input, output...)?

  8. I read about function nth_element on STL. Can anyone help me to implement it because how I can understand it's cool function in linear time complexity.

  9. What is the difference between I write double pi = 3.14159; or #define pi 3.14159?

  10. Is there any link on the Internet on page or book title like: "Hasing for dummies "

Full text and comments »

  • Vote: I like it
  • +29
  • Vote: I do not like it

By lovro-sinda, 10 years ago, In English

First I want you to read the task and try to solve it in linear time complexity, and minimum memorize complexity.

Lonely Integer
There are N integers in an array A. All but one integer occurs in pairs. Your task is to find out the number that occurs only once.

Input Format

The first line of the input contains an integer N indicating number of integers in the array A. The next line contains N integers each separated by a single space. Constraints 1 <= N < 100 N % 2 = 1 ( N is an odd number ) 0 <= A[i] <= 100, ∀ i ∈ [1, N]

Output Format

Output S, the number that occurs only once.
Sample Input
3
1 1 2
Sample Output
2

If you don't have any idea I will write a code.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
 	int N;
	cin >> N;
	int tmp, result = 0;
	for (int i = 0; i < N; i++) {
		cin >> tmp;
		result ^= tmp;
	}
	cout << result;
    return 0;
}

Cool trick using only xor operation, but I can't prove why that work. Can anyone prove it?

Full text and comments »

  • Vote: I like it
  • -20
  • Vote: I do not like it

By lovro-sinda, 10 years ago, In English

The number is the "law" if it consists only of digits 3 and 5 or if it is divisible by the number that is law.
For example, the numbers 3, 53, 66, 106 are "law" numbers, and 16, 34 and 56 did not.
How many there are "Law" numbers greater than or equal to A and smaller than or equal to B?

input
The first line contains two integers A and B (1 ≤ A ≤ B ≤ 10^9).
output
The first and only line of output as the "law" of numbers in the interval [a, b].


Examples:


entrance
1 10
output
5


entrance
171 822
output
315


Any idea how to solve it?

Full text and comments »

  • Vote: I like it
  • +16
  • Vote: I do not like it

By lovro-sinda, 10 years ago, In English

A new season, marks the beginning of many things new. And we cherish them all. As we enter into the second half of the year, we look forward to make it surpass its precursor in terms of excitement, fun, and some delicious crunchy contests. Just like the monsoon snacks, you enjoy sitting on your porch watching the rain drops drip down the windowpane. And we start with our June Challenge 2014.

Keeping up with the picturesque view around, our problem-setting panel is adorned by some of the finest programmers from across the world. Like the first rain of the season, you surely would not want to miss the June Challenge.

So, here are the details of the contest:

Start Date: Friday, 6th June, 2014 at 15:00 HRS (IST)
End Date: Monday, 16th June, 2014 at 15:00 HRS (IST)
Link: June Challenge 2014.  -> http://www.codechef.com/JUNE14/

Know the contest timing in your region here.

We hope you all will make a big spatter with your performance. So, join in the June Challenge 2014 and pour in the submissions for next ten days.

To add a tad more color to your grounding for the contest, we have the editorials of the hot and sizzling May contests. Go enjoy them, with the June contest and rainproof your preparations.

Editorials - May Challenge 2014
Editorials - May Lunchtime 2014
Editorials - May Cook-Off 2014

That is all from the chef’s kitchen for the first monsoon contest. Wind down and make a splash.

For any doubts, queries, or some monsoon greetings, you can write to us at [email protected].

Alternatively, you can also call us at: +91 — (22) — 30797709 (On Weekdays between 11:00 am to 8:00 pm).

Love & Luck!

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it

By lovro-sinda, 10 years ago, In English

The given is N non-negative numbers, select exactly K who provide minimal result of OR operation (binary OR operation).

Input The first line contains an integer N (1 ≤ K ≤ N ≤ 50). The next line contains N integers not exceeding 1000 000 000

Output

Print result of OR operation selected K numbers.

Examples:

entrance

2 2
1 3

output

3

entrance

6 3
5 2 4 1 7 5

output

5

Any ideas how to solve it?

Full text and comments »

  • Vote: I like it
  • +9
  • Vote: I do not like it

By lovro-sinda, 10 years ago, In English

Can anyone help with this task.

Given a sequence of N different integers. Operations allowed members of the series are:

  • Move to the beginning of the sequence

  • Move to the end of the sequence

Print the smallest number of necessary operations to a default set of ascending sorted.

For example:

Input

4

3 4 2 1

Output

2

Thank you.

Full text and comments »

Tags dp, task
  • Vote: I like it
  • +5
  • Vote: I do not like it

By lovro-sinda, 10 years ago, In English

Can anyone please help me with my solution. Codeforces evaluator say that is crashed, but I can normaly test it.

Link: http://codeforces.me/contest/433/submission/6708852

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By lovro-sinda, 11 years ago, In English

We have a sequence. What is the smallest number should be removed to sequence be a growing array?

Example: 5 1 2 4 3 6 4 6

If left sequence 1 2 4 6 then we kicked four numbers.

And if you leave the series 1 2 3 4 6 then we threw three the number of which is better than four.

So answer is 3. Can anyone have any idea how to solve by DP? Sorry for bad English.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By lovro-sinda, 12 years ago, In English

Can you write a faster way to check is number N prime?

http://collabedit.com/fj2dc

Write in URL.

Thank you

Full text and comments »

  • Vote: I like it
  • -10
  • Vote: I do not like it

By lovro-sinda, 12 years ago, In English

Can anyone help me and write down miller rabin test example in c++? Thank you. ;)

Full text and comments »

  • Vote: I like it
  • +2
  • Vote: I do not like it