hdu 6205 card card card 尺取+超神读入挂

题没啥好说的

我就是想把读入挂记录一下

 1 #include<bits/stdc++.h>
 2 #define cl(a,b) memset(a,b,sizeof(a))
 3 #define debug(a) cerr<<#a<<"=="<<a<<endl
 4 using namespace std;
 5 typedef long long ll;
 6 typedef pair<int,int> pii;
 7
 8 const int maxn=1e6+10;
 9
10 int n;
11 int a[maxn*2];
12 int b[maxn*2];
13
14 namespace fastIO {
15     #define BUF_SIZE 100000
16     //fread -> read
17     bool IOerror = 0;
18     inline char nc() {
19         static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
20         if(p1 == pend) {
21             p1 = buf;
22             pend = buf + fread(buf, 1, BUF_SIZE, stdin);
23             if(pend == p1) {
24                 IOerror = 1;
25                 return -1;
26             }
27         }
28         return *p1++;
29     }
30     inline bool blank(char ch) {
31         return ch == ‘ ‘ || ch == ‘\n‘ || ch == ‘\r‘ || ch == ‘\t‘;
32     }
33     inline void read(int &x) {
34         char ch;
35         while(blank(ch = nc()));
36         if(IOerror)
37             return;
38         for(x = ch - ‘0‘; (ch = nc()) >= ‘0‘ && ch <= ‘9‘; x = x * 10 + ch - ‘0‘);
39     }
40     #undef BUF_SIZE
41 };
42 using namespace fastIO;
43
44 int chiqu(int n)
45 {
46     int sum=0,mx=0,ans=0;
47     for(int l=1,r=1; l<=n&&r<=n;)
48     {
49         if(sum>0) sum+=(a[r]-b[r++]);
50         if(r-l+1>=mx)
51         {
52             mx=r-l+1;
53             ans=l-1;
54         }
55         if(sum<=0) sum-=(a[l]-b[l++]);
56     }
57     return ans;
58 }
59
60 int main()
61 {
62     while(read(n),!fastIO::IOerror)
63     {
64         for(int i=1; i<=n; i++) read(a[i]);
65         for(int i=1; i<=n; i++) read(b[i]);
66         for(int i=1; i<=n; i++) a[i+n]=a[i],b[i+n]=b[i];
67         int ans=chiqu(2*n);
68 //        debug(ans);
69         printf("%d\n",ans);
70     }
71     return 0;
72 }/*
73
74 5
75 4 6 2 8 4
76 1 5 7 9 2
77
78 */
时间: 2024-08-02 15:14:51

hdu 6205 card card card 尺取+超神读入挂的相关文章

hdu 6231 -- K-th Number(二分+尺取)

题目链接 Problem Description Alice are given an array A[1..N] with N numbers. Now Alice want to build an array B by a parameter K as following rules: Initially, the array B is empty. Consider each interval in array A. If the length of this interval is le

HDU 6396 Swordsman --------2018 Multi-University Training Contest 7 (模拟+读入挂)

原题地址: 打怪升级 一开始有N个怪物:主角有K个能力:只有K个能力都击败怪物才能斩杀怪物并获得K个能力的增值:问最多能杀几个怪物: 做法: 用优先队列把怪物能力装进去:能力小放前面: 最重要的是数据量要用读入挂才能过:(读入挂太神奇了!!) Swordsman Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2049    Acce

【尺取】HDU String

http://acm.hdu.edu.cn/showproblem.php?pid=5672 [题意] 给定一个小写英语字母组成的字符串,求这个字符串一共包含多少个至少有m个不同字母的连续子序列 [思路] 尺取. 我们发现,如果i~j是恰好含有k个字母的区间,那么对于k(j<k<=n),i~k是含有至少k个不同字母的子串,那么对于每一个左边界,我们都可以找到一个最小的右边界,使得这个区间恰好含有k个字母,然后统计以这个左边界符合条件的子串个数,找到右边界,用尺取法即可. [Accepted]

【尺取】HDU Problem Killer

acm.hdu.edu.cn/showproblem.php?pid=5328 [题意] 给定一个长度为n的正整数序列,选出一个连续子序列,这个子序列是等差数列或者等比数列,问这样的连续子序列最长是多少? [思路] 尺取,用来解决这样的问题:需要在给的一组数据中找到不大于某一个上限的"最优连续子序列" 分别用双指针找最长的等差数列和等比数列,找最大值就可以了. 注意a 或者 a b既是等差数列,又是等比数列. [Accepted] 1 #include <iostream>

hdu 6119 小小粉丝度度熊 (区间处理+尺取)

http://acm.hdu.edu.cn/showproblem.php?pid=6119 解题思路:给出的出发时间和结束时间对有重合的部分进行处理,然后用尺取法找出最后的结果.比赛的时候的确想到了用尺取的想法完成题目,但是代码能力不行没有想出来. AC代码: 1 #include <iostream> 2 #include <bits/stdc++.h> 3 using namespace std; 4 const int maxn=100005; 5 struct node

hdu 4123 Bob’s Race 树的直径+rmq+尺取

Bob’s Race Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Bob wants to hold a race to encourage people to do sports. He has got trouble in choosing the route. There are N houses and N - 1 roads

HDU 5806 NanoApe Loves Sequence Ⅱ(尺取+思维)——BestCoder Round #86 1003

传送门 NanoApe Loves Sequence Ⅱ Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)Total Submission(s): 514    Accepted Submission(s): 248 Problem Description NanoApe, the Retired Dog, has returned back to prepare for f

HDU 5178 pairs【二分】||【尺取】

<题目链接> 题目大意: 给定一个整数序列,求出绝对值小于等于k的有序对个数. 解题分析: $O(nlong(n))$的二分很好写,这里就不解释了.本题尺取$O(n)$也能做,并且效率很不错. 尺取: #include <bits/stdc++.h> using namespace std; int arr[int(1e5+5)]; int main(){ int T,n,k;scanf("%d",&T); while(T--){ scanf("

HDU 6205(尺取法)2017 ACM/ICPC Asia Regional Shenyang Online

题目链接 emmmm...思路是群里群巨聊天讲这题是用尺取法.....emmm然后就没难度了,不过时间上3000多,有点.....盗了个低配本的读入挂发现就降到2800左右, 翻了下,发现神犇Claris280MS秒过.......%%% #include <stdio.h> #include <stdlib.h> #include <cmath> #include <string.h> #include <iostream> #include