#include<bits/stdc++.h> using namespace std; int main(){ int n,m=0,k=0,l; size_t p; string a,b; while(getline(cin,a)){ if(a[0] == '+') m++; else if(a[0] == '-') m--; else { k+=m*(a.size()-a.find(':')-1); } } cout << k <<endl; return 0 ; }
Tuesday, August 30, 2016
Codeforces-A. Chat Server's Outgoing Traffic
Codeforces[div.2-659]-A. Round House
#include <stdio.h> #include <math.h> int main() { int n, a, b, r, d; while(scanf("%d%d%d", &n, &a, &b)==3) { d = (a+b)%n; if(d<0)d+=n; if(d==0)d=n; printf("%d\n",d); } return 0; }
Codeforces[div.2-706]-A. Beru-taxi
#include <bits/stdc++.h> using namespace std; int main() { int n,p,i,j,lo=0,q,a[100001],t=0,a1,b,x,z,y; double k ,l = 1e99; cin >> a1>>b>>n; for(i=1;i<=n;i++){ cin >>x>>y>>z; k = hypot(x - a1 + 0., y - b + 0.) / z; l = min(l,k); } printf("%.10f\n",l); return 0; }
Codeforces[div.2-706B]-B. Interesting drink
#include <bits/stdc++.h> using namespace std; int main() { int n,p,i,j,k,lo=0,q,t=0; long int q1; cin >> n; vector<int>a(n); for(i=0;i<n;i++)cin >>a[i]; sort(a.begin(),a.end()); cin >> q; for(i=0;i<q;i++){ cin >>q1; k = upper_bound(a.begin(),a.end(),q1)-a.begin(); cout<<k<<endl; } return 0; }
Codeforces-(dev 709A)-A. Juicer
#include<stdio.h> #include<math.h> int main() { int i,n,b,c = 0,d,sum = 0,a[100001]; scanf("%d %d %d",&n,&b,&d); for(i = 0 ; i < n ; i++) { scanf("%d",&a[i]); if(a[i] <= b){ sum += a[i];} if(sum>d){c++;sum = 0;} } printf("%d\n",c); return 0; }
Monday, August 29, 2016
hackerrank- Minimum Distances locked(https://www.hackerrank.com/contests/june-world-codesprint/challenges/minimum-distances)
#include <bits/stdc++.h>
using namespace std;
int main() {
int i,j,n,k=0,l,b1,d1=0;
cin >> n ;
int a[n],b[n];
for(i=0;i<n;i++) cin >> a[i];
k = 0;
l = a[0] ;
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(a[i] == a[j]){
b1 = j-i;
d1 = 1;
}
}
if(l>b1) l = b1 ;
}
if(d1!=0)
cout << l <<endl;
else
cout << "-1" <<endl;
return 0;
}
using namespace std;
int main() {
int i,j,n,k=0,l,b1,d1=0;
cin >> n ;
int a[n],b[n];
for(i=0;i<n;i++) cin >> a[i];
k = 0;
l = a[0] ;
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(a[i] == a[j]){
b1 = j-i;
d1 = 1;
}
}
if(l>b1) l = b1 ;
}
if(d1!=0)
cout << l <<endl;
else
cout << "-1" <<endl;
return 0;
}
Sunday, August 28, 2016
uri- 2144 - Bodybuilder
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
double W1, W2, R, acumulacao=0.0;
int qtd=0;
while(cin >> W1 >> W2 >>R ){
double esq, dir;
double media;
if(qtd !=0)
cout<<endl;
if(W1+W2+R == 0)
break;
esq = W1*(1+ R/30);
dir = W2*(1+ R/30);
media = (esq+dir)/2;
acumulacao+=media;
qtd++;
if(media>=1 && media < 13){
cout << "Nao vai da nao";
}
if(media>=13 && media <14){
cout << "E 13";
}
if(media>=14 && media <40){
cout << "Bora, hora do show! BIIR!" ;
}
if(media>=40 && media <=60){
cout << "Ta saindo da jaula o monstro!" ;
}
if(media>60){
cout << "AQUI E BODYBUILDER!!" ;
}
}
if((acumulacao/qtd)>40){
cout<<"\n";
printf("Aqui nois constroi fibra rapaz! Nao e agua com musculo!\n");
}
return 0;
}
#include <stdio.h>
using namespace std;
int main(){
double W1, W2, R, acumulacao=0.0;
int qtd=0;
while(cin >> W1 >> W2 >>R ){
double esq, dir;
double media;
if(qtd !=0)
cout<<endl;
if(W1+W2+R == 0)
break;
esq = W1*(1+ R/30);
dir = W2*(1+ R/30);
media = (esq+dir)/2;
acumulacao+=media;
qtd++;
if(media>=1 && media < 13){
cout << "Nao vai da nao";
}
if(media>=13 && media <14){
cout << "E 13";
}
if(media>=14 && media <40){
cout << "Bora, hora do show! BIIR!" ;
}
if(media>=40 && media <=60){
cout << "Ta saindo da jaula o monstro!" ;
}
if(media>60){
cout << "AQUI E BODYBUILDER!!" ;
}
}
if((acumulacao/qtd)>40){
cout<<"\n";
printf("Aqui nois constroi fibra rapaz! Nao e agua com musculo!\n");
}
return 0;
}
uri- 1940 - Strategy Game
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,i,n1,c=0,c1,c2,max,pos,bar[501],arr[250001],j;
cin >> n >> n1 ;
max = pos = 0;
for(i=1;i<=n*n1;i++){
cin >> arr[i];
}
for(i=1;i<=n;i++){
c=0;
for(j=i;j<=n1*n;j+=(n)){
c += arr[j];
}
if(max<=c){
max = c;
pos = i;
}
}
cout << pos <<endl;
return 0;
}
using namespace std;
int main()
{
int n,i,n1,c=0,c1,c2,max,pos,bar[501],arr[250001],j;
cin >> n >> n1 ;
max = pos = 0;
for(i=1;i<=n*n1;i++){
cin >> arr[i];
}
for(i=1;i<=n;i++){
c=0;
for(j=i;j<=n1*n;j+=(n)){
c += arr[j];
}
if(max<=c){
max = c;
pos = i;
}
}
cout << pos <<endl;
return 0;
}
uri- 1893 - Moon Phases
#include <bits/stdc++.h>
using namespace std;
int main() {
int a,b1,b2;
cin >> b1 >>b2 ;
if(b1>b2){
if(b2>=0 && b2<3)
cout <<"nova"<<endl;
else if(b2>=3 && b2<97)
cout <<"minguante"<<endl;
else if(b2>=97 && b2<101)
cout <<"cheia"<<endl;
}else{
if(b2>=0 && b2<3)
cout <<"nova"<<endl;
else if(b2>=3 && b2<97)
cout <<"crescente"<<endl;
else if(b2>=97 && b2<101)
cout <<"cheia"<<endl;
}
return 0;
}
using namespace std;
int main() {
int a,b1,b2;
cin >> b1 >>b2 ;
if(b1>b2){
if(b2>=0 && b2<3)
cout <<"nova"<<endl;
else if(b2>=3 && b2<97)
cout <<"minguante"<<endl;
else if(b2>=97 && b2<101)
cout <<"cheia"<<endl;
}else{
if(b2>=0 && b2<3)
cout <<"nova"<<endl;
else if(b2>=3 && b2<97)
cout <<"crescente"<<endl;
else if(b2>=97 && b2<101)
cout <<"cheia"<<endl;
}
return 0;
}
uri- 1595 - Humm.. Run or Walk.. That's the Question
#include <bits/stdc++.h>
using namespace std;
int cmp(const void * a,const void * b){ return (*(int*)a - *(int*)b);}
int main() {
int ar[100001];
int t,n,s,c,r;
double res;
cin >> n ;
while(n--){
res = 0.0 ;
cin >>s>>c>>r;
for(int i = 0; i<s ; i++) cin >>ar[i];
qsort(ar,s,sizeof(int),cmp);
if(c!=0)
for(int i = 0; i<c;i++) res += 1.0/((double)ar[i]*1.0 + (double)r*1.0);
for(int i = c; i<s;i++) res += 1.0/((double)ar[i]*1.0);
printf("%.2lf\n",res);
}
return 0;
}
using namespace std;
int cmp(const void * a,const void * b){ return (*(int*)a - *(int*)b);}
int main() {
int ar[100001];
int t,n,s,c,r;
double res;
cin >> n ;
while(n--){
res = 0.0 ;
cin >>s>>c>>r;
for(int i = 0; i<s ; i++) cin >>ar[i];
qsort(ar,s,sizeof(int),cmp);
if(c!=0)
for(int i = 0; i<c;i++) res += 1.0/((double)ar[i]*1.0 + (double)r*1.0);
for(int i = c; i<s;i++) res += 1.0/((double)ar[i]*1.0);
printf("%.2lf\n",res);
}
return 0;
}
uri- 1451 - Broken Keyboard
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
list<char>s1;
list<char>::iterator it;
while(cin >> a){
s1.clear();
it = s1.begin();
for(int i = 0; i<a.size();i++){
if(a[i] == ']') {
it = s1.end();
} else if(a[i] == '[') {
it = s1.begin();
}else {
s1.insert(it, a[i]);
}
}
for(it = s1.begin(); it != s1.end(); it++)
cout << *it;
cout << '\n';
}
return 0;
}
using namespace std;
int main() {
string a;
list<char>s1;
list<char>::iterator it;
while(cin >> a){
s1.clear();
it = s1.begin();
for(int i = 0; i<a.size();i++){
if(a[i] == ']') {
it = s1.end();
} else if(a[i] == '[') {
it = s1.begin();
}else {
s1.insert(it, a[i]);
}
}
for(it = s1.begin(); it != s1.end(); it++)
cout << *it;
cout << '\n';
}
return 0;
}
uri- 1383 - Sudoku
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n, i, j, k, sum = 285, cnt = 0;
int a[9][9];
string s = "";
cin >> n;
while(n--) {
for(i = 0; i < 9; i++)
for(j = 0; j < 9; j++)
cin >> a[i][j];
int sl[9], sc[9], sm[3][3];
for (i = 0; i < 9; i++)
sl[i] = sc[i] = sm[i/3][i%3] = 0;
for (i = 0; i < 9; i++) {
for (j = 0; j < 9; j++) {
k = a[i][j];
k *= k;
sl[i] += k;
sc[j] += k;
sm[i/3][j/3] += k;
if (i == 8 && sc[j] != 285)
break;
}
if (sl[i] != 285)
break;
}
// if(s == "")
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
if (sm[i][j] != 285)
s = "NAO";
if(s == "")
s = "SIM";
cnt++;
cout << "Instancia " << cnt << endl << s << endl << endl;
s = "";
}
return 0;
}
using namespace std;
int main(int argc, char const *argv[]) {
int n, i, j, k, sum = 285, cnt = 0;
int a[9][9];
string s = "";
cin >> n;
while(n--) {
for(i = 0; i < 9; i++)
for(j = 0; j < 9; j++)
cin >> a[i][j];
int sl[9], sc[9], sm[3][3];
for (i = 0; i < 9; i++)
sl[i] = sc[i] = sm[i/3][i%3] = 0;
for (i = 0; i < 9; i++) {
for (j = 0; j < 9; j++) {
k = a[i][j];
k *= k;
sl[i] += k;
sc[j] += k;
sm[i/3][j/3] += k;
if (i == 8 && sc[j] != 285)
break;
}
if (sl[i] != 285)
break;
}
// if(s == "")
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
if (sm[i][j] != 285)
s = "NAO";
if(s == "")
s = "SIM";
cnt++;
cout << "Instancia " << cnt << endl << s << endl << endl;
s = "";
}
return 0;
}
uri- 1033 - How Many Calls?
#include <bits/stdc++.h>
using namespace std;
typedef long long Nu;
int bigmod(Nu n, const int M)
{
if ( n <= 0 ) return 0;
Nu a, b, c, d, r;
a = 1, b = 0 , c = 0, d = 1;
--n;
while ( n > 0 )
{
if ( n&1 )
{
r = ( (d*b) + (c*a) )%M;
b = ( d*(b+a) + (c*b) )%M;
a = r;
}
r = ( c*c + d*d )%M;
d = ( d * (2*c + d) )%M;
c = r;
n = n/2;
}
return (a + b)%M;
}
int main()
{
Nu k;
int g, h, re = 0;
while (cin >> k >> g && (k || g) )
{
h = ( (2 * bigmod(k+1, g)) - 1 + g ) % g;
printf("Case %d: %lld %d %d\n", ++re, k, g, h);
}
return 0;
}
using namespace std;
typedef long long Nu;
int bigmod(Nu n, const int M)
{
if ( n <= 0 ) return 0;
Nu a, b, c, d, r;
a = 1, b = 0 , c = 0, d = 1;
--n;
while ( n > 0 )
{
if ( n&1 )
{
r = ( (d*b) + (c*a) )%M;
b = ( d*(b+a) + (c*b) )%M;
a = r;
}
r = ( c*c + d*d )%M;
d = ( d * (2*c + d) )%M;
c = r;
n = n/2;
}
return (a + b)%M;
}
int main()
{
Nu k;
int g, h, re = 0;
while (cin >> k >> g && (k || g) )
{
h = ( (2 * bigmod(k+1, g)) - 1 + g ) % g;
printf("Case %d: %lld %d %d\n", ++re, k, g, h);
}
return 0;
}
uri- 2172 - Event
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
long r;
while ((cin >> n >> r) && (n&&r)!=0){
cout<<n*r<<endl;
}
return 0;
}
using namespace std;
int main() {
int n;
long r;
while ((cin >> n >> r) && (n&&r)!=0){
cout<<n*r<<endl;
}
return 0;
}
uri- 2187 - Bits Exchanged
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i,j=0,k,l,m,n;
while(cin>>n && n){
i = l = k = m = 0;
j++;
i = n/50;
k = (n - i*50)/10;
l = (n - (i*50+k*10))/5;
m = (n - (i*50+k*10+l*5))/1;
cout<<"Teste "<<j<<"\n"<<i <<" "<<k<<" "<<l <<" "<<m<<endl<<endl;
}
return 0 ;
}
using namespace std;
int main()
{
int i,j=0,k,l,m,n;
while(cin>>n && n){
i = l = k = m = 0;
j++;
i = n/50;
k = (n - i*50)/10;
l = (n - (i*50+k*10))/5;
m = (n - (i*50+k*10+l*5))/1;
cout<<"Teste "<<j<<"\n"<<i <<" "<<k<<" "<<l <<" "<<m<<endl<<endl;
}
return 0 ;
}
uri- 2171 - Sharing with Fink
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,j=0;
long r;
while (cin >>r && r!=0){
j=0;
for(int i = 1;j+i<=r;i++){
j +=i;
}
cout<<j<<" "<<r - j<<endl;
}
return 0;
}
using namespace std;
int main() {
int n,j=0;
long r;
while (cin >>r && r!=0){
j=0;
for(int i = 1;j+i<=r;i++){
j +=i;
}
cout<<j<<" "<<r - j<<endl;
}
return 0;
}
uri- 2174 - Pomekon Collection
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,k,j,l;
string a;
cin>> n;
set<string>ar;
while(n--){
cin >> a;
ar.insert(a);
}
printf("Falta(m) %d pomekon(s).\n",151-ar.size());
ar.clear();
return 0 ;
}
using namespace std;
int main()
{
int n,i,k,j,l;
string a;
cin>> n;
set<string>ar;
while(n--){
cin >> a;
ar.insert(a);
}
printf("Falta(m) %d pomekon(s).\n",151-ar.size());
ar.clear();
return 0 ;
}
uri- 2175 - What is the Fastest?
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n,i,k,j,l;
string a;
cin>> n >> i >> k;
l = min(n,min(i,k));
if(n==l && (n != i && n!=k))cout<<"Otavio\n";
else if(i==l && (n != i && i!=k))cout<<"Bruno\n";
else if(k==l && (k != i && n!=k))cout<<"Ian\n";
else cout<<"Empate\n";
return 0 ;
}
using namespace std;
int main()
{
double n,i,k,j,l;
string a;
cin>> n >> i >> k;
l = min(n,min(i,k));
if(n==l && (n != i && n!=k))cout<<"Otavio\n";
else if(i==l && (n != i && i!=k))cout<<"Bruno\n";
else if(k==l && (k != i && n!=k))cout<<"Ian\n";
else cout<<"Empate\n";
return 0 ;
}
uri- 2176 - Parity
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,k,j,l;
string a;
cin>> a;
for(int p = 0; p<a.size();p++){
if(a[p]=='1')k++;
}
if(k%2==0) cout<<a<<'0'<<endl;
else cout<<a<<'1'<<endl;
return 0 ;
}
using namespace std;
int main()
{
int n,i,k,j,l;
string a;
cin>> a;
for(int p = 0; p<a.size();p++){
if(a[p]=='1')k++;
}
if(k%2==0) cout<<a<<'0'<<endl;
else cout<<a<<'1'<<endl;
return 0 ;
}
uri- 1028 - Collectable Cards
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,n;
scanf("%d",&n);
while(n--){
scanf("%d %d",&a,&b);
printf("%d\n",__gcd(a,b));
}
return 0;
}
using namespace std;
int main()
{
int a,b,c,n;
scanf("%d",&n);
while(n--){
scanf("%d %d",&a,&b);
printf("%d\n",__gcd(a,b));
}
return 0;
}
Subscribe to:
Posts (Atom)