Author |
Topic |
Stoad
Freaky Yak Linguist
1983 Posts |
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2005-01-06 : 15:05:55
|
[code]create table dbo.posters (n int identity(0,1), l int, r int)insert into postersselect 1, 2 union allselect 5, 6 union allselect 1, 4 union allselect 2, 6 union allselect 8, 10 union allselect 3, 4 union allselect 7, 10 gocreate function dbo.isblocked (@n int, @l int,@r int)returns bitasbegin declare @isblocked bit set @isblocked = 0 if exists ( select 1 from dbo.posters where l <= @l and r >= @r and n > @n ) set @isblocked = 1 return @isblockedendgoselect l,r,dbo.isblocked(n,l,r) blockedfrom postersorder by n descgodrop table postersdrop function dbo.isblocked[/code] |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-01-06 : 15:12:10
|
you're kidding me. ehorn you had that stashed somewhere didn't you Go with the flow & have fun! Else fight the flow |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-01-06 : 15:51:28
|
lol!obviously it can't be accepted! or can? hahathat's why I love that e-judge. You can't cheat "him"!btw, time limit is the crucial point of 80% of those problems.... and seriously, 70% of them are very very very hard problems. |
 |
|
ehorn
Master Smack Fu Yak Hacker
1632 Posts |
Posted - 2005-01-06 : 16:39:48
|
quote: you had that stashed somewhere didn't you..
LoL.. Nah, just a slow Thursday Not even sure if it satisfies all inputs |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-01-11 : 14:11:13
|
Just for our fun.I bet no-one here can solve this really easy prob even in 3 days.PS Feel free to post your solutions written in t-sql. I'll check them. |
 |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-26 : 11:42:00
|
quote: Originally posted by Stoad Just for our fun.I bet no-one here can solve this really easy prob even in 3 days.PS Feel free to post your solutions written in t-sql. I'll check them.
I guess my euclidian geometry skills are not up to date.Geel free to post a solution.rockmoose |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-02-26 : 18:57:42
|
rocko, it's not interesting (a right solution). I just was waiting forsomeone come up with "oh! it's so easy! iif (a<c) AND (b<d) then ... ".And of course, this solution is wrong ... in general case.uses math;var tc,tcs,aa,bb,xx,yy: longint; a,b,x,y,e,h: double;beginreadln(tcs);for tc:=1 to tcs dobeginreadln(aa,bb,xx,yy);a:=min(aa,bb); b:=max(aa,bb); x:=min(xx,yy); y:=max(xx,yy);if (x<a)and(y<b) then writeln('Escape is possible.')elseif (x>=a)or(y*y>=a*a+b*b) then writeln('Box cannot be dropped.')elsebegine:=x*(a*x+sqrt(sqr(a*x)+(x*x+y*y)*(y*y-a*a)))/(x*x+y*y);h:=(b*y-y*y*e/x)/(a-e);if (sqrt(y*y-(a-e)*(a-e))<b)and(h>x)then writeln('Escape is possible.')else writeln('Box cannot be dropped.');end;end;end. |
 |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-27 : 06:51:58
|
The diagonal/general case is non-trivial.Got me stumped, makes me really annoyed.Can't get e the way Yo do... e=f(a,x,y)Oh well, maybe another day I'll try again.rockmoose |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-02-27 : 07:45:43
|
> Got me stumped, makes me really annoyed.Yes, rocko. It's an extremely irritating problem.I myself was in amok state while been trying to solve it.How about next SQL problem:create table processes (t1 datetime, t2 datetime)t1 and t2 mean: a process was running from point in Time t1 to point in Time t2 (including).Problem: to write the most efficient and compact query which counts the maximal numberof processes running simultaneously.For simplicity we can use int datatype instead of datetime datatype.create table p (n1 int, n2 int)goinsert into pselect 3, 8 union allselect 0, 2 union allselect 3, 8 union allselect 6, 7 union allselect 7, 9 union allselect 3, 8goanswer is 5. |
 |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-27 : 08:11:09
|
>> I myself was in amok state while been trying to solve it.Don't even speak of it... Aaaaarghh.select top 1 count(*) from (select distinct n1,n2 from p) p1 join p p2 on p2.n1 <= p1.n2 and p2.n2 >= p1.n1group by p1.n1,p1.n2order by 1 desc I guess it's my turn to find a puzzle, I'll see what I can come up with.rockmoose |
 |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-27 : 09:04:30
|
--Given a table t with one column a(int) with 3 rows,--How many rows will this query return ?select a from t where (a=1) or not(a=1)rockmoose |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-27 : 09:22:22
|
emmm.... all.Go with the flow & have fun! Else fight the flow |
 |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-27 : 11:00:23
|
You know it depends....Given the uncompleteness of the information, the query could return 0,1,2 or 3 rows.If I give one more piece of information:"a is unique"How many rows will the query return?rockmoose |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-27 : 11:18:04
|
can you shom me how it can return less than 3???declare @t table (a int)insert into @tselect 1 union all--select 1 union all -- uncomment for un-uniqueness--select 1 union all -- uncomment for un-uniquenessselect 2 union all -- comment for un-uniquenessselect 3 -- comment for un-uniquenessselect * from @t where (a=1) or not(a=1) because as i see it the where always evaluates to trueGo with the flow & have fun! Else fight the flow |
 |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-27 : 11:31:15
|
It's somewhat of a trick question.....declare @t table (a int /*unique*/)insert into @t values(1)insert into @t values(2)insert into @t default valuesselect * from @t where (a=1) or not(a=1) rockmoose |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-27 : 11:35:34
|
huh??what's with the insert into @t default values ??you don't specify it anywhere.declare @t table (a int default(1) /*unique*/)insert into @t values(1)insert into @t values(2)insert into @t default values-- returns 3 rows if /*unique*/select * from @t where (a=1) or not(a=1)-- errors out if uniqueselect * from @t where (a=1) or not(a=1) Go with the flow & have fun! Else fight the flow |
 |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-27 : 13:17:07
|
The default value for a column = null when no explicit default is provided.The point is that the rules of 3VL(true/false/NULL)are NOT the same as the rules of "ordinary" 2VL logic(true/false).(for this example NULL simply represents "value not known", and makes no distinction as to why - (not entered, n/a, unknown, not valid etc...))In 2VL:A OR NOT(A) = TRUEWith nulls:A OR NOT(A) OR (A IS NULL) = TRUEThis was an extremely trivial example,but nonetheless I think it demonstrates that NULL can be a source of confusion and error.rockmoose |
 |
|
Stoad
Freaky Yak Linguist
1983 Posts |
Posted - 2005-02-27 : 13:27:45
|
quote: Originally posted by rockmoose
select top 1 count(*) from (select distinct n1,n2 from p) p1 join p p2 on p2.n1 <= p1.n2 and p2.n2 >= p1.n1group by p1.n1,p1.n2order by 1 desc
a bit impolitely of you to produce this brilliant solution ...... soooo fast! :) |
 |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-27 : 14:16:44
|
moose: ooooohhhhhhh..... that's your point. ok then.Go with the flow & have fun! Else fight the flow |
 |
|
rockmoose
SQL Natt Alfen
3279 Posts |
Posted - 2005-02-27 : 15:48:59
|
>> moose: ooooohhhhhhh..... that's your pointWell yeah, no more no less, setting a tiny "logic trap">> a bit impolitely of you to produce this brilliant solution ...... soooo fast! :)Good problem...You must unlearn what you have learntrockmoose |
 |
|
Next Page
|