Skip to content

Commit 37bd7f4

Browse files
author
Jie Feng
committed
haha
2 parents 39c40db + 2ae828b commit 37bd7f4

20 files changed

+562
-57
lines changed

codeforces/438C.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -981,18 +981,34 @@ int n;
981981
#define nn(x) (x>=n?x-n:x)
982982
const ll mod = 1000000007;
983983

984-
typedef point pt;
985-
typedef double ld;
986984

987-
inline bool between(pt a, pt b, pt c)
985+
inline bool between(point a, point b, point c)
988986
{
989-
ld aa = atan2(a.y, a.x);
990-
ld ab = atan2(b.y, b.x);
991-
ld ac = atan2(c.y, c.x);
987+
double aa = atan2(a.y, a.x);
988+
double ab = atan2(b.y, b.x);
989+
double ac = atan2(c.y, c.x);
992990
while (ab < aa) ab += 2 * 3.14159265358;
993991
while (ac < aa) ac += 2 * 3.14159265358;
994992
return ac < ab;
995993
}
994+
995+
bool inside_polygon(int j1, int j2, int n, point p[], double area){
996+
// assert(j1 < j2);
997+
/* double area = 0;
998+
* for (int i = 0; i < n; i++) area += p[i] * p[i + 1];
999+
* if (area < 0){
1000+
* reverse(p, p + n);
1001+
* area = -area;
1002+
* }
1003+
* p[n] = p[0];
1004+
*/
1005+
1006+
double sq = 0;
1007+
for (int i = 0; i < j1; i++) sq += p[i] * p[i + 1];
1008+
sq += p[j1] * p[j2];
1009+
for (int i = j2; i < n; i++) sq += p[i] * p[i + 1];
1010+
return 0 <= sq && sq <= area;
1011+
}
9961012
int main(){
9971013
scanf("%d", &n);
9981014
clr(can, true);
@@ -1008,24 +1024,17 @@ int main(){
10081024
{
10091025
reverse(p, p + n);
10101026
p[n] = p[0];
1027+
sq = -sq;
10111028
}
10121029

1013-
if (p[0].x == -744281){
1014-
cout << 144076085 << endl;
1015-
return 0;
1016-
}
1017-
1018-
if (p[0].x == -62958){
1019-
cout << 589057227 << endl;
1020-
return 0;
1021-
}
10221030

10231031

10241032
F(i,0,n)
10251033
F(j,i+2,n){
10261034
if (i == 0 && j == n-1) continue;
10271035
// if (!inside_polygon(p[j], p[i], n, p)){
1028-
if (!between(p[j + 1] - p[j], p[j - 1] - p[j], p[i] - p[j])) {
1036+
if (!inside_polygon(i, j, n, p, sq)){
1037+
// if (!between(p[j + 1] - p[j], p[j - 1] - p[j], p[i] - p[j])) {
10291038
// cout << i << ' ' << j << endl;
10301039
can[i][j] = can[j][i] = false;
10311040
continue;

codeforces/in

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
4
2-
0 0
3-
0 1
4-
1 1
5-
1 0
1+
5
2+
0 0
3+
1 0
4+
1 1
5+
0 1
6+
-2 -1

interview/convert-BST-to-doublelinkedlist.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* Facebook
2+
* http://www.mitbbs.com/article_t/JobHunting/32705761.html
3+
*/
14
#include<iostream>
25

36
using namespace std;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//http://www.mitbbs.com/article_t/JobHunting/32709291.html
2+
#include<iostream>
3+
#include<string>
4+
#include<vector>
5+
using namespace std;
6+
7+
8+
vector<string> convert_string_to_words(string s){
9+
10+
11+
}
12+
int main(){
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//http://www.mitbbs.com/article_t/JobHunting/32708493.html
2+
/**
3+
* Definition for singly-linked list with a random pointer.
4+
* struct RandomListNode {
5+
* int label;
6+
* RandomListNode *next, *random;
7+
* RandomListNode(int x) : label(x), next(NULL), random(NULL) {}
8+
* };
9+
*/
10+
class Solution {
11+
private:
12+
map<RandomListNode*, RandomListNode*> mRR;
13+
public:
14+
RandomListNode *copyRandomList(RandomListNode *head) {
15+
if (head == NULL) return NULL;
16+
RandomListNode* cur = new RandomListNode(head->label);
17+
mRR[head] = cur;
18+
cur->next = copyRandomList(head->next);
19+
cur->random = mRR[head->random];
20+
return cur;
21+
}
22+
};

interview/count-inversions.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* http://www.mitbbs.com/article_t/JobHunting/32708791.html
3+
*/
4+
#include<iostream>
5+
#include<cstring>
6+
#include<vector>
7+
using namespace std;
8+
9+
10+
11+
int merge(int A[], int L, int M, int R){
12+
int *B = new int[R-L+1];
13+
int L1 = L, L2 = M+1, i = 0;
14+
int cnt = 0;
15+
while(L1 <= M && L2 <= R){
16+
if (A[L1] <= A[L2]){
17+
B[i++] = A[L1++];
18+
cnt += L2-(M+1);
19+
}else
20+
B[i++] = A[L2++];
21+
}
22+
23+
if (L1 <= M){
24+
cnt += (M+1-L1) * (R-M);
25+
while(L1 <= M){
26+
B[i++] = A[L1++];
27+
}
28+
}else{
29+
while(L2 <= R){
30+
B[i++] = A[L2++];
31+
}
32+
}
33+
34+
memcpy(A+L, B, sizeof(int)*(R-L+1));
35+
return cnt;
36+
}
37+
38+
int count(int A[], int L, int R){
39+
if (L == R) return 0;
40+
int M = (L + R) / 2;
41+
int cnt = count(A, L, M) + count(A, M+1, R);
42+
// cout << L << ' ' << R << ' ' << cnt << endl;
43+
cnt += merge(A, L, M, R);
44+
return cnt;
45+
}
46+
47+
int main(){
48+
int A[] = {5,4,3,2,1};
49+
int n = sizeof(A)/4;
50+
cout << count(A, 0, n-1) << endl;
51+
}

interview/count-numbers-contain-5

70.4 KB
Binary file not shown.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* http://www.mitbbs.com/article_t/JobHunting/32710149.html
3+
*
4+
给任意一个数N,求小于N的数里含数字5的个数。
5+
比如26,小于26的数有5,15,25含有5,所以返回3。
6+
这题看起来挺简单,可是给跪了。。。。。
7+
*/
8+
#include<iostream>
9+
#include<vector>
10+
using namespace std;
11+
12+
int count_numbers_contain(int n, int b){
13+
if (n <= 0) return 0;
14+
vector<int> bits;
15+
while(n != 0){
16+
bits.push_back(n % 10);
17+
n /= 10;
18+
}
19+
vector<int> ten(bits.size()+1);
20+
21+
vector<int> F(bits.size()+1);
22+
23+
//F[i] = count of numbers of i+1 digits which contanis specific bit
24+
25+
F[0] = 0;
26+
ten[0] = 1;
27+
for (int i = 1; i < bits.size(); i++){
28+
ten[i] = ten[i-1] * 10;
29+
F[i] = F[i-1] * 9 + ten[i-1];
30+
}
31+
32+
int cnt = 0;
33+
for (int i = bits.size()-1; i >= 0; i--){
34+
35+
36+
if (b < bits[i]){
37+
cnt += ten[i];
38+
cnt += (bits[i]-1) * F[i];
39+
}else cnt += bits[i] * F[i];
40+
41+
if (bits[i] == b && i != 0){
42+
cnt += n % ten[i-1];
43+
break;
44+
}
45+
}
46+
if (b == 0){
47+
for (int i = bits.size()-1; i >= 1; i--){
48+
cnt -= 9 * ten[i-1];
49+
}
50+
}
51+
return cnt;
52+
}
53+
int main(){
54+
cout << count_numbers_contain(23, 0) << endl;
55+
}
123 KB
Binary file not shown.

interview/expression.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* given 一个字符串,这个字符串是一个算式,包含加减乘除,没有括号,符号和数
3+
字之间以一个空格格开,比如:“1 + 2 * 4 / 5”,return算式的结果
4+
*/
5+
#include<iostream>
6+
#include<string>
7+
#include<stack>
8+
#include<sstream>
9+
using namespace std;
10+
11+
int expression(string exp){
12+
stringstream ss(exp);
13+
char c, op;
14+
15+
stack<int> nums;
16+
stack<char> ops;
17+
18+
int num, num1;
19+
20+
while(true){
21+
// cout << "New round ....." << endl;
22+
while(!ss.eof() && ss.peek() == ' '){
23+
// cout << ss.peek() << " ";
24+
ss.get(c);
25+
// cout << (int)c << endl;
26+
}
27+
28+
if (ss.eof()) break;
29+
c = ss.peek();
30+
31+
if ('0' <= c && c <= '9'){
32+
ss >> num;
33+
if (!ops.empty()){
34+
op = ops.top();
35+
if (op == '*' || op == '/'){
36+
ops.pop();
37+
num1 = nums.top(); nums.pop();
38+
if (op == '*'){
39+
num = num1 * num;
40+
}else{
41+
num = num1 / num;
42+
}
43+
}
44+
}
45+
nums.push(num);
46+
}else{
47+
ss >> op;
48+
ops.push(c);
49+
}
50+
}
51+
while(!ops.empty()){
52+
num = nums.top(); nums.pop();
53+
num1 = nums.top(); nums.pop();
54+
op = ops.top(); ops.pop();
55+
if (op == '+'){
56+
nums.push(num1+num);
57+
}else{
58+
nums.push(num1-num);
59+
}
60+
}
61+
return nums.top();
62+
63+
64+
}
65+
66+
67+
int main(){
68+
cout << expression("1 + 2 * 4 * 5") << endl;
69+
}
70+

0 commit comments

Comments
 (0)