首页 > 其他分享 >“现代汽车中国前瞻软件赛杯” 牛客周赛 Round 43 D、E

“现代汽车中国前瞻软件赛杯” 牛客周赛 Round 43 D、E

时间:2024-05-20 21:07:41浏览次数:12  
标签:周赛 const 10 double LL 43 long 牛客 include

 

那时候吃了饭后,剩下25分钟,我就把A-D都过了一遍,E不够时间。

 

D

对于x~y这个长度为k的序列:对于1~k每个数,它出现的数目。

从x~y,到x+1~y:如果一个数出现的数目从0 -> 1,出现元素数目+1;如果一个数出现的数目从1 -> 0,出现元素数目-1。

记录所有出现元素数目=k的序列。

太多人对了。

 

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <cstdbool>
 6 #include <string>
 7 #include <algorithm>
 8 #include <iostream>
 9 #include <sstream>
10 #include <ctime>
11 #include <stack>
12 #include <vector>
13 #include <queue>
14 #include <set>
15 #include <map>
16 #include <array>
17 #include <bitset>
18 using namespace std;
19 #define LL long long
20 #define ULL unsigned long long
21 
22 const LL mod_1=1e9+7;
23 const LL mod_2=998244353;
24 
25 const double eps_1=1e-5;
26 const double eps_2=1e-10;
27 
28 const int maxn=1e5+10;
29 
30 LL a[maxn], hap[maxn];
31 
32 int main()
33 {
34     LL n,k,ci=0,r=0,i;
35 
36     memset(hap,0,sizeof(hap));
37 
38     cin>>n>>k;
39     for (i=1;i<=n;i++)
40         cin>>a[i];
41 
42     for (i=1;i<=n;i++)
43     {
44         if (hap[ a[i] ]==0)
45             ci++;
46         hap[ a[i] ]++;
47 
48        if (i>=k)
49         {
50             if (ci==k)
51                 r++;
52         }
53 
54         if (i>=k)
55         {
56             if (hap[ a[i-k+1] ]==1)
57                 ci--;
58             hap[ a[i-k+1] ]--;
59         }
60 
61     }
62 
63     cout<<r;
64 
65     return 0;
66 }

 

 

 

E

遍历所有边,因为点数目<=1e3,那么边数目>=1e6。

对于每条边,记录斜率y、x(斜率为y/x),长度len(长度为sqrt(len)),然后用map记录满足这个条件的b的最大值/最小值(y=k*x+b)。如果有两条边,斜率y、x、长度len都一样,那么它们可以作为平行四条行的两条边(剩下两条边也自然满足条件)。

斜率用y, x表示,长度用len表示,使得它们都是整数,这样一来,避免出现浮点数精度的错误。

 

这样写很方便:

1 typedef pair<pair<LL,LL>, LL> typ;
2 
3 map<typ, LL> m_min, m_max;

 

 

最后的结果是一个整数,如果用double、long double,只能过53%左右的样例。

 

为什么结果一定是整数,把它切成这样,就能理解了,点的x,y坐标都是整数。

 

 

  1 #include <cstdio>
  2 #include <cstdlib>
  3 #include <cstring>
  4 #include <cmath>
  5 #include <cstdbool>
  6 #include <string>
  7 #include <algorithm>
  8 #include <iostream>
  9 #include <sstream>
 10 #include <ctime>
 11 #include <stack>
 12 #include <vector>
 13 #include <queue>
 14 #include <set>
 15 #include <map>
 16 #include <array>
 17 #include <bitset>
 18 using namespace std;
 19 #define LL long long
 20 #define ULL unsigned long long
 21 
 22 const LL mod_1=1e9+7;
 23 const LL mod_2=998244353;
 24 
 25 const double eps_1=1e-5;
 26 const double eps_2=1e-10;
 27 
 28 const int maxn=1e3+10;
 29 const int maxp=1e6+10;
 30 
 31 LL x[maxn], y[maxn];
 32 
 33 typedef pair<pair<LL,LL>, LL> typ;
 34 
 35 map<typ, LL> m_min, m_max;
 36 
 37 
 38 int main()
 39 {
 40     LL n,i,j,xx,yy,len,xishu,v1,v2;
 41     typ ty;
 42     //long double r=0,b1,b2;
 43     ///变为long double,反而有一个错了
 44 
 45     ///输出全部都是整数
 46 
 47     ///也就是說,long double只是定義為至少跟double一樣精度(即是可以一樣)
 48 
 49 
 50     ///double r=0,b1,b2;
 51 
 52     LL r=0;
 53 
 54     cin>>n;
 55     for (i=1;i<=n;i++)
 56         cin>>x[i]>>y[i];
 57     for (i=1;i<=n;i++)
 58         for (j=i+1;j<=n;j++)
 59         {
 60             yy = y[i]-y[j];
 61             xx = x[i]-x[j];
 62 
 63             if (xx<0)
 64                 yy=-yy, xx=-xx;
 65 
 66             /*
 67             if (x[i]==x[j])
 68                 xishu = y[i] - 1.0*(y[i]-y[j])/(x[i]-x[j])*x[i];
 69             else
 70                 xishu = 1e18;
 71             */
 72 
 73             xishu = y[i]*xx - yy*x[i]; /// xishu/xx
 74 
 75             len = yy*yy + xx*xx;    /// sqrt(len)
 76 
 77             ty = make_pair( make_pair(yy,xx), len);
 78 
 79             if (m_max.find(ty)==m_max.end())
 80                 m_max[ty]=xishu;
 81             else
 82                 m_max[ty]=max(m_max[ty], xishu);
 83 
 84             if (m_min.find(ty)==m_min.end())
 85                 m_min[ty]=xishu;
 86             else
 87                 m_min[ty]=min(m_min[ty], xishu);
 88         }
 89 
 90 
 91 
 92     for (auto d : m_max)
 93     {
 94         v1 = d.second;
 95         ty = d.first;
 96         v2 = m_min[ty];
 97 
 98         len = ty.second;
 99         yy = ty.first.first;
100         xx = ty.first.second;
101 
102         /*
103         if (xx==0)
104             continue;
105         */
106 
107         //b1 = abs( 1.0* (v1-v2) / xx );
108         //b2 = sqrt(1.0*len);
109 
110         //r = max(r, b2 * b1 * xx / b2);
111 
112         //r = max(r, 1.0*(v1-v2));
113 
114         r = max(r, v1-v2);
115 
116     }
117 
118     if (r==0)
119         cout<<"-1";
120     else
121         cout<<r<<".0";
122 
123     /*
124     if (fabs(r)<1e-5)
125     {
126         cout<<"-1";
127         return 0;
128     }
129 
130     printf("%.1f",r);
131     */
132 
133     //printf("%.1Lf",r);
134 
135     return 0;
136 }
137 /*
138 4
139 0 0
140 0 10
141 10 0
142 10 10
143 
144 
145 
146 
147 4
148 0 0
149 10 0
150 3 5
151 13 5
152 
153 
154 
155 6
156 0 0
157 0 10
158 10 0
159 10 10
160 3 5
161 13 5
162 
163 
164 4
165 0 0
166 1 0
167 2 0
168 3 0
169 
170 4
171 0 10
172 1 10
173 2 10
174 3 10
175 
176 4
177 10 0
178 10 1
179 10 2
180 10 3
181 */

 

