Useful Contents /Get Introduced to Various Parts of PRogramming

Advertisements
Posted in Uncategorized | Tagged , | Leave a comment

Set Up Graphics.h Header File

 

For executing programming with use of graphics,we need to include some files!

I am indicating some programmes

And so on!

for these types of wonderful works u need to do some works!

#In Codeblocks

Click Here! for setup process!

#In DevC++
Click here! for setup process!

                               >>A Calculator Project Using Java 🙂 <<<

happy-coding-150x150

N:B:In many browsers,this post is not shown properly, I tested Mozilla,Chrome and IE all are working fine , please update your browser

Posted in Uncategorized | 8 Comments

2033: Devices

Problem Link

Tutorial

Here , today I’ll discuss about the problem .
The main point of the problem is to determine the numbers of modern devices that his friends have.

And he will buy the device that is used by maximum numbers of his friend.
From this overview, we have got some hints about determining the occurrence of modern devices.

if there are several devices that occupy max number of times, then he will buy the cheapest one.

 

Code in brief

I used two map ,one will store the frequency and another will update the minimum cost of the device to find the cheapest one .
That’s it 🙂

 

 

View Code

#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<vector>

using namespace std;
int main()
{
	int ok=0,mx=0,mn=(int)1e9,k;
	string ans;
	string x,y;
	map<string,int> mp;
	map<string,int> mpp;
	for(int i=0;i<6;i++) 	         { 		                 cin>>x>>y>>k;
		if(!mp.count(y))
			mp[y]++,mpp[y]=k;
		else{
			mpp[y]=min(k,mpp[y]),mp[y]++;
		}
                ok=max(ok,mp[y]);
	}
	for(auto it : mp)
	{
		 if(it.second==ok)
		 {
			if(mpp[it.first]<=mn)
			{
				ans=it.first;
				mn=mpp[it.first];
			}
		}
	}
	cout<<ans<<'\n';
}

 

 

 

 

Posted in timus | Tagged , , , | Leave a comment

448B

Problem Link

 

View Code
#include<bits/stdc++.h>
using namespace std;
#define all(s) sort(s.begin(),s.end())
string s,t;
bool ar()
{all(s);all(t);
return s==t;
}

bool autom()
{
int c=0,sz=0;
int l=s.size();
for(int i=0;i<l;i++)
{
if(s[i]==t[c])
c++,sz++;
}

return sz==t.size()?1:0;

}
bool bt()
{
all(s);
all(t);
int c=0,sz=0;
int l=s.size();
for(int i=0;i<l;i++) { if(s[i]==t[c]) c++,sz++; } return sz==t.size()?1:0; } int main() { cin>>s>>t;
if(autom())
cout<<"automaton"<<endl;
else if(ar())
cout<<"array"<<endl;
else if(bt())
cout<<"both"<<endl;
else
cout<<"need tree"<<endl;

}

 

Posted in Uncategorized | Leave a comment

GSS1

#Problem Link

Prerequisites:

1.  e-maxx

 

 

View Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mx = 50010;
ll a[mx];

struct data {
int sum, pref, suff, ans ;
}tree[4*mx] ;
data make_data ( ll val ) {
data res ;
res. sum = val ;
res. pref = res. suff = res. ans = val ;
return res ;
}
data combine ( data l, data r ) {
data res ;
res. sum = l. sum + r. sum ;
res. pref = max ( l. pref , l. sum + r. pref ) ;
res. suff = max ( r. suff , r. sum + l. suff ) ;
res. ans = max ( max ( l. ans , r. ans ) , l. suff + r. pref ) ;
return res ;
}

void build(ll node,ll b,ll e)
{
if(b==e)
{
tree[node]=make_data(a[b]);
}
else{
int mid=(b+e)/2;
build(node*2,b,mid);
build(node*2+1,mid+1,e);
tree[node]=combine(tree[node*2],tree[node*2+1]);
}
}
void buildsm(ll node,ll b,ll e)
{

}

ll update(ll node,ll b,ll e,ll x,ll y)
{

}

data query(ll node,ll b,ll e,ll l,ll r)
{
if(l==b &&e==r)
return tree[node];
int mid=(b+e)/2;
if(r<=mid) return query(node*2,b,mid,l,r); if(l>mid)
return query(node*2+1,mid+1,e,l,r);
return combine(query(node*2,b,mid,l,mid),query(node*2+1,mid+1,e,mid+1,r));
};
ll n,q;
int main()
{

scanf(“%lld”,&n);
memset(tree,0,sizeof tree);
memset(a,0,sizeof a);
for(ll i=1;i<=n;i++)
{scanf(“%lld”,&a[i]);
}
build(1,1,n);
//buildsum(1,1,n);
scanf(“%lld”,&q);
while(q–)
{
ll x,y;
scanf(“%lld %lld”,&x,&y);
{
printf(“%lld\n”,query(1,1,n,x,y).ans);
//cout<<query(1,1,n,x,y)<<endl;
}

}

}

 

 

Posted in Uncategorized | Leave a comment

126B – Password

This problem is based on Z- algorithm

To learn this algorithm  – Click here!

 

View Code

#include<bits/stdc++.h>
using namespace std;
void solve(string s)
{
int l=s.size();
int z[l];
int left,right;
left=right=0;
for(int k=1;k<l;k++) { if(k>right)
{
left=right=k;
while(right {
right++;
}
z[k]=right-left;
right–;
}
else{
int k1=k-left;
if(z[k1]<right-k+1)
{
z[k]=z[k1];
}
else{
left=k;
while(right {
right++;
}
z[k]=right-left;
right–; }

}
}
int mxz = 0, res = 0,n=l;
for(int a=1;a<l;a++){
//printf(“%d %d\n”, a, Z[a]);
if(a + z[a] == l){
if(z[a] <= mxz){
for(int j=0;j<z[a];j++) printf(“%c”, s[j]); return ; } } mxz = max(mxz, z[a]); } puts(“Just a legend”); } int main() { string s; cin>>s;

solve(s);
}

 

Posted in Uncategorized | Leave a comment

Z algorithm

Today we will try with a new algorithm – Z algorithm

This algo is used in pattern matching,there is another algo for pattern matching

This algorithm works in O(length of text+length of pattern) complexity

and space complexity is similar to time complexity that means O(length of text+length of pattern)

This algorithm is very easy.

</>Video Tutorial

 

</>Visualization

 

</> Blog

 

#Problemset

 

Posted in Uncategorized | Leave a comment

Lightoj 1414 Feb 29

Problem Link:


Hints:

if 2nd given month is not feb and january ,i will increment the value by 1

and if the first given month is jan or feb and date is less then 29 then i will decrement the value by 1

then for every year i will calculate the difference using a function

let y and yy are two years &&yy>=y &&passing yy and y-1 to function

int leap(int yy,int y,int x)
{
     return yy/x-y/x;
}


Then calculations

View Code
#include
using namespace std;
int month(string s)
{
string months[]={" ","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
vectorv(months,months+13);
vector::iterator it=find(v.begin(),v.end(),s);
return distance(v.begin(), it);
}
int leap(int y,int yy,int x)
{
	return y/x-yy/x;
}

int main() {
		int n,d,dd,y,yy,cs=1;
		char a[24],b[24];
		cin>>n;
		while(n--)
		{//a.clear(),b.clear();
			scanf("%s %d, %d",a,&d,&y);
			scanf("%s %d, %d",b,&dd,&yy);
			int m,mm;
			m=month(a);
			mm=month(b);
			if(m>2) y++;
			if(mm<2 ||(mm==2 &&dd<29))
			yy--;
			y--;
			int dif=leap(yy,y,4)-leap(yy,y,100)+leap(yy,y,400);
			cout<<"Case "<<cs++<<": "<<dif<<endl;
		}
	return 0;
}

 

 

 

Posted in Uncategorized | Leave a comment

1259: Goldbach`s Conjecture

Problem Link

Hints:

store prime numbers in an vector;

then check the n-*it is prime or not

for example

6

2 4

3 3

here 2 is prime but (6-2)=4 is not prime

in the case of  3+3 here 3 is a prime and n-3=3 is also a prime number

 

 

 

View Code

#include<bits/stdc++.h>
using namespace std;
const int N=10000005;
bool status[N];
#define ll long long
vectorprime;

void sieve()
{
memset(status,0,sizeof status);
status[0]=status[1]=1;
ll k=N/2;

for(ll i=2;i<=k;i++)
{
if(!status[i])
{
prime.push_back(i);
for(ll j=2*i;j<=N;j+=i) status[j]=1; } } } int main() { sieve(); ll t,n,co=0,cs=1; //ll dp[N]; cin>>t;
while(t–)
{
cin>>n;

co=0;
ll k=n/2;
for(vector::iterator it=prime.begin();it!=prime.end() && *it<=k;it++)
{
if(status[n-*it]==0)
co++;
}
printf(“Case %lld: %lld\n”,cs++,co);
}
}

 

Posted in Uncategorized | Leave a comment