Skip to content

Commit b05496f

Browse files
committed
add a URAL problem
1 parent 93fe302 commit b05496f

File tree

7 files changed

+134951
-12
lines changed

7 files changed

+134951
-12
lines changed

ural/1178.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include <iostream>
2+
#include <cstdlib>
3+
#include <string>
4+
#include <vector>
5+
#include <algorithm>
6+
#include <queue>
7+
#include <list>
8+
#include <stack>
9+
#include <map>
10+
#include <set>
11+
using namespace std;
12+
13+
14+
typedef long long ll;
15+
typedef struct my_node{
16+
ll x, y;
17+
}point;
18+
19+
const int MAXN = 10500;
20+
point points[MAXN];
21+
int N;
22+
23+
vector< point > ans;
24+
25+
26+
void proc( int n_points, vector< ll > pp){
27+
if(n_points == 0)return ;
28+
if(n_points == 2){
29+
point tmp;
30+
tmp.x = pp[0];
31+
tmp.y = pp[1];
32+
ans.push_back(tmp);
33+
return ;
34+
}
35+
36+
int sz = pp.size();
37+
38+
vector<ll> left;
39+
vector<ll> right;
40+
41+
int ls =0, rs = 0, a, b;
42+
while(1){
43+
a = rand()%sz;
44+
b = rand()%sz;
45+
if(a == b)b = (a+1)%sz;
46+
47+
left.clear(); right.clear();
48+
49+
//cout<<"a = "<<a<<" b = "<<b<<endl;
50+
51+
ll x1 = points[pp[a]].x;
52+
ll y1 = points[pp[a]].y;
53+
ll x2 = points[pp[b]].x;
54+
ll y2 = points[pp[b]].y;
55+
ls = 0, rs = 0;
56+
57+
for(int i=0; i<sz; i++){
58+
//cout<<"i = "<<i<<endl;
59+
if(i==a || i==b)continue;
60+
61+
ll x = points[pp[i]].x;
62+
ll y = points[pp[i]].y;
63+
64+
//cout<<(y-y1)<<" "<<(x2-x1)<<endl;
65+
ll _tmp = (y-y1)*(x2-x1) - (y2-y1)*(x-x1);
66+
if( _tmp > 0LL){
67+
left.push_back(pp[i]);
68+
ls += 1;
69+
}else if(_tmp < 0LL) {
70+
right.push_back(pp[i]);
71+
rs += 1;
72+
}
73+
}
74+
//cout<<ls<<" "<<rs<<endl;
75+
if( rs%2 == 1 || ls%2 == 1)continue;
76+
//cout<<"ok"<<endl;
77+
break;
78+
}
79+
80+
point tmp;
81+
tmp.x = pp[a];
82+
tmp.y = pp[b];
83+
84+
ans.push_back(tmp);
85+
86+
proc(left.size(), left);
87+
proc(right.size(), right);
88+
}
89+
90+
91+
void work(){
92+
vector<ll> tmp;
93+
for(int i=0; i<N; i++){
94+
tmp.push_back(i);
95+
}
96+
97+
proc(tmp.size(), tmp );
98+
for(int i=0; i<ans.size(); i++){
99+
cout<<ans[i].x+1<<" "<<ans[i].y+1<<endl;
100+
}
101+
ans.clear();
102+
103+
}
104+
105+
106+
107+
108+
int main(){
109+
110+
while(cin>>N){
111+
112+
for(int i=0; i<N; i++){
113+
cin>>points[i].x>>points[i].y;
114+
}
115+
work();
116+
}
117+
118+
return 0;
119+
}
120+

ural/1749.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import numpy as np
2+
3+
4+
x1 = 150*100/(100+100+150+1.0/3)
5+
x2 = x1
6+
x3 = 150*150/(100+100+150+1.0/3)
7+
x4 = 1.0/3
8+
9+
10+
print x1, x2, x3, x4
11+
12+
13+
print (x1*1000 + x2*750 + x3*585 + x4*0)/(1000.0 * 150)
14+
42.81636536631779677009
15+
64.22454804947669515514
16+
42.81636536631779677009
17+
0.33333333333331144344
18+
19+
print (42.81636536631779677009 + .585*64.22454804947669515514 + .750*42.81636536631779677009 )/150
20+
21+
42.85714285714285409767
22+
64.28571428571429180465
23+
42.85714285714285409767
24+
0.00000000000000000000
25+
26+
27+
print (42.85714285714285409767 + .585*64.28571428571429180465 + .750*42.85714285714285409767 )/150

ural/1757.cpp

Lines changed: 104 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include <iostream>
22
#include <string>
3+
#include <iomanip>
34
#include <vector>
45
#include <algorithm>
56
#include <queue>
67
#include <list>
8+
#include <cmath>
79
#include <stack>
810
#include <map>
911
#include <set>
@@ -15,17 +17,107 @@ using namespace std;
1517
#define VE vector<int>
1618
#define SZ size()
1719
#define PB push_back
18-
19-
int main()
20-
#ifndef ONLINE_JUDEGE
21-
freopen("input.txt","r",stdin);
22-
#endif
23-
24-
#ifdef DEBUG
25-
// to write some values for debugging purposes, e.g.,
26-
int i =5;
27-
printf("%d",i);
28-
#endif
29-
return 0;
20+
21+
const int MAXN = 10001;
22+
int n, m;
23+
double p;
24+
25+
const double eps = 1e-9;
26+
27+
struct node{
28+
int p;
29+
int weight;
30+
int idx;
31+
}L[MAXN];
32+
int cmp(const struct node &a, const struct node &b){
33+
return a.p>b.p;
34+
}
35+
36+
double ans[MAXN];
37+
int ans_idx = 0;
38+
void work(){
39+
40+
std::cout.precision(15);
41+
std::cout<<std::fixed;
42+
43+
sort(L, L+n, cmp);
44+
45+
bool ok = true;
46+
if(L[0].p<p || L[n-1].p > p){
47+
ok = false;
48+
}
49+
50+
double cur_p = 0, pure;
51+
int pos = -1, sum_weight = 0;
52+
53+
ans_idx = 0;
54+
for(int i=0; i<n; i++){
55+
int w_sum = sum_weight + L[i].weight;
56+
pure = (sum_weight*cur_p + L[i].weight*L[i].p)*1.0/w_sum;
57+
//cout<<"now pure = "<<pure<<endl;
58+
if(pure - p < eps && sum_weight + L[i].weight>= m){
59+
pos = i;
60+
//cout<<"breaking "<<endl;
61+
break;
62+
}
63+
//ans.push_back( L[i].weight );
64+
ans[L[i].idx] = L[i].weight;
65+
ans_idx += 1;
66+
sum_weight += L[i].weight;
67+
cur_p = pure;
68+
}
69+
if(pos == -1){
70+
ok = false;
71+
}
72+
73+
double add;
74+
if(fabs(p-L[pos].p) <= 0){
75+
add = L[pos].weight;
76+
}else{
77+
add = (cur_p - p)*1.0*sum_weight/(p-L[pos].p);
78+
}
79+
80+
/*
81+
cout<<"sum_weight = "<<sum_weight<<endl;
82+
cout<<"melt = "<<melt_sum<<endl;
83+
*/
84+
if(add + sum_weight < m){
85+
ok = false;
86+
}
87+
88+
if(ok==false){
89+
cout<<"NO"<<endl;
90+
return ;
91+
}
92+
93+
double melt_sum = add;
94+
for(int i=0; i<ans_idx; i++){
95+
melt_sum += ans[i];
96+
}
97+
cout<<"YES"<<endl;
98+
for(int i=0; i<ans_idx; i++){
99+
double tmp = ans[i]*m*1.0/melt_sum;
100+
cout<<tmp<<endl;
101+
102+
}
103+
cout<<add<<endl;
104+
}
105+
106+
107+
108+
int main(){
109+
110+
111+
cin>>n>>m>>p;
112+
113+
for(int i=0; i<n; i++){
114+
cin>>L[i].weight;
115+
cin>>L[i].p;
116+
//L[i].p/= 1000.0;
117+
p*= 1.0;
118+
L[i].idx = i;
119+
}
120+
work();
121+
return 0;
30122
}
31123

ural/a.out

11.1 KB
Binary file not shown.

ural/b.p

Whitespace-only changes.

0 commit comments

Comments
 (0)