您的位置:首页 > 大数据 > 人工智能

2016 Multi-University Training Contest 10

2016-08-18 20:35 344 查看

HDU【5857】——Median

Time Limit: 6000/3000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)

Problem Description

There is a sorted sequence A of length n. Give you m queries, each one contains four integers, l1, r1, l2, r2. You should use the elements A[l1], A[l1+1] … A[r1-1], A[r1] and A[l2], A[l2+1] … A[r2-1], A[r2] to form a new sequence, and you need to find the median of the new sequence.

Input

First line contains a integer T, means the number of test cases. Each case begin with two integers n, m, means the length of the sequence and the number of queries. Each query contains two lines, first two integers l1, r1, next line two integers l2, r2, l1<=r1 and l2<=r2.

T is about 200.

For 90% of the data, n, m <= 100

For 10% of the data, n, m <= 100000

A[i] fits signed 32-bits int.

Output

For each query, output one line, the median of the query sequence, the answer should be accurate to one decimal point.

Sample Input

1

4 2

1 2 3 4

1 2

2 4

1 1

2 2

Sample Output

2.0

1.5

Author

BUPT

分类讨论的题

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int Max =  110000;
LL a[Max];
int main() {
int n,m,T;
int x1,y1,x2,y2;
scanf("%d",&T);
while(T--) {
scanf("%d %d",&n,&m);
for(int i = 1;i<=n;i++) scanf("%lld",&a[i]);
while(m--) {
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
if(x1>x2) {
swap(x1,x2);swap(y1,y2);
}
double ans = 0;
if(y1<x2) {
int len = (y1-x1+1)+(y2-x2+1);
if(len%2 ==0) {
len/=2;
if(x1+len-1<=y1) {
ans+=a[x1+len-1];
}
else ans+=a[x2+(len-(y1-x1+1))-1];
len++;
if(x1+len-1<=y1) {
ans+=a[x1+len-1];
}
else ans+=a[x2+(len-(y1-x1+1))-1];
ans/=2;
}
else {
len=(len+1)/2;
if(x1+len-1<=y1) {
ans+=a[x1+len-1];
}
else ans+=a[x2+(len-(y1-x1+1))-1];
}
}
else {
int l = max(x2,x1);int r = min(y1,y2);
int L = min(x1,x2); int R = max(y1,y2);
int len = (max(y1,y2)-min(x1,x2)+1+(r-l+1));

if(len%2 ==0) {
len/=2; int s = len;
if(L+s-1<l) {
ans+=a[L+s-1];
}
else {
s -= (l-L);
s = (s+1)/2;
if(l+s-1<=r) ans+=a[l+s-1];
else {
s= len-(l-L)-(r-l+1)*2;

ans+=a[r+s];
}
}
len++; s = len;
if(L+s-1<l) {
ans+=a[L+s-1];
}
else {
s -= (l-L);
s = (s+1)/2;
if(l+s-1<=r) ans+=a[l+s-1];
else {
s= len-(l-L)-(r-l+1)*2;

ans+=a[r+s];
}
}

ans/=2;
}
else {

len=(len+1)/2; int s = len;
if(L+s-1<l) {
ans+=a[L+s-1];
}
else {
s -= (l-L);
s = (s+1)/2;
if(l+s-1<=r) ans+=a[l+s-1];
else {
s= len-(l-L)-(r-l+1)*2;

ans+=a[r+s];
}
}
}
}
printf("%.1f\n",ans);
}
}
return 0;
}


HDU【5858】——Hard problem

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)

Problem Description

cjj is fun with math problem. One day he found a Olympic Mathematics problem for primary school students. It is too difficult for cjj. Can you solve it?



Give you the side length of the square L, you need to calculate the shaded area in the picture.

The full circle is the inscribed circle of the square, and the center of two quarter circle is the vertex of square, and its radius is the length of the square.

Input

The first line contains a integer T(1<=T<=10000), means the number of the test case. Each case contains one line with integer l(1<=l<=10000).

Output

For each test case, print one line, the shade area in the picture. The answer is round to two digit.

Sample Input

1

1

Sample Output

0.29

一个图足以说明题解



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <cmath>
#include <ctime>
#define LL long long
#define Pr pair<int,int>
#define fread(ch) freopen(ch,"r",stdin)
#define fwrite(ch) freopen(ch,"w",stdout)
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double  Pi = acos(-1.0);
const int mod = 1000000007;
int main(){
int T; double l;
scanf("%d",&T);
while(T--){
scanf("%lf",&l);
double c = acos(-sqrt(2)/4);
double d = acos(sqrt(2)*5/8);
double area1 =  (l/2)*(l/2)*(Pi-c);
double area2 = l*l*d;
double area3 = sqrt(2)*l*l*sin(d)/2;
printf("%.2f\n",(area1-(area2-area3))*2);
}
return 0;
}


HDU【5862】——Counting Intersections

Time Limit: 12000/6000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)

Problem Description

Given some segments which are paralleled to the coordinate axis. You need to count the number of their intersection.

The input data guarantee that no two segments share the same endpoint, no covered segments, and no segments with length 0.

Input

The first line contains an integer T, indicates the number of test case.

The first line of each test case contains a number n(1<=n<=100000), the number of segments. Next n lines, each with for integers, x1, y1, x2, y2, means the two endpoints of a segment. The absolute value of the coordinate is no larger than 1e9.

Output

For each test case, output one line, the number of intersection.

Sample Input

2

4

