264 - Count on Cantor
Moderator: Board moderators
-
- New poster
- Posts: 4
- Joined: Wed Nov 16, 2005 8:54 pm
-
- New poster
- Posts: 33
- Joined: Tue Jun 29, 2004 1:38 pm
- Location: IITM,chennai,Tamil Nadu,India
- Contact:
264 Output Limit Exceeded
#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
#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
This is my output
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
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
-
- New poster
- Posts: 1
- Joined: Tue Apr 25, 2006 11:26 am
- Location: In the Hidden Leaf Village
- Contact:
Time Limit Exceeded 264!!! Help!!!
...
....
....
CODE
....
....
CODE
Last edited by Pachy_4_Ever on Tue Apr 25, 2006 11:28 pm, edited 1 time in total.
264 - simple questtion
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
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
Your program should read input from the standard input. For example, in this way (C++):
or this (C):
Code: Select all
int n;
while (cin >> n) { <compute answer>; cout << answer << endl; }
Code: Select all
while (scanf("%d", &n) == 1) { ...; printf("%s\n", answer); }
264 WA
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'
#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'
264 PE?
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
-
- New poster
- Posts: 23
- Joined: Thu Jul 27, 2006 2:43 pm
- Location: University of Dhaka,Bangladesh
Why I am gettiong PE?
I have taken input & print output as
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?
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?