Posts

Showing posts from September, 2016

Dev Skill Mr. And Mrs. A

//Next Codeforces Round #354 (Div. 2) #include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define high 1000003 #define mxhigh 1000000000003 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef set<LL>sll; LL sze=0; vll v; void fun() {     LL i, j;     sll st;     sll ::iterator it;     for(i=2; i<high; i++)     {         LL p=1;         for(j=2; j<40; j++)         {             p = powl(i , j);             if(p > mxhigh) break;             if(p <= mxhigh)             {                 st.insert(p);

Dev Skill Divided by Whom ?

//Next Codeforces Round #354 (Div. 2) #include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define high 100005 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; typedef map<LL , bool>mpllb; typedef map<LL , LL>mpLLi; typedef map<int, multiset<int> >mmset; typedef multiset<int>mset; typedef pair<int , int>pii; int ar[high]; pii pr[high]; int main() {     int n, k , i , d , t , tc=0 , prlen=0;     scanf("%d", &t);     mmset mp;     mset::iterator it;     while(t--)     {         mp.clear();         prlen=0;         bool f=

Codeforces B. Anatoly and Cockroaches

//Next Codeforces Round #354 (Div. 2) #include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; string s , s1="" , s2=""; void ek(int len) {     for(int i=0; i<len; i++)     {         s1 += !(i&1) ? 'r' : 'b';     } } void dui(int len) {     for(int i=0; i<len; i++)     {         s2 += !(i&1) ? 'b' : 'r';     } } int main() {     fast;     int n , len=0 , i , s1r=0, s1b=0, s2r=0, s2b=0 , totals1=0, totals2=0;     while(cin >> n)     {         cin >>

Codefores A. Vitya in the Countryside

//Next Codeforces Round #354 (Div. 2) #include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int ar[100]; int main() {     fast;     int n ,  i;     while(cin >> n)     {         if(n == 1)         {             cin >> ar[0];             if(ar[0] == 15) outn("DOWN");             else if(ar[0] == 0) outn("UP");             else outn("-1");             continue;         }         for(i=0; i<n; i++)         {             cin >> ar[i];         }         if(ar[n-1] > ar[n-2]

Codeforces A. Counterexample

//Next Codeforces Round #354 (Div. 2) #include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; LL gcd(LL a , LL b) {     return b != 0 ? gcd(b , a%b) : a; } int main() {     fast;     LL l , r , i , a , b , c , j;     while(cin >> l >> r)     {         if(r - l < 2)         {             cout << "-1\n";             continue;         }         a = b = c = 0;         for(i=l; i<=r-1; i++)         {             if(gcd(i, i+1) == 1)             {                  //cout << i << "

UVa 661 - Blowing Fuses

#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define high 25 typedef map<int, bool>mpib; int consumtion[high]; int main() {     fast;     int n , m , c , tc=0 , i=0 , x , maxi=-1 , power=0;     mpib mp;     while(cin >> n >> m >> c)     {         if(!n and !m and !c) break;         mp.clear();         maxi = -1;         power = 0;         bool flown = false;         for(i=1; i<=n; i++)         {             cin >> consumtion[i];         }         for(i=0; i<m; i++)         {             cin >> x;             if(!mp[x])             {                 mp[x] = true;                 power+=consumtion[x];             }             else             {                 mp[x] = false;                 power -= consumtion[x];             }             maxi = max(power, maxi);             if(power > c) flown = true;         }         cout << "Sequence " << ++tc << "\n&qu

Codeforces Round #244 (Div. 2) A. Police Recruits

#include<bits/stdc++.h> using namespace std; int main() {     ios_base::sync_with_stdio(false);     int n , x , crime=0, police=0 , i , tmp;     while(cin >> n)     {         crime=0;         police=0;         tmp=0;         for(i=0; i<n; i++)         {             cin >> x;             if(x > 0)             {                 crime+=tmp;                 tmp=0;                 police+=x;             }             else             {                 tmp++;                 if(police >= tmp)                 {                     police = police - tmp;                     tmp=0;                 }             }         }         cout << tmp+crime << "\n";     }     return 0; }

Codeforces Round #260 (Div. 2) A. Laptops

#include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf #define high 100010 typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; struct my {     int price, quality; }; my ar[high]; bool cmp(my a, my b) {     return a.price < b.price; } int main() {     fast;     int n , a , b ,  i;     while(cin >> n)     {         bool happy=false;         for(i=0; i<n; i++)         {             cin >> ar[i].price >> ar[i].quality;         }         sort(ar, ar+n , cmp);         for(i=0; i<n-1; i++)         {             if(ar[i].price < ar[i+1].price and ar[i]