标签:周赛,const,10,double,LL,43,long,牛客,include
From: https://www.cnblogs.com/cmyg/p/18202790

相关文章

  • 洛谷 P4383 [八省联考 2018] 林克卡特树
    原题等价于在树上选出\(k+1\)条不相交链,最大化边权和。树形DP。设\(f_{u,k,0/1/2}\)表示在\(u\)的子树中选了\(k\)条链,\(u\)的度数为\(0,1,2\)的最大边权和。注意到状态里缺了链退化为单个点的情况,可以把它放到\(f_{u,k,2}\)中(相当于自环)。转移时分讨一......
  • “现代汽车中国前瞻软件赛杯” 牛客周赛 Round 43
    A小红平分糖果Code:#include<bits/stdc++.h>usingnamespacestd;#definedebug(x)cerr<<#x<<":"<<x<<'\n';intmain(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);intn;ci......
  • 洛谷题单指南-动态规划3-P4342 [IOI1998] Polygon
    原题链接:https://www.luogu.com.cn/problem/P4342题意解读:环中节点表示数字,边表示运算符,可以任意断一条边,其余节点两两按边的符号计算,求结果的最大值,以及最大值是断开那些边可以得到。解题思路:题意中有几个个关键信息:环形,节点数为n,边数为n任意断一条边,即可以从任意节点开始,......
  • CF1438C Engineer Artem
    题目链接:https://www.luogu.com.cn/problem/CF1438C一道很有意思的思维题。题目说每个元素只能进行加一操作。加一操作最重要的性质就是改变元素的奇偶性。那么我们可以考虑棋盘的性质即:101010101010101这样。其中1代表奇数,0代表偶数那么我们学习棋盘的这种......
  • Codeforces Round 943 (Div. 3)
    CodeforcesRound943(Div.3)1968D-枚举思路:每个人走的位置最多会形成长度为n的环,所以直接枚举走到某个位置之后后面就不走了的所有情况的最大值,相互比较即可1968E-构造题意:设\(F(A_i,A_j)=|x_i-x_y|+|y_i-y_j|\),在\(N*N\)的矩阵中选n个点使所有不同的\(F(A_i,A_j)=|x_i-......
  • 力扣第130场双周赛
    判断矩阵是否满足条件给定二维矩阵,判断所有格子是否满足如下条件:如果它下面的格子存在,那么它需要等于它下面的格子如果它右边的格子存在,那么它需要不等于它右边的格子遍历二维矩阵,简单模拟即可。classSolution{public:boolsatisfiesConditions(vector<vector<in......
  • 43.Android 网络编程的简单学习整理
    关于Android网络通信编程Android对HTTP通信提供了支持通过标准的JAVA类HttpURLConnection便可以实现基于URL的请求及响应功能关于URL和URI还分不清吗然后还有就是GET和POST方式提交数据注意使用GET或者POST方式提交参数时为了防止中文乱码要对参数进行编码使用Web......
  • luogu P4342[IOI1998]Polygon
    阅读前需深剖析分系列是记录我个人的做题思路,实现过程的全面分析,存在内容可靠、思路健全、分析到位、试错纠错等优于一般题解的特征,其中,Quest部分表示探索问题,我会在此提出做题时的想法、问题,并在内容中得到解决,因此建议从上到下按序浏览,以防出现思路断层,内容不衔接的情况,感谢理......
  • 牛客小白月赛93(python)
    A生不逢71defcheck(num):2return'7'instr(num)ornum%7==034defsolve():5n,a,k=LII()6d=a+17foriinrange(k):8ifcheck(d):9print('p',end='')10els......
  • bzoj4399: 魔法少女LJJ
    先上头图:诈骗题认真读题c<=7 只需要考虑前七个操作一.动态开点即可二.线段树合并三.四.对于这两个操作,可以先统计出有多少个数小于/大于x,然后删除所有小于/大于x的数,并在x位置加上这些数五.下放标记查询即可六.每个数最大为1e9,直接乘肯定会炸,所以可以用double存它们的......