Not a TriangleProblem code: NOTATRI |
All submissions for this problem are available.
A tutorial for this problem is available here.
You have N (3 ? N ? 2,000) wooden sticks, which are labeled from 1 to N. The i-th stick has a length of Li (1 ? Li ? 1,000,000). Your friend has challenged you to a simple game: you will pick three sticks at random, and if your friend can form a triangle with them (degenerate triangles included), he wins; otherwise, you win. You are not sure if your friend is trying to trick you, so you would like to determine your chances of winning by computing the number of ways you could choose three sticks (regardless of order) such that it is impossible to form a triangle with them.
Input
The input file consists of multiple test cases. Each test case starts with the single integer N, followed by a line with the integers L1, ..., LN. The input is terminated with N = 0, which should not be processed.
Output
For each test case, output a single line containing the number of triples.
Example
Input: 3 4 2 10 3 1 2 3 4 5 2 9 6 0 Output: 1 0 2
For the first test case, 4 + 2 < 10, so you will win with the one available triple. For the second case, 1 + 2 is equal to 3; since degenerate triangles are allowed, the answer is 0.
| Author: | admin |
| Date Added: | 1-12-2008 |
| Time Limit: | 2 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

What does M stand for in memory = 2.5M? Is it MB or what?
can 2 sticks have same length ?
got it :D they can be same.
@tarin Yes, it stands for MB
Time 2s s== ?
Seconds..
can some sticks be of equal length. if yes then should we consider triplets like 1 2 4 and 1 2 4 different or same?
@atul It seems you've figured that out yourself :)
i concluded answer is yes to my question
I am considering 2 triplet of
Yes, if I understand you
Yes, if I understand you correctly, you are right in assuming so. :)
i want information about how
i want information about how to improve my skills and al and i m MBA student so guide me plz
if degenrate triangles are
if degenrate triangles are allowed , then y is ans of second test case 0 ??
shouldnt it be 1 ??
i got it , my mistake ,
i got it , my mistake ,
i dnt seem to find y i am
i dnt seem to find y i am getting wrong ans.. plz help
what is the problem wid
what is the problem wid foloowing search algo ..
count=0;
for(i=0;i<sortindex-2;i++)//0 1 2 5 6 9
{
for(tmp=i+1;tmp<sortindex-1;tmp++)//1 2
{
n=sorted[i]+sorted[tmp];
lb=tmp+1;
ub=sortindex-1;
mid=(lb+ub)/2;
while(lb<ub)
{
if(sorted[mid]>n)
{
ub=mid-1;
mid=(lb+ub)/2;
}
else
if(sorted[mid]<n)
{
lb=mid+1;
mid=(lb+ub)/2;
}
else
break;
}
while(sorted[mid]==n)
mid++;
if(sorted[mid]>n)
count+=sortindex-mid;
}
}
plz help I wrote the
plz help
I wrote the following code:
#include<stdio.h>
void sort_merge_aux(int , int);
void sort_merge(int, int, int);
//int p=0;
long int arr[2000];
long int temp[1000];
void sort_merge_aux(int low,int high)
{
int mid;
if(low!=high)
{
mid=(low+high)/2;
sort_merge_aux(low,mid);
sort_merge_aux(mid+1,high);
sort_merge(low,mid,high);
}
}
void sort_merge(int low,int mid,int high)
{
int i,j,k;
i=low;
j=mid+1;
k=low;
while((i<=mid)&&(j<=high))
{
if(arr[i]>=arr[j])
temp[k++]=arr[j++];
else
temp[k++]=arr[i++];
}
while(i<=mid)
temp[k++]=arr[i++];
while(j<=high)
temp[k++]=arr[j++];
for(i=low;i<=high;i++)
arr[i]=temp[i];
}
int search_number(long int k,int lower,int num)
{
int mig,low,mid,high,found=0,var;
//var=-1;
// mig=0;
low=lower;
high=num-1;
while(low<=high)
{
mid=(low+high)/2;
if(k>arr[mid])
low=mid+1;
else if(k<arr[mid])
high=mid-1;
else
{
// found=1;
// var=mid;
break;
}
}
if(high<lower)
return (high+1);
if(low>num-1)
return low;
if(low<=high)
{
while(arr[mid]==k)
mid++;
return mid;
}
else
{
if(arr[high]>k&&arr[low]>k)
return high-1;
else if(arr[high]<k&&arr[low]>k)
return (high+1);
//else if(arr[high]>k&&arr[low]<k)
// return ;
else if(arr[high]<k&&arr[low]<k)
return low+1;
}
}
int main()
{
long nt,n,m,p,not_a_triangle;
int t,num;
register long int i,j,k;
scanf("%d",&num);
while(num!=0)
{
t=0;
while(t<num)
{
scanf("%d",&arr[t]);
t++;
}
sort_merge_aux(0,num-1);
not_a_triangle=0;
for(i=0;i<num-2;i++)
{
for(j=i+1;j<num-1;j++)
{
not_a_triangle+=num-search_number(arr[i]+arr[j],j+1,num);
}
}
printf("%dn",not_a_triangle);
scanf("%d",&num);
}
//getch();
return 0;
}
but I get runtime error.i have checked for
-memory limit is not exceeded if long int is of 8byte or less
-array bounds are also not exceeded
please, fellow coders, do NOT
please, fellow coders, do NOT post code here. besides it being hard to read, some people would rather solve the problems themselves without getting hints. see the FAQ for how to post a link to your submission, and people who want to can then see it, properly formatted, there.
plz help! ok! i read faqs but
plz help!
ok! i read faqs but from where can i get
link to the solution i submit
from the problem page, say:
from the problem page, say: http://www.codechef.com/problems/TEST/
to the right of the headline "Life, the Universe, and Everything" you will see 3 buttons: "ALL SUBMISSIONS", "MY SUBMISSIONS", and "SUBMIT". Click "MY SUBMISSIONS".
You will see a list of your submitted programs. Pick the one you want, and on the far right of the row, click "View Solution".
Copy and paste the link from your browser into the Comment page: http://www.codechef.com/viewsolution/110651
I'll review the FAQ, and add this info if needed.
Anyway, I'm not clear on why anyone should help debug other people's, i.e. YOUR, programs. You don't learn nearly as much if someone does it for you. During a contest, nobody is allowed to assist you anyway, and if you have been getting help all along, you'll be, quite literally, helpless. Especially since it seems many contest problems are described incorrectly or the sample input/output is wrong. Do you remember the battleship problem, I think it was in November? The testcases were wrong, but someone solved it anyway before the admins fixed it. Now THAT was a real coder... he not only debugs his programs, he debugged the problem description itself, without assistance.
In first test case, in above
In first test case, in above Ex, how we get one triple? 4+2<10
actually length of largest side should be lesser than sum of other two sides.
Read the problem statement.
Read the problem statement. You are not asked to print out the number of valid triples.
Can anyone name a few
Can anyone name a few boundary test cases where my prog could be failing :( i have tried a lot of em.. but passes here.. The overall result in judge is Wrong Answer
hiii
hiii
how to see the input output
how to see the input output set used...
I have solved the problem as
I have solved the problem as explained in the tutorial (I have used merge sort, by the way), but I am still geting TLE. Moreover, my code is running perfectly within the time limit of 2s on my computer (It gave the answer in 0.17 seconds for N=2000 and N random positive numbers less than 1000000 as input for the lengths of the sticks). I even compared the execution time with that of an accepted solution with the same input, and the accepted solution gave the answer in 0.18 seconds.
Here is the link to my solution: http://www.codechef.com/viewsolution/406062.
Hi, How to figure out number
Hi,
How to figure out number of test cases in advance?
or What is the max no. of test cases?
It is required as I am using C and I have to create array to store results.
It is giving me Runtime Error and I think it is because I was using array of 1000 to store the results.
#include<iostream>#include<co
#include<iostream>
#include<conio.h>
using namespace std;
int main(){
int i,j,k,n,count=0,a[10];
int sum2,sum3;
int max;
while(1){
cin>>n;
if(n==0)
return 0;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n-2;i++){
max=a[i];
for(j=i+1,sum2=0;j<n-1;j++){
if(a[j]>max){
sum2=a[i];
max=a[j];
}
else sum2=a[j];
for(k=j+1,sum3=0;k<n;k++){
if(a[k]>max){
sum3=sum2+max;
max=a[k];
}
else sum3=sum2+a[k];
if(sum3>=max)
count++;
}}}
cout<<count<<endl;
}
getch();
return 0;
}
I am getting a runtime error
Please tell me where I am wrong....
wat i am doing is calculating max of the 3 and putting other 2 in sum and comparing these two....
The time given is for all the
why the program shows error
as far as i know, time limit
http://www.codechef.com/views
http://www.codechef.com/views