## Search found 215 matches

Thu Sep 20, 2007 8:34 am
Forum: Volume 112 (11200-11299)
Topic: 11275 - 3D Triangles
Replies: 6
Views: 3862
My AC code's epsilon is 1e-8. Your algorithm is right, but notice the problem statement: "if the distance between two points is equal or less than 1e-6, they are regarded as one point". So you should consider these situations: 1. If the distance between one endpoint of triangle A and one edge of tri...
Wed Sep 12, 2007 2:37 am
Forum: Algorithms
Topic: Whether a 3D vector is on the clockwise side of another one
Replies: 1
Views: 1457
Oh, I'm so stupid, there is no clockwise in 3-dimension coordinate system.
Sorry.
Tue Sep 11, 2007 5:32 pm
Forum: Algorithms
Topic: Whether a 3D vector is on the clockwise side of another one
Replies: 1
Views: 1457

### Whether a 3D vector is on the clockwise side of another one

I know for two 2-dimension vectors u and v, calculate the cross product of u and v. if it is positive,then u is on the clockwise side of v.
How to extend this problem to 3 dimension?
Mon Jul 16, 2007 1:13 pm
Forum: Algorithms
Topic: Get the maximun product.
Replies: 4
Views: 2141
OK, the second problem is a little bit different, but I'm trying to understand it.
Thanks.
Mon Jul 16, 2007 12:50 pm
Forum: Algorithms
Topic: Get the maximun product.
Replies: 4
Views: 2141
Oh, thank you. You described it very clearly.
But a further question:
It is said when dividind X into n parts, and X1 must not be less than A (A > X / n), then the optimal partition is X1 = A, X2 = X3 ... = Xn = (X - A) / (n - 1).
Is it true?
Mon Jul 16, 2007 8:22 am
Forum: Algorithms
Topic: Get the maximun product.
Replies: 4
Views: 2141

### Get the maximun product.

It is said if you want to divide a positive number X to n parts, X1, X2 ... Xn, that X1 + X2 ... + Xn = X, and make their product X1 * X2 ... * Xn maximun, you should divide X averagely, i.e. X1 = X2 = ... = Xn = (X / n).
Is it true? If any, can anybody prove it for me.
Thanks.
Sun Jul 15, 2007 6:24 am
Forum: Volume 111 (11100-11199)
Topic: 11107 - Life Forms
Replies: 21
Views: 13882
I couldn't find a more efficient algorithm, but unfortunately I get a 'memory limit exceeded'. Any idea ?? To avoid MLE, you should not copy the substrings to other places, but just reference the pointers of their original places. And don't use STL string for this problem, but use the C style strin...
Thu Jun 28, 2007 12:30 pm
Forum: C++
Topic: Why can we use the manipulators in <iomanip>
Replies: 3
Views: 2090
Oh, I see. The manipulators in <iomanip> don't use the overloads of operator << in <ostream>, but the overloads defined in <iomanip> which are not visible for us. Am I right?
Thu Jun 28, 2007 8:25 am
Forum: C++
Topic: Why can we use the manipulators in <iomanip>
Replies: 3
Views: 2090

### Why can we use the manipulators in <iomanip>

It is said the manipulators in the header <iomanip> can be used in the operator <<, such as: cout << setbase(16) << 100 << endl; But when I read the manual of the header <iomanip>, here , I found none of the manipulators receives argument of type ios_base. So I can't understand which overload of ope...
Wed Dec 27, 2006 7:29 am
Forum: C++
Topic: Why we can use "while(cin >> a)"
Replies: 6
Views: 3255
Yes, I find it in the basic_ios.h.

Code: Select all

``````/**
*  @brief  The quick-and-easy status check.
*
*  This allows you to write constructs such as
*  "if (!a_stream) ..." and "while (a_stream) ..."
*/
operator void*() const
{ return this->fail() ? 0 : const_cast<basic_ios*>(this); }``````
Mon Dec 18, 2006 4:05 pm
Forum: C++
Topic: A class with static member function. Compile error.
Replies: 2
Views: 1915
Thank you.
Mon Dec 18, 2006 2:14 pm
Forum: C++
Topic: A class with static member function. Compile error.
Replies: 2
Views: 1915

### A class with static member function. Compile error.

This is my code: #include <iostream> using namespace std; class A { private: static int a; public: static void set(int i) { a = i; } static void get() { cout << a << endl; } }; int main() { A::set(199); A::get(); return 0; } This is the compiling result: /tmp/ccaeaQQB.o: In function `A::set(int)': s...
Tue Oct 17, 2006 5:02 am
Forum: C++
Topic: Is a class implicitly a friend class of itself?
Replies: 5
Views: 2947
Watch the function "f()" in my first post. It changes the value of a variable in another object. I think it's strange. I typed another code and it get compilation error. #include <iostream> using namespace std; class B { private: int i; }; class A { public: void f(B& b) { b.i++; cout << b.i << endl;...
Fri Oct 13, 2006 6:16 am
Forum: C++
Topic: STL :: sort + binary search for character array!
Replies: 2
Views: 2079
Elements to be sorted by "sort()" must has an "<" operator. I don't know how to sort a 2-dimension array. Maybe you should put your string in to an structure. Like this code: struct MyStr { char str[100]; bool operator < (const MyStr& s) const { return strcmp(str, s.str) < 0; } }; main() { MyStr str...
Wed Oct 11, 2006 12:00 pm
Forum: C++
Topic: Is a class implicitly a friend class of itself?
Replies: 5
Views: 2947

### Is a class implicitly a friend class of itself?

Watch this code: #include <iostream> using namespace std; class A { private: int i; public: A() { i = 0; } void f(A& a) { a.i++; cout << a.i << endl; } }; int main() { A a, b; a.f(b); return 0; } It is accepted by the compiler(g++ 4.1.0). I think it's strange. A class can access the member variable ...