Posts

Showing posts from February, 2016

913 - Joana and the Odd Numbers(UVA)

Run brute force , you'll get elements like below: Line   0-------------   1   1-------------   3      5      7   2-------------   9     11    13   15    17   3-------------  19   21    23   25    27   29    31   4-------------  33   35    37  39     41   43    45  47  49 Notice carefully : last element in each line propagates though the sequence given below : 6     (7-1) 10   (17-7) 14   (31-17) 18   (49-18) You need to iterate propagation  N /2  (number of lines) times If you face any problem handling the code you may see the code given below:  #include<bits/stdc++.h> using namespace std; #define ll long long int int main() {     int n;     while(scanf("%lld",&n)==1)   ...

Agent J problem no:1037 (Lightoj)

This problem is a bitmask DP problem & very much interesting  :)   ....... #include<bits/stdc++.h> using namespace std; #define maxx 15*1000000+3 int _N,dp[(1<<15)+9],health[16],arra[16][16]; /*dp[] array may need maximum index,this index is such a number that is in binary 15 digit of which bit are set (111111111111111) in decimal 2^15*/ char s[16]; //-------------Set ,reset, check function------------- int Set(int N,int pos) {     return N=N| (1<<pos); } int reset(int N,int pos) {     return N=N& ~(1<<pos); } bool check(int N,int pos) {     return (bool)  (N & (1<<pos)); } //--------------------bitmask function--------------- int bitmask(int mask) {     if(mask==(1<<_N)-1)    return 0;     if(dp[mask]!=-1)      return dp[mask];     int mnshot=maxx;     for(int i=0;i<_N;i++)     {...

10940 Throwing Cards Away II (UVA)

Brute Force  চালাও  আর দেখ  কোন Pattern পাও কি না  ;) । হ্যা ,  n=1 হলে ans=1 এরপর  থেকে  n  এর  মান  যখন  2 এর  কোন  ঘাতের  সমান  হবে  তখন ans = n তা  নাহলে  N  এর  সবচেয়ে  বড়  যে  মানের  জন্য  (n / 2^N )  এর মান  '0'  থেকে  বড়  হয় সেক্ষেত্রে 2^N=2   ( 2^N refers to answer=2 ) 2^N+1=4  ( 2^N+1 refers to answer=4 ) 2^N+2=6 2^N+i=x 2^N+i=n  হয়ে  গেলে  ans=x হবে।

11231 - Black and white painting (UVA)

প্রব্লেমটা বেশ মজার।আশা করি তোমরা statement পড়েছ।তো শুর করা যাক------ নিচের গ্রিডটা দেখ   1  2  3  4  5  6 7  8  9 10 11 12 1 .   .   .   .   .   .   .   .   .   .   .   . 2.   .   .   .   .   .   .   .   .   .   .   . 3.   .   .   .   .   .   .   .   .   .   .   . 4.   .   .   .   .   .   .   .   .   .   .   . 5.   .   .   .   .   .   .   .   .   .   .   . 6.   .   .   .   .   .   .   .   .   .   .   . 7.   .   .   .   .   .   .   .   .   .   .   . 8.   .   .   .   .   .   .  W  B  W   B  W 9.   ....