Codeforces Codeforces Beta Round #9 (Div. 2 Only) A. Die Roll

#include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; void sol(LL n) {     if(n == 1) outn("1/6");     else if(n == 2) outn("1/3");     else if(n == 3) outn("1/2");     else if(n == 4) outn("2/3");     else if(n == 5) outn("5/6");     else if(n == 6) outn("1/1"); } int main() {     fast;     LL a, b , val=0;     while(cin >> a >> b)     {         if(a == 0 and b== 0)         {             cout << "0/1\n";         }         else        

Codeforces A. Magnets

#include<bits/stdc++.h> //#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     fast;     int n , i , cnt=0;     string s, tmp="";     while(cin >> n)     {         tmp="";         cnt=0;         cin >> s;         tmp = s;         for(i=1; i<n; i++)         {             cin >> s;             if(s != tmp)             {                 cnt++;             }             tmp = s;         }         cnt++;         outn(cnt);     }     return 0; }

Codeforces Round #282 (Div. 2) B. Modular Equations

//#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     fast;     LL a , b , cnt=0 , ans=0 , i , div=0, tmp=0;     while(cin >> a >> b)     {         cnt=0;         ans = a - b;         if(ans < 0)         {             cout << "0\n";             continue;         }         else if(ans == 0)         {             cout << "infinity\n";             continue;         }         tmp = ans;         ans = sqrt(double(ans));         bool f=false , fl=false;         if(

Codeforces Round #371 (Div. 2) Meeting of Old Friends

//#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     LL l1, r1, l2, r2, k , l , r , ans=0;     while(~sf("%I64d %I64d %I64d %I64d %I64d", &l1, &r1, &l2, &r2, &k))     {         if(l1 > l2) l = l1;         else l = l2;         if(r1 > r2) r = r2;         else r = r1;         if(k >= l and k <= r)         {             //pf("%I64d\n", ((k-1 - l)+1) + ((r - k-1) + 1 ));             ans = ((k-1 - l)+1) + ((r - k-1) + 1 );         }         else         {   

Codeforces Roma and Lucky Numbers

//#include<cstdio> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define bfast cin.tie(0) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     fast;     int n,k ;     LL cnt=0, ans=0 , i , len=0;     string s;     while(cin >> n >> k)     {         cnt=0;         ans=0;         while(n--)         {             cin >> s;             len = s.length();             cnt=0;             for(i=0; i<len; i++)             {                 if(s[i] == '4' or s[i] == '7') cnt++;             }             if(cnt <= k) ans++;         }         outn(ans);     }     re

LightOj 1136 - Division by 3

// Solution Link: 1136 - Division by 3 // Accepted // Time: 0.008 /* Analysis: The number which is number%3=0 and number%3=2 is the answer, because look, a=3 and b=5 means 123%3=0 [1+2+3=6%3=0], 1234%3=1 [1+2+3+4=10%3=1, which is not answer] and 12345%3=0 [1+2+3+4+5=15%3=0] now just think about the positive number sequence 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9, 10, 11, 12 , 13, 14 , 15 , 16 , 17 , 18, 19 , 20 , 21, 22 , 23 , 24, 25; now do the digit sum for 1 to N by Gaussian formula, what will happen ? for 1, 1*(1+1)/2=2/2=1%3=1 is not an answer;     for 2, 2*(2+1)/2=6/2=3%3=0 is an answer;     for 3, 3*(3+1)/2=12/2=6%3=0 is an answer;     for 4, 4*(4+1)/2=20/2=10%3=1 is not an answer;     for 5, 5*(5+1)/2=30/2=15%3=0 is an answer;     for 6, 6*(6+1)/2=42/2=21%3=0 is an answer;     and then you will see the 7 is not an answer by above this process     again 8 and 9 will be an answer but 10 is not, again 11, 12 will be an answer but 13 is not..........     So, by d

AtCoder Be Together

//#include<stdio.h> //#include<iostream> //#include<algorithm> //#include<vector> //#include<cstring> //#include<cmath> //#include<map> #include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false) #define outs(x) cout << x << " " #define outn(x) cout << x << "\n" #define sf scanf #define pf printf typedef long long LL; typedef vector<int>vii; typedef vector<LL>vll; int main() {     fast;     int n;     vii v;     while(cin >> n)     {         v.clear();         int i=0 , x;         for(; i<n; i++)         {             cin >> x;             v.push_back(x);         }         LL mxe = *max_element(v.begin(), v.end()) , mini = 1000000000 ,sum=0 , df=0;         //cout << mxe << "\n";         LL tmini = mini;         int  j=0 ;         for(i=-101; i<=100; i++)         {             sum=0;             for(j=0; j<n; j