2017 多校赛 第二场

1003.Maximum Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0


Problem Description
Steph is extremely obsessed with “sequence problems” that are usually seen on magazines: Given the sequence 11, 23, 30, 35, what is the next number? Steph always finds them too easy for such a genius like himself until one day Klay comes up with a problem and ask him about it.

Given two integer sequences {ai} and {bi} with the same length n, you are to find the next n numbers of {ai}:  an+1a2n. Just like always, there are some restrictions on an+1a2n: for each number ai, you must choose a number bk from {bi}, and it must satisfy ai≤max{aj-j│bk≤j<i}, and any bk can’t be chosen more than once. Apparently, there are a great many possibilities, so you are required to find max{2nn+1ai} modulo 109+7 .

Now Steph finds it too hard to solve the problem, please help him.
 

 

Input
The input contains no more than 20 test cases.
For each test case, the first line consists of one integer n. The next line consists of n integers representing {ai}. And the third line consists of n integers representing {bi}.
1≤n≤250000, n≤a_i≤1500000, 1≤b_i≤n.
 
Output
For each test case, print the answer on one line: max{ 2nn+1ai} modulo 109+7。
 
Sample Input
4 8 11 8 5 3 1 4 2
 
Sample Output
27
 
思路:贪心,用一个数组记下从i到n的a[i]-i的最大值pre[i],可以得到pre[i]=max(pre[i+1],a[i]-i),然后容易得到b[k]从小往大取时,后n项之和最大,所以a[n+1]=pre[b[1]](后n项会呈单调不递增趋势,a[n+1]-n-1即为之后取最大值的比较对象)。
代码:
 1 #include "cstdio"
 2 #include "stdlib.h"
 3 #include "iostream"
 4 #include "algorithm"
 5 #include "string"
 6 #include "cstring"
 7 #include "queue"
 8 #include "cmath"
 9 #include "vector"
10 #include "map"
11 #include "set"
12 #define db double
13 #define ll long long
14 #define inf 0x3f3f3f
15 using namespace std;
16 const int N=3e5+5;
17 const int mod=1e9+7;
18 #define rep(i,x,y) for(int i=x;i<=y;i++)
19 //char s[N],t[N];
20 db  pi=3.14;
21 //int s[N],w[N];
22 int a[N],b[N];
23 int pre[N];
24 int main()
25 {
26     int n;
27     while(scanf("%d",&n)==1){
28         for(int i=1;i<=n;i++){
29             scanf("%d",a+i);
30             a[i]-=i;
31         }
32         memset(pre,0, sizeof(pre));
33         for(int i=n;i>=1;i--) pre[i]=max(a[i],pre[i+1]);
34         for(int i=1;i<=n;i++) scanf("%d",&b[i]);
35         sort(b+1,b+n+1);
36         int ma=0;
37         ll ans=pre[b[1]];
38         for(int i=2;i<=n;i++){
39             ma=max(pre[b[1]]-n-1,pre[b[i]]);
40             ans=(ma+ans)%mod;
41 //            printf("%d\n",ma);
42         }
43         printf("%lld\n",ans);
44     }
45 
46 }

 

10011.Regular polygon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 752    Accepted Submission(s): 273


Problem Description
On a two-dimensional plane, give you n integer points. Your task is to figure out how many different regular polygon these points can make.
 

 

Input
The input file consists of several test cases. Each case the first line is a numbers N (N <= 500). The next N lines ,each line contain two number Xi and Yi(-100 <= xi,yi <= 100), means the points’ position.(the data assures no two points share the same position.)
 

 

Output
For each case, output a number means how many different regular polygon these points can make.
 

 

Sample Input
4
0 0
0 1
1 0
1 1
6
0 0
0 1
1 0
1 1
2 0
2 1
 
Sample Output
1 2

思路:整点正多边形只能是正方形,将点按x从小到大,y从大到小,枚举对角线 (x1,y1) (x2,y2) xx=x1-x2,yy=y1-y2;则x3=x1+yy,y3=y1-xx;x4=x1-yy,y4=y1+xx;判断是否存在即可。

学长的代码:

 1 #include "cstdio"
 2 #include "stdlib.h"
 3 #include "iostream"
 4 #include "algorithm"
 5 #include "string"
 6 #include "cstring"
 7 #include "queue"
 8 #include "cmath"
 9 #include "vector"
10 #include "map"
11 #include "set"
12 #define db double
13 #define ll long long
14 #define inf 0x3f3f3f
15 #define rep(i,x,y) for(int i=x;i<=y;i++)
16 using namespace std;
17 const int N=3e5+5;
18 const int mod=1e9+7;
19 const double eps=1e-9;
20 //char s[N],t[N];
21 db  pi=3.14;
22 int n;
23 struct node
24 {
25     double x,y;
26 }p[N];
27 bool cmp(node a,node b)
28 {
29     return (a.x<b.x||(a.x==b.x&&a.y<b.y));
30 }
31 bool Check(double x,double y)
32 {
33     int l=1,r=n;
34     while(l<=r)
35     {
36         int mid=l+r>>1;
37         if(fabs(p[mid].x-x)<eps&&fabs(p[mid].y-y)<eps) return true;
38         else if(p[mid].x-x>eps||(fabs(p[mid].x-x)<eps&&p[mid].y-y>eps)) r=mid-1;
39         else l=mid+1;
40     }
41     return false;
42 }
43 int main()
44 {
45     while(~scanf("%d",&n))
46     {
47         ll ans=0;
48         rep(i,1,n)
49         {
50             scanf("%lf%lf",&p[i].x,&p[i].y);
51         }
52         sort(p+1,p+1+n,cmp);
53         rep(i,1,n)
54         {
55             rep(j,i+1,n)
56             {
57                 double x=(p[i].x+p[j].x)/2;
58                 double y=(p[i].y+p[j].y)/2;
59                 double xx=p[i].x-x;
60                 double yy=p[i].y-y;
61                 if(Check(x+yy,y-xx)&&Check(x-yy,y+xx)) ans++;
62             }
63         }
64         printf("%lld\n",ans/2);
65     }
66 }

 

 

转载于:https://www.cnblogs.com/mj-liylho/p/7247765.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值