1 0 1 3

2 0 2 3

0 1 3 1

0 2 3 2

4

0 0 2 0

3 0 3 2

3 3 1 3

0 3 0 2

Sample Output

4

0

Author

BUPT

这一道题初看起来想几何(好坑),但是看到看到所有的线段都是坐标轴是平行的,瞬间就看就被坑了。我们考虑将线段分为横着的和竖着的。那么对于横着的我们将其分为两个点,左加右减,遇到竖着的线的时候,进行查询。所所以这个题就是一个树状数组。。。。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <algorithm>
#include <cmath>
#include <ctime>
#define LL long long
#define Pr pair<LL,LL>
#define zero(x) (((x) >0 ?(x):(-x))<eps)
#define fread(ch) freopen(ch,"r",stdin)
#define fwrite(ch) freopen(ch,"w",stdout)

using namespace std;
const LL INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double  Pi = acos(-1.0);
const LL mod = 1000000007;
const LL Max = 110000;

struct node {
LL x,y;
LL l,r;
LL op;
bool operator < (const node &a)const {
if(x==a.x){
if(op==a.op) return y<a.y;
else return op>a.op;
}
return x<a.x;
}
} p[Max*5];
LL st[Max*8],s;
LL Tr[Max*8];
LL lowbite(LL x) { return x&(-x);}
void upd(LL x,LL d) {
while(x<=s) {
st[x]+=d;
x+=lowbite(x);
}
}
LL qu(LL x) {
LL ans = 0;
while(x>0) {
ans+=st[x];
x-=lowbite(x);
}
return ans;
}
int main() {
LL T,n;
LL x1,y1,x2,y2;
scanf("%I64d",&T);
while(T--) {
Tr[0 ] =0; LL m = 0;
scanf("%I64d",&n);
for(LL i = 0; i<n; i++) {
scanf("%I64d %I64d %I64d %I64d",&x1,&y1,&x2,&y2);
if(y1 == y2) {
p[m].x = min(x1,x2); p[m].y =y1;
p[m++].op = 1;
p[m].x = max(x1,x2); p[m].y = y2;
p[m++].op = -1;
Tr[++Tr[0]]= y1;
} else  {
p[m].x = x1; p[m].y = min(y1,y2);
p[m].l = min(y1,y2); p[m].r = max(y1,y2);
p[m++].op = 0;
Tr[++Tr[0]] = y1;
Tr[++Tr[0]] = y2;
}
}
sort(Tr+1,Tr+Tr[0]+1);
sort(p,p+m);
s = Tr[0]; Tr[0] =1;
for(LL i =2; i<=s; i++) if(Tr[Tr[0]]!= Tr[i]) Tr[++Tr[0]] = Tr[i];
s = Tr[0];LL ans =0;
memset(st,0,sizeof(st));
for(LL i = 0; i<m; i++) {
if(p[i].op == 1) {
LL l = lower_bound(Tr+1,Tr+1+Tr[0],p[i].y)-Tr;
upd(l,1);
}
else if(p[i].op == 0) {
LL L = lower_bound(Tr+1,Tr+1+Tr[0],p[i].l)-Tr;
LL R = lower_bound(Tr+1,Tr+1+Tr[0],p[i].r)-Tr;
ans+=(qu(R)-qu(L-1));
}
else {
LL l = lower_bound(Tr+1,Tr+1+Tr[0],p[i].y)-Tr;
upd(l,-1);
}
}
printf("%I64d\n",ans);
}
return 0;
}


HDU【5867】——Water problem

Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)

Problem Description

If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3+3+5+4+4=19 letters used in total.If all the numbers from 1 to n (up to one thousand) inclusive were written out in words, how many letters would be used?

Do not count spaces or hyphens. For example, 342 (three hundred and forty-two) contains 23 letters and 115 (one hundred and fifteen) contains 20 letters. The use of “and” when writing out numbers is in compliance with British usage.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases.

For each test case: There is one positive integer not greater one thousand.

Output

For each case, print the number of letters would be used.

Sample Input

3

1

2

3

Sample Output

3

6

11

Author

BUPT

模拟题

#include <bits/stdc++.h>
using namespace std;
#define fr(ch) freopen(ch,"r",stdin)
#define fw(ch) freopen(ch,"w",stdout)
char str[][111]= {
"and",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
"ten",
"eleven",
"twelve",
"thirteen",
"fourteen",
"fifteen",
"sixteen",
"seventeen",
"eighteen",
"nineteen",
"twenty",
"thirty"  ,
"forty"  ,
"fifty"  ,
"sixty"  ,
"seventy" ,
"sighty",
"ninety",
"hundred",
"thousand"
};
int ans[1100];
void Init() {
ans[0] = 0;
for(int i = 1;i<=1000;i++) {
if(i<20) ans[i] = strlen(str[i]);
else if(i>=20 && i<100) ans[i] = strlen(str[i/10+18])+(i%10 == 0?0:ans[i%10]);
else if(i>=100&& i<1000) ans[i] = ans[i/100]+strlen(str[28])+(i%100 ==0 ?0:strlen(str[0]))+ans[i%100];
else ans[i] = strlen(str[1])+strlen(str[29]);
}

for(int i = 1;i<=1000;i++) ans[i] += ans[i-1];
}
int main() {
fr("test.out");
fw("1011.out");
Init();
int T,n;
scanf("%d",&T);
while(T--) {
scanf("%d",&n); printf("%d\n",ans
);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: