HPU积分赛 2019.8.18
A题
给出n个数,问这n个数能不能分成奇数个连续的长度为奇数并且首尾均为奇数的序列
代码
- 1 #include <bits/stdc++.h>
- 2 #define ll long long
- 3 #define ull unsigned long long
- 4 #define ms(a,b) memset(a,b,sizeof(a))
- 5 const int inf=0x3f3f3f3f;
- 6 const ll INF=0x3f3f3f3f3f3f3f3f;
- 7 const int maxn=1e6+10;
- 8 const int mod=1e9+7;
- 9 const int maxm=1e3+10;
- 10 using namespace std;
- 11 int a[maxm];
- 12 int main(int argc, char const *argv[])
- 13 {
- 14 #ifndef ONLINE_JUDGE
- 15 freopen("/home/wzy/in.txt", "r", stdin);
- 16 freopen("/home/wzy/out.txt", "w", stdout);
- 17 srand((unsigned int)time(NULL));
- 18 #endif
- 19 ios::sync_with_stdio(false);
- 20 cin.tie(0);
- 21 int n;
- 22 cin>>n;
- 23 int sum=0;
- 24 for(int i=0;i<n;i++)
- 25 {
- 26 cin>>a[i];
- 27 a[i]&=1;
- 28 sum+=a[i];
- 29 }
- 30 if(!(n&1))
- 31 {
- 32 cout<<"No\n";
- 33 return 0;
- 34 }
- 35 if(!a[0]||!a[n-1])
- 36 {
- 37 cout<<"No\n";
- 38 return 0;
- 39 }
- 40 cout<<"Yes\n";
- 41 #ifndef ONLINE_JUDGE
- 42 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
- 43 #endif
- 44 return 0;
- 45 }
B题
注意第一行和第二行出现同一个数的情况,记录一下
代码
- 1 #include <bits/stdc++.h>
- 2 #define ll long long
- 3 #define ull unsigned long long
- 4 #define ms(a,b) memset(a,b,sizeof(a))
- 5 const int inf=0x3f3f3f3f;
- 6 const ll INF=0x3f3f3f3f3f3f3f3f;
- 7 const int maxn=1e6+10;
- 8 const int mod=1e9+7;
- 9 const int maxm=1e3+10;
- 10 using namespace std;
- 11 int a[maxn];
- 12 int b[maxn];
- 13 int vis[maxn];
- 14 int main(int argc, char const *argv[])
- 15 {
- 16 #ifndef ONLINE_JUDGE
- 17 freopen("/home/wzy/in.txt", "r", stdin);
- 18 freopen("/home/wzy/out.txt", "w", stdout);
- 19 srand((unsigned int)time(NULL));
- 20 #endif
- 21 ios::sync_with_stdio(false);
- 22 cin.tie(0);
- 23 int n,m;
- 24 cin>>n>>m;
- 25 for(int i=0;i<n;i++)
- 26 {
- 27 cin>>a[i];
- 28 vis[a[i]]=1;
- 29 }
- 30 for(int i=0;i<m;i++)
- 31 cin>>b[i];
- 32 sort(a,a+n);
- 33 sort(b,b+m);
- 34 int flag=0;
- 35 for(int i=0;i<m;i++)
- 36 {
- 37 if(vis[b[i]])
- 38 {
- 39 cout<<b[i]<<endl;
- 40 flag=1;
- 41 break;
- 42 }
- 43 }
- 44 if(!flag)
- 45 cout<<min(a[0],b[0])<<max(a[0],b[0])<<endl;
- 46 #ifndef ONLINE_JUDGE
- 47 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
- 48 #endif
- 49 return 0;
- 50 }
C题
输出四行1.00
D题
不会
E题
给出一个有n个整数的数组 a1, a2, ..., an 和一个整数k。你被要求把这个数组分成k 个非空的子段。 然后从每个k 个子段拿出最小值,再从这些最小值中拿出最大值。求这个最大值最大能为多少?
代码
- 1 #include <bits/stdc++.h>
- 2 #define ll long long
- 3 #define ull unsigned long long
- 4 #define ms(a,b) memset(a,b,sizeof(a))
- 5 const int inf=0x3f3f3f3f;
- 6 const ll INF=0x3f3f3f3f3f3f3f3f;
- 7 const int maxn=1e6+10;
- 8 const int mod=1e9+7;
- 9 const int maxm=1e3+10;
- 10 using namespace std;
- 11 int a[maxn];
- 12 int main(int argc, char const *argv[])
- 13 {
- 14 #ifndef ONLINE_JUDGE
- 15 freopen("/home/wzy/in.txt", "r", stdin);
- 16 freopen("/home/wzy/out.txt", "w", stdout);
- 17 srand((unsigned int)time(NULL));
- 18 #endif
- 19 ios::sync_with_stdio(false);
- 20 cin.tie(0);
- 21 int n,k;
- 22 cin>>n>>k;
- 23 int maxx;
- 24 int place=0;
- 25 int minn;
- 26 for(int i=0;i<n;i++)
- 27 {
- 28 cin>>a[i];
- 29 if(!i)
- 30 {
- 31 maxx=a[i];
- 32 place=0;
- 33 minn=a[i];
- 34 }
- 35 else if(maxx<a[i])
- 36 place=i,maxx=a[i];
- 37 minn=min(minn,a[i]);
- 38 }
- 39 if(k==1)
- 40 cout<<minn<<endl;
- 41 else if(k==2)
- 42 cout<<max(a[0],a[n-1])<<endl;
- 43 else
- 44 cout<<maxx<<endl;
- 45 #ifndef ONLINE_JUDGE
- 46 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
- 47 #endif
- 48 return 0;
- 49 }
F题
给出一个有n个数的序列a[1],a[2]……a[n],使得在i<=j<=k的条件下,令p*a[i]+q*a[j]+r*a[k]的值最大并输出这个值
代码
- 1 #include <bits/stdc++.h>
- 2 #define ll long long
- 3 #define ull unsigned long long
- 4 #define ms(a,b) memset(a,b,sizeof(a))
- 5 const int inf=0x3f3f3f3f;
- 6 const ll INF=0x3f3f3f3f3f3f3f3f;
- 7 const int maxn=1e6+10;
- 8 const int mod=1e9+7;
- 9 const int maxm=1e3+10;
- 10 using namespace std;
- 11 ll Left[maxn];
- 12 ll Right[maxn];
- 13 ll a[maxn];
- 14 int main(int argc, char const *argv[])
- 15 {
- 16 #ifndef ONLINE_JUDGE
- 17 freopen("/home/wzy/in.txt", "r", stdin);
- 18 freopen("/home/wzy/out.txt", "w", stdout);
- 19 srand((unsigned int)time(NULL));
- 20 #endif
- 21 ios::sync_with_stdio(false);
- 22 cin.tie(0);
- 23 int n;
- 24 ll p,q,r;
- 25 cin>>n>>p>>q>>r;
- 26 for(int i=0;i<n;i++)
- 27 cin>>a[i];
- 28 Left[0]=a[0]*p;
- 29 Right[n-1]=a[n-1]*r;
- 30 for(int i=1;i<n;i++)
- 31 Left[i]=max(Left[i-1],p*a[i]);
- 32 for(int i=n-2;i>=0;i--)
- 33 Right[i]=max(Right[i+1],r*a[i]);
- 34 ll ans=-INF;
- 35 for(int i=0;i<n;i++)
- 36 ans=max(ans,Left[i]+q*a[i]+Right[i]);
- 37 cout<<ans<<endl;
- 38 #ifndef ONLINE_JUDGE
- 39 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
- 40 #endif
- 41 return 0;
- 42 }
G题
排下序就好了
代码
- 1 #include <bits/stdc++.h>
- 2 #define ll long long
- 3 #define ull unsigned long long
- 4 #define ms(a,b) memset(a,b,sizeof(a))
- 5 const int inf=0x3f3f3f3f;
- 6 const ll INF=0x3f3f3f3f3f3f3f3f;
- 7 const int maxn=1e6+10;
- 8 const int mod=1e9+7;
- 9 const int maxm=1e3+10;
- 10 using namespace std;
- 11 int a[maxn];
- 12 int b[maxn];
- 13 int main(int argc, char const *argv[])
- 14 {
- 15 #ifndef ONLINE_JUDGE
- 16 freopen("/home/wzy/in.txt", "r", stdin);
- 17 freopen("/home/wzy/out.txt", "w", stdout);
- 18 srand((unsigned int)time(NULL));
- 19 #endif
- 20 ios::sync_with_stdio(false);
- 21 cin.tie(0);
- 22 int t;
- 23 int _=0;
- 24 cin>>t;
- 25 while(t--)
- 26 {
- 27 int n,m;
- 28 cin>>n>>m;
- 29 for(int i=0;i<n;i++)
- 30 cin>>a[i];
- 31 for(int i=0;i<m;i++)
- 32 cin>>b[i];
- 33 sort(a,a+n);
- 34 sort(b,b+m);
- 35 cout<<"Problem "<<1000+(++_)<<":"<<endl;
- 36 if(!n)
- 37 cout<<"Shortest judge solution: N/A bytes."<<endl;
- 38 else
- 39 cout<<"Shortest judge solution: "<<a[0]<<" bytes."<<endl;
- 40 if(!m)
- 41 cout<<"Shortest team solution: N/A bytes."<<endl;
- 42 else
- 43 cout<<"Shortest team solution: "<<b[0]<<" bytes."<<endl;
- 44 }
- 45 #ifndef ONLINE_JUDGE
- 46 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
- 47 #endif
- 48 return 0;
- 49 }
H题
现在有n个整数,在这n个数中找出k个数,保证这k个数中任意两个数差的绝对值可以被m整除。
代码
- 1 #include <bits/stdc++.h>
- 2 #define ll long long
- 3 #define ull unsigned long long
- 4 #define ms(a,b) memset(a,b,sizeof(a))
- 5 const int inf=0x3f3f3f3f;
- 6 const ll INF=0x3f3f3f3f3f3f3f3f;
- 7 const int maxn=1e6+10;
- 8 const int mod=1e9+7;
- 9 const int maxm=1e3+10;
- 10 using namespace std;
- 11 int a[maxn];
- 12 int vis[maxn];
- 13 bool cmp(int a,int b)
- 14 {
- 15 return a>b;
- 16 }
- 17 int main(int argc, char const *argv[])
- 18 {
- 19 #ifndef ONLINE_JUDGE
- 20 freopen("/home/wzy/in.txt", "r", stdin);
- 21 freopen("/home/wzy/out.txt", "w", stdout);
- 22 srand((unsigned int)time(NULL));
- 23 #endif
- 24 ios::sync_with_stdio(false);
- 25 cin.tie(0);
- 26 int n,m,k;
- 27 cin>>n>>k>>m;
- 28 int cnt=0;
- 29 int num;
- 30 int maxx=0;
- 31 for(int i=0;i<n;i++)
- 32 {
- 33 cin>>a[i];
- 34 if(!vis[a[i]%m])
- 35 cnt++;
- 36 vis[a[i]%m]++;
- 37 if(maxx<vis[a[i]%m])
- 38 maxx=vis[a[i]%m],num=a[i]%m;
- 39 }
- 40 if(maxx<k)
- 41 cout<<"No\n";
- 42 else
- 43 {
- 44 int res=0;
- 45 cout<<"Yes\n";
- 46 for(int i=0;i<n;i++)
- 47 {
- 48 if(a[i]%m==num)
- 49 {
- 50 res++;
- 51 cout<<a[i]<<" ";
- 52 }
- 53 if(res==k)
- 54 break;
- 55 }
- 56 cout<<"\n";
- 57 }
- 58 #ifndef ONLINE_JUDGE
- 59 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
- 60 #endif
- 61 return 0;
- 62 }
I题
先固定第一个位置的雷的数量,往后递推
代码
- 1 #include <bits/stdc++.h>
- 2 #define ll long long
- 3 #define ull unsigned long long
- 4 #define ms(a,b) memset(a,b,sizeof(a))
- 5 const int inf=0x3f3f3f3f;
- 6 const ll INF=0x3f3f3f3f3f3f3f3f;
- 7 const int maxn=1e4+10;
- 8 const ll mod=1e8+7;
- 9 const int maxm=1e3+10;
- 10 using namespace std;
- 11 ll a[maxn];
- 12 // 每一列可以放多少个
- 13 ll dp[maxn];
- 14 int main(int argc, char const *argv[])
- 15 {
- 16 #ifndef ONLINE_JUDGE
- 17 freopen("/home/wzy/in.txt", "r", stdin);
- 18 freopen("/home/wzy/out.txt", "w", stdout);
- 19 srand((unsigned int)time(NULL));
- 20 #endif
- 21 ios::sync_with_stdio(false);
- 22 cin.tie(0);
- 23 int t;
- 24 cin>>t;
- 25 while(t--)
- 26 {
- 27 ms(dp,0);
- 28 ms(a,0);
- 29 string s;
- 30 cin>>s;
- 31 int l=s.length();
- 32 for(int i=0;i<l;i++)
- 33 a[i]=1LL*(s[i]-'0');
- 34 ll ans=0;
- 35 // 固定第一个位置的个数
- 36 for(int i=0;i<3;i++)
- 37 {
- 38 if(i>a[0])
- 39 break;
- 40 dp[0]=i;
- 41 ll pos=1;
- 42 // 第一个固定之后,枚举后面的每个位置
- 43 int cnt=0;
- 44 for(int j=1;j<l;j++)
- 45 {
- 46 int res;
- 47 // 第一列前面没有别的了,所以不需要考虑第一列左边的情况
- 48 if(j==1)
- 49 res=a[j-1]-dp[j-1];
- 50 // 第j列需要放的雷的个数
- 51 else
- 52 res=a[j-1]-dp[j-1]-dp[j-2];
- 53 // 符合要求
- 54 if(res<=2&&res>=0)
- 55 dp[j]=res,cnt++;
- 56 }
- 57 // 如果没有枚举到最后一个位置
- 58 if(cnt!=l-1)
- 59 continue;
- 60 // 如果最后两列放雷数不等于实际的个数,排除掉
- 61 if(dp[l-1]+dp[l-2]!=a[l-1])
- 62 continue;
- 63 // 计算当第一列为雷数为i的总情况
- 64 for(int j=0;j<l;j++)
- 65 if(dp[j]==1)
- 66 pos<<=1,pos%=mod;
- 67 ans+=pos;ans%=mod;
- 68 }
- 69 cout<<ans%mod<<endl;
- 70 }
- 71 #ifndef ONLINE_JUDGE
- 72 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
- 73 #endif
- 74 return 0;
- 75 }
J题
注意考虑两种情况
代码
- 1 #include <bits/stdc++.h>
- 2 #define ll long long
- 3 #define ull unsigned long long
- 4 #define ms(a,b) memset(a,b,sizeof(a))
- 5 const int inf=0x3f3f3f3f;
- 6 const ll INF=0x3f3f3f3f3f3f3f3f;
- 7 const int maxn=1e6+10;
- 8 const int mod=1e9+7;
- 9 const int maxm=1e3+10;
- 10 using namespace std;
- 11 struct wzy
- 12 {
- 13 ll bigness;
- 14 ll money;
- 15 double price;
- 16 }p[maxn];
- 17 bool cmp(wzy u,wzy v)
- 18 {
- 19 return u.price<v.price;
- 20 }
- 21 int main(int argc, char const *argv[])
- 22 {
- 23 #ifndef ONLINE_JUDGE
- 24 freopen("/home/wzy/in.txt", "r", stdin);
- 25 freopen("/home/wzy/out.txt", "w", stdout);
- 26 srand((unsigned int)time(NULL));
- 27 #endif
- 28 ios::sync_with_stdio(false);
- 29 cin.tie(0);
- 30 int n;
- 31 ll l;
- 32 cin>>n>>l;
- 33 for(int i=1;i<=n;i++)
- 34 {
- 35 cin>>p[i].money;
- 36 p[i].bigness=(1LL<<(i-1));
- 37 p[i].price=1.0*p[i].money/p[i].bigness;
- 38 }
- 39 sort(p+1,p+1+n,cmp);
- 40 ll L=l;
- 41 ll ans=INF;
- 42 ll res1=0,res2=0;
- 43 while(L>0)
- 44 {
- 45 for(int i=1;i<=n;i++)
- 46 {
- 47 // 全买这个饮料
- 48 res1=res2+ceil(1.0*L/p[i].bigness)*p[i].money;
- 49 ans=min(ans,res1);
- 50 // 多余的部分买别的
- 51 res2+=L/p[i].bigness*p[i].money;
- 52 L-=(p[i].bigness*(L/p[i].bigness));
- 53 }
- 54 }
- 55 ans=min(ans,res2);
- 56 cout<<ans<<endl;
- 57 #ifndef ONLINE_JUDGE
- 58 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
- 59 #endif
- 60 return 0;
- 61 }
K题
矩阵快速幂
f[i]=f[i-1]+2*f[i-2]+n^3
L题
暴力枚举就行了
代码
- 1 #include <bits/stdc++.h>
- 2 #define ll long long
- 3 #define ull unsigned long long
- 4 #define ms(a,b) memset(a,b,sizeof(a))
- 5 const int inf=0x3f3f3f3f;
- 6 const ll INF=0x3f3f3f3f3f3f3f3f;
- 7 const int maxn=1e6+10;
- 8 const int mod=1e9+7;
- 9 const int maxm=1e3+10;
- 10 using namespace std;
- 11 struct wzy
- 12 {
- 13 ll s,d;
- 14 }p[maxn];
- 15 int main(int argc, char const *argv[])
- 16 {
- 17 #ifndef ONLINE_JUDGE
- 18 freopen("/home/wzy/in.txt", "r", stdin);
- 19 freopen("/home/wzy/out.txt", "w", stdout);
- 20 srand((unsigned int)time(NULL));
- 21 #endif
- 22 ios::sync_with_stdio(false);
- 23 cin.tie(0);
- 24 int n;
- 25 cin>>n;
- 26 for(int i=0;i<n;i++)
- 27 cin>>p[i].d>>p[i].s;
- 28 ll ans=p[0].d;
- 29 for(int i=1;i<n;i++)
- 30 {
- 31 ans+=1;
- 32 ll res=p[i].d;
- 33 if(res>=ans)
- 34 ans=res;
- 35 else
- 36 {
- 37 ll pos=ceil(1.0*(ans-res)/p[i].s);
- 38 ans=res+(p[i].s*pos);
- 39 }
- 40 }
- 41 cout<<ans<<endl;
- 42 #ifndef ONLINE_JUDGE
- 43 cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" s."<<endl;
- 44 #endif
- 45 return 0;
- 46 }
HPU积分赛 2019.8.18的更多相关文章
- 2019.3.18考试&2019.3.19考试&2019.3.21考试
2019.3.18 C O D E T1 树上直接贪心,环上for一遍贪心 哇说的简单,码了将近一下午终于码出来了 感觉自己码力/写题策略太糟糕了,先是搞了一个细节太多的写法最后不得不弃疗了,然后第二 ...
- MySQL存储过程-2019/7/18
MySQL 5.0 版本开始支持存储过程. 存储过程(Stored Procedure)是一种在数据库中存储复杂程序,以便外部程序调用的一种数据库对象. 存储过程是为了完成特定功能的SQL语句集,经编 ...
- 6362. 【NOIP2019模拟2019.9.18】数星星
题目描述 题解 一种好想/好写/跑得比**记者还快的做法: 对所有询问排序,按照R递增的顺序来处理 维护每个点最后一次被覆盖的时间,显然当前右端点为R时的答案为所有时间≥L的点的权值之和 LCT随便覆 ...
- 2019/4/18 wen 线程
- Python脱产8期 Day06 2019/4/18
一 深浅拷贝 例:ls = [1, 'abc', [10]] 1.值拷贝:s1 = ls # ls1直接将ls中存放的地址拿过来,>ls内部的值发生任何变化,ls1都会随之变化. 2.浅拷 ...
- 最小生成树模板题 hpu 积分赛 Vegetable and Road again
问题 H: Vegetable and Road again 时间限制: 1 Sec 内存限制: 128 MB 提交: 19 解决: 8 题目描述 修路的方案终于确定了.市政府要求任意两个公园之间都必 ...
- [hgoi#2019/2/18]比较水
T1--调换纸牌(card) Alex有 n张纸牌,每张纸牌上都有一个值ai,Alex把这些纸牌排成一排,希望将纸牌按值从小到大的顺序排好.现在他把这个任务交给你,你只能进行一种操作:选中一张牌,然后 ...
- 2019.03.18 连接my sql
11.登陆功能(链接MySQL) python manage.py starapp movie 新建一个应用模块之后要记得到setting添加这个应用模块 在python2中你还有去导入一个MySQL ...
- hpu积分赛(回溯法)
问题 : 不开心的小明① 时间限制: 1 Sec 内存限制: 128 MB 提交: 2 解决: 1 题目描述 一天, 小明很不开心,先是向女神表白被拒, 数学又考了0分, 回家的路上又丢了钥匙, 他非 ...
随机推荐
- 一次线上GC故障解决过程记录
排查了三四个小时,终于解决了这个GC问题,记录解决过程于此,希望对大家有所帮助.本文假定读者已具备基本的GC常识和JVM调优知识,关于JVM调优工具使用可以查看我在同一分类下的另一篇文章: http: ...
- API 管理在云原生场景下的机遇与挑战
作者 | 张添翼 来源 | 尔达Erda公众号 云原生下的机遇和挑战 标准和生态的意义 自从 Kubernetes v1.0 于 2015 年 7 月 21 日发布,CNCF 组织随后建立以来,其 ...
- Flink(九)【Flink的重启策略】
目录 1.Flink的重启策略 2.重启策略 2.1未开启checkpoint 2.2开启checkpoint 1)不设置重启策略 2)不重启 3)固定延迟重启(默认) 4)失败率重启 3.重启效果演 ...
- Cx_Oracle 安装
1. 下载安装 2.把oci.ddl oraociei11.dll 放到C:\Python33\Lib\site-packages路径下
- Linux学习 - 使用qq邮箱发送邮件
1 打开qq邮箱,设置->账户->POP3/SMTP,开启服务 2 配置/etc/mail.rc文件 set from=73***32@qq.com #设置发送方邮件地址 set smtp ...
- Spring(4):Mybatis和Spring整合
第一步:创建数据库 MySQL代码 1 CREATE DATABASE `mybatis` ; 2 3 USE `mybatis`; 4 5 CREATE TABLE `user` ( 6 `id` ...
- 运维笔记之yum,rpm,挂载,磁盘管理和raid详解
yum 与 rpm centos6,7 主要有rpm和yum这两种包管理软件,两种包的管理各有用处,其中最主要区别是: yum使用简单但需要联网,yum会去网上的yum包源去获取所需要的软件包.而r ...
- 如何用shell脚本分析网站日志统计PV、404、500等数据
以下shell脚本能统计出网站的总访问量,以及404,500出现的次数.统计出来后,可以结合监控宝来进行记录,进而可以看出网站访问量是否异常,是否存在攻击.还可以根据查看500出现的次数,进而判断网站 ...
- linux 操作只读变量
由于该操作需要用到 gdb,所以需要先 安装好 gdb 1. 查询是否有gdb: 2. 如果没有,需要先执行 yum install gdb 命令进行安装 3. 定义 只读变量 abc 并打印值: a ...
- 修改页面.JSP
<%@ page contentType="text/html;charset=UTF-8" language="java" %><%@tag ...