000golabi's blog

By 000golabi, history, 4 years ago, In English

“N” people are standing in a line, we name them as a0, a1, ... aN.

The age of any subset of people is defined to be the sum of its individuals.

we want to kill the oldest subset of these N people in a way that for each pair of killed people “ai” and “aj”, the distance is between “p” and “q”.

0< p <= abs(I — j) <= q

p and q are positive numbers. N < 20,000

———-

The above is a problem I came to when designing time series in a charting library. I have converted the original problem into a more readable codeforces style. This will be calculated in each WebGL animation frame, It needs to be fast.

Full text and comments »

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

By 000golabi, 10 years ago, In English

I don't want to write a .cpp file for every simple c++ class.

when I write a class definition and declaration in a single .hpp file, the linker complains about multiple definition of member functions which are not implemented inside the body of the class or defined with inline keyboard.

For example this will work but member functions will become inline :

// log.hpp file
#pragma once
#include<iostream>

class log {
  private:
    static int m_cnt = 0;
  public:
    void log();
};

inline void log::log() {
    std::cout << ++m_cnt << std::endl;
}

So I use templates to get rid of linker complaints and hope that member functions will not become inline(do they ?):

// log.hpp file
#pragma once
#include<iostream>

template<typename T>
class log_t {
  private:
    static int m_cnt = 0;
  public:
    void log();
};

template<typename T>
void log_t<T>::log() {
    std::cout << ++m_cnt << std::endl;
}

// some random type (int)
typedef log_t<int> log;

And then I can simply use log class in multiple .cpp files without linker complaints.

even when i use this method will member functions become inline ?

Full text and comments »

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

By 000golabi, 10 years ago, In English

1- every variable declared outside of functions are static and have the default value of zero(0) .

int dp[100];
bool vis[100];
struct point { int x,y; }; 
point ps[100];
int main(){
   // all elements of dp are zero by default
   // all elements of vis are false
   // all points have x == 0 and y == 0
}

2- , is an operator and returns its rightmost statement value , for example if A and B be statements (A,B) == B .

if,for,while without a block { } take one statement so you can simply write multiple statements separated bye ,

int main() {
    int a = 1, b = 2;
    int c = a,b; // c == 2
    int A[100];
    int sumA = 0;
    for(int i = 0; i < 100; ++i)
        cin >> A[i],
        sumA += A[i];
}

3- if you declare an array inside a function the value of its elements are garbage , but if you write TYPE var[LEN] = { }; all elements will be zero by default.

int main(){
   int A[100] ; // elements of A have garbage values
   int B[100] = { } ; // all elements of B are zero 
}

4- memset is defined in <string.h> and sets the bye values of a block of memory . you can use memset to initialize all elements of an integer array to 0 or -1 but not the other values .

int main(){
   int A[100];
   memset(A,0,sizeof(A)); // all elements of A are zero
   memset(A,-1,sizeof(A)); // all elements of A are -1

   //NOT WORKING
   memset(A,other_numbers,sizeof(A)); // WRONG
}

help me update this post with other useful facts . have fun !

Full text and comments »

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

By 000golabi, 11 years ago, In English

hi !

it is a plugin for c++ programmers ! generates source .cpp files for codeforces problems with test cases !

added in version 2 : you can add your own code template (as requested !)

i just tested with visual studio 2012 ,and visual studio 2013 preview i don't know if it works with 2010 or not !

download 'codeforces vs plugin 2.zip' from my skydrive public folder :

https://skydrive.live.com/?cid=04987FA06FF8DD8B&id=4987FA06FF8DD8B%21105

copy 'codeforces_vs_addin.AddIn' and 'codeforces_vs_addin.dll' to :

C:\Users\CURRENT_USER\Documents\Visual Studio 2012\Addins => for visual studio 2012

C:\Users\CURRENT_USER\Documents\Visual Studio 2012\Addins => for visual studio 2013

(CURRENT_USER == your windows account) (note : if the 'Addins' folder dos not exits , create it yourself !) and done !

codeforces plugin is accessable from => options->codeforces_vs_addin

i included photographic tutorial in 'codeforces vs plugin 2.zip'

source : https://github.com/keramer/codeforces-visual-studio-plugin have fun !

edit 2.1: version 2.01 from dear mitstudent ( fix some problems for some users ) :)

http://www.putlocker.com/file/75544024710505A3

edit 3: version 3.0 , download codeforces addin 3.zip from https://skydrive.live.com/?cid=04987FA06FF8DD8B&id=4987FA06FF8DD8B!105 i used #define ONLINE_JUDGE instead of testing=false variable . and fixed code template problem for visual studio 2013 ( works for me now ! )

Full text and comments »

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