584A. Olesya and Rodion

Problem Link

<Source Code>

#include <bits/stdc++.h>
using namespace std;

#define INF 10000000

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef set<int> si;
typedef map<string, int> msi;

#define all(x) x.begin(), x.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define spresent(c,x) ((c).find(x) != (c).end())  // for set,map
#define present(c,x) (find(all(c),x) != (c).end())  // for vector
#define uu first
#define vv second
#define fr(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nfr(i,a,b) for(int i= int(a);i>=int(b);--i)



int main()
{
ll n,m,i;
cin>>n>>m;
if(n==1 &&m==10)
{
cout<<-1<<endl;
return 0;
}
if(m<10){
for(i=0;i<n;i++)
{cout<<m;
}
}
else if(m==10)
{
    printf("1");
    for(i=1;i<n;i++)
        cout<<"0";
    cout<<endl;
}
cout<<'\n';

}
Advertisements

1133 – Array Simulation

Problem Link

<Source Code>

#include<bits/stdc++.h>
using namespace std;
int a[10000],b[10000];
char c;

int main()
{
int t,n,j,o,m,i,add,d;
cin>>t;
for(o=1;o<=t;o++)
{
cin>>n>>m;
memset(a,0,sizeof(a));
for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<m;i++)
{
cin>>c;
if(c==’S’)
{cin>>add;
for(j=0;j<n;j++)
a[j]+=add;
}
else if(c==’M’)
{
cin>>d;
for(j=0;j<n;j++)
a[j]*=d;

}
else if(c==’R’)
{
for(j=0;j<=(n-1)/2;j++)
swap(a[n-j-1],a[j]);
}
else if(c==’D’)
{
cin>>d;
for(j=0;j<n;j++)
a[j]=a[j]/d;
}
else{
int x,y;
cin>>x>>y;
swap(a[x],a[y]);
}
}

printf(“Case %d:\n”,o);
for(j=0;j<n-1;j++)
{printf(“%d “,a[j]);
}
cout<<a[n-1];
cout<<endl;

}
return 0;
}

 

682B. Alyona and Mex

Problem Link

<Solution>

#include <bits/stdc++.h>
using namespace std;

#define INF 10000000

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef set<int> si;
typedef map<string, int> msi;

#define all(x) sort(x.begin(), x.end())
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define spresent(c,x) ((c).find(x) != (c).end()) // for set,map
#define present(c,x) (find(all(c),x) != (c).end()) // for vector
#define uu first
#define vv second
#define fr(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nfr(i,a,b) for(int i= int(a);i>=int(b);–i)

int main()
{
int n,x,i,co=1;
cin>>n;
int a[n];
for(i=0;i<n;i++)
{
cin>>a[i];

}
sort(a,a+n);
//for(i=0;i<n;i++)
// cout<<a[i]<<‘ ‘;
// cout<<endl;
for(i=0;i<n;i++)
{
if(a[i]>=co)
co++;

}
cout<<co<<endl;
}

336:A Node Too Far

Problem Link

<Source Code>

#include<bits/stdc++.h>
#define pb push_back
#define sf(x) scanf(“%d”,&x)
#define MN 1234567
#define max 10000
#define all(water) (water.begin(),water.end());
#define fr(i,a,b) for(i=a;i<b;i++)
using namespace std;
#define cln(a) memset(a,0,sizeof(a))
#define eof(a) memset(a,-1,sizeof(a))
#define pt(c) printf(“Case %d: “,++c)
#define ll long long
map<int,int>visited;
void bfs(int start, map<int,vector<int>>graph) {
queue<int>q;
q.push(start);
visited[start]=0;
while(!q.empty())
{
int u=q.front(),i;
q.pop();
int l=graph[u].size();
for(i=0;i<l;i++)
{
int v=graph[u][i];
if(!visited.count(v))
{
visited[v]=visited[u]+1;
q.push(v);
}
}
}
}
int main()
{
int c=0,node,i,start,ttl,res;
while(scanf(“%d”,&node) &&node)
{
map<int,vector<int>>graph;
int x,y;
while(node–)
{
cin>>x>>y;
graph[x].pb(y);
graph[y].pb(x);

}
while(scanf(“%d %d”,&start,&ttl) &&(start!=0 ||ttl!=0))
{
visited.clear();
map<int,int>::const_iterator it;
res=0;
bfs(start,graph);
for(it=visited.begin();it!=visited.end();it++)
{
if((*it).second>ttl)
res++;
}
res+=graph.size()-visited.size();

printf(“Case %d: %d nodes not reachable from node %d with TTL = %d.\n”,++c,res,start,ttl);
}
}

return 0;
}

10611:Playboy Chimp

Problem Link

<Source Code>

#include<bits/stdc++.h>
#define pb push_back
#define sf(x) scanf(“%d”,&x)
#define MN 1234567
#define max 10000
#define all(water) (water.begin(),water.end());
#define fr(i,a,b) for(i=a;i<b;i++)
using namespace std;
#define cln(a) memset(a,0,sizeof(a))
#define ll long long
int main()
{int n,luchu;
while(cin>>n)
{
int lady[n],i,j,Q;
for(i=0;i<n;i++)
{
cin>>lady[i];
}
cin>>Q;
for(i=0;i<Q;i++)
{
cin>>luchu;
int low=(lower_bound(lady,lady+n,luchu)-lady-1);
int high=(upper_bound(lady,lady+n,luchu)-lady);

if(low>=0 &&low<n)
{
printf(“%d “,lady[low]);
}
else
printf(“X “);
if(high>=0 &&high<n)
printf(“%d\n”,lady[high]);
else printf(“X\n”);

}

}

return 0;
}

10473 – Simple Base Conversion

Problem Link

<Source Code>

import java.util.*;
import java.math.*;

class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
String s;
while(sc.hasNext())
{
s=sc.next();
if(s.charAt(0)==’-‘)
break;
if(s.charAt(0)==’0′ &&s.charAt(1)==’x’)
{
BigInteger number = new BigInteger(s.substring(2),16);
System.out.println(number);
}
else{
BigInteger number = new BigInteger(s);
s=number.toString(16);
System.out.println(“0x”+s.toUpperCase());
}
}
}}

Useful Contents /Get Introduced to Various Parts of PRogramming