264 - Count on Cantor

All about problems in Volume 2. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko » Mon Dec 05, 2005 6:09 am

No, it says:
" No blank line should appear after the last number."

You are missing a newline at the end.

Darko

Trust Noone
New poster
Posts: 4
Joined: Wed Nov 16, 2005 8:54 pm

Post by Trust Noone » Tue Dec 13, 2005 11:27 pm

You must delete the first cout<<'\n';
Then enable the last //cout<<'\n';
Then change cout<<"TERM "<<a<<" is "; to cout<<"TERM "<<a<<" IS ";

Karthekeyan
New poster
Posts: 33
Joined: Tue Jun 29, 2004 1:38 pm
Location: IITM,chennai,Tamil Nadu,India
Contact:

oh ya!

Post by Karthekeyan » Wed Dec 21, 2005 10:40 am

such a silly mistake i made!!:-((
Karthe

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Wed Dec 21, 2005 1:46 pm

Why don't you remove your code?

xlvector
New poster
Posts: 11
Joined: Thu Dec 29, 2005 8:30 am
Contact:

264 Output Limit Exceeded

Post by xlvector » Mon Jan 02, 2006 7:02 am

#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

class CountCantor
{
public:
int* solve(int pos);
};

int* CountCantor::solve(int pos)
{
int n = (int)((sqrt(1.0+8.0*pos)-1)/2.0);
int size = (int)(n*(n+1)/2);
int left = pos - size;
int *ret = new int[2];
if(left>0){
ret[1] = n + 2 - left;
ret[0] = left;
}
else{
ret[0] = n;
ret[1] = 1;
}
if((n%2==0 && left>0)||(n%2==1 && left==0)){
std::swap(ret[0],ret[1]);
}
return ret;
}

int main()
{
int n;
CountCantor CC;
int *ret;
while(true){
cin>>n;
ret = CC.solve(n);
cout<<"TERM "<<n<<" IS "<<ret[0]<<"/"<<ret[1]<<endl;
delete[] ret;
}
return 0;
}

What's wrong with my code , I got Output Limit Exceeded Error

xlvector
New poster
Posts: 11
Joined: Thu Dec 29, 2005 8:30 am
Contact:

This is my output

Post by xlvector » Mon Jan 02, 2006 7:04 am

1
TERM 1 IS 1/1
2
TERM 2 IS 1/2
3
TERM 3 IS 2/1
4
TERM 4 IS 3/1
5
TERM 5 IS 2/2
10
TERM 10 IS 4/1
20
TERM 20 IS 5/2
100
TERM 100 IS 9/6
1000
TERM 1000 IS 36/10
10000
TERM 10000 IS 12/130
100000
TERM 100000 IS 129/319

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Mon Jan 02, 2006 4:59 pm

When do you believe your program terminates? :P

Pachy_4_Ever
New poster
Posts: 1
Joined: Tue Apr 25, 2006 11:26 am
Location: In the Hidden Leaf Village
Contact:

Time Limit Exceeded 264!!! Help!!!

Post by Pachy_4_Ever » Tue Apr 25, 2006 11:34 am

...
....
....
CODE
Last edited by Pachy_4_Ever on Tue Apr 25, 2006 11:28 pm, edited 1 time in total.

Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha » Tue Apr 25, 2006 6:12 pm

This problem has a very nice solution. Think about a math formula.

noahuman
New poster
Posts: 1
Joined: Sat Jul 29, 2006 6:26 am

264 - simple questtion

Post by noahuman » Sat Jul 29, 2006 6:31 am

hi there
i have a very simple question to ask

in question 264, it says "[i]The input list contains a single number per line and will be terminated by end-of-file.", [/i]does this mean the input should be from the command line, or from a file (using C++)?

I've got the answers correct, but the system does not accept my program, plz give me some hints ..... much appriciation ! :)


best regards

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf » Sat Jul 29, 2006 7:24 am

Your program should read input from the standard input. For example, in this way (C++):

Code: Select all

int n;
while (cin >> n) { <compute answer>; cout << answer << endl; }
or this (C):

Code: Select all

while (scanf("%d", &n) == 1) { ...; printf("%s\n", answer); }

ldaniele
New poster
Posts: 6
Joined: Sat Aug 12, 2006 2:26 am

264 WA

Post by ldaniele » Sat Aug 12, 2006 4:09 am

What's wrong in my code (that could be optimised)

#include<iostream>

//#define PROVA
#ifdef PROVA

#include<fstream>
using std::ofstream;
using std::ifstream;
//using std::cout;
ofstream cout("output.txt");
ifstream cin("input.txt");

#endif
#ifndef PROVA

using std::cin;
using std::cout;

#endif

inline void elaborate(int n){
int term=n;
int minus=1, diag=1;
while(n>minus){
n-=minus;
minus+=1;
diag++;
}
//minus ora rappresenta la riga su cui si trova(da 1)
int den=0;
if(diag%2==0){
den=diag-(n-1);
//n rimane com'

ldaniele
New poster
Posts: 6
Joined: Sat Aug 12, 2006 2:26 am

Post by ldaniele » Sat Aug 12, 2006 4:39 am

i've solved!
There was a problem with input!
I had to put a test of nullity after cin!

Vexorian
Learning poster
Posts: 100
Joined: Sat Aug 26, 2006 5:50 am

264 PE?

Post by Vexorian » Thu Aug 31, 2006 8:15 pm

The problem says "No blank line should appear after the last number." But when I try not to have a blank line after last output it tells me Presentation Error, if I make it have a blank line after the last output, my solution gets AC

User avatar
jainal cse du
New poster
Posts: 23
Joined: Thu Jul 27, 2006 2:43 pm
Location: University of Dhaka,Bangladesh

Post by jainal cse du » Thu Mar 22, 2007 10:06 am

Why I am gettiong PE?
I have taken input & print output as

Code: Select all

while(scanf("%ld",&term) == 1)
{
       after calcultaing  result 
   
         printf("TERM %ld IS %ld / %ld\n",term,a,b);
}

My program take 7.258 sec to solve this problem.
But I have seen some people solve it 0.000 sec.


Can Anybody tell me What's the algorithm for this problem?

Post Reply

Return to “Volume 2 (200-299)”