2017计蒜之道程序设计大赛初赛第五场
来源:互联网 发布:万能数据恢复大师 编辑:程序博客网 时间:2024/04/30 07:32
https://www.jisuanke.com/contest/730
第一题:只要从大到小排序再取即可。
#include<bits/stdc++.h>using namespace std;int a[105];int cmp(int a,int b){ return a>b;}int main(){ int n,m; scanf("%d%d",&n,&m); for(int i=0;i<m;i++) { scanf("%d",&a[i]); a[i]--; } sort(a,a+m,cmp); int i; int ans=0; n--; for(i=0;i<m;i++) { //printf("%d\n",n); if(n<=0) { break; } n=n-a[i]; ans++; } if(n>0) { printf("Impossible"); return 0; } printf("%d\n",ans); return 0;}// 1 6 1 2
#include<bits/stdc++.h>using namespace std;int a[105];int b[105];int B[105];int A[105];int main(){ int n,m; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&a[i]); } scanf("%d",&m); while(m--) { int N; scanf("%d",&N); memset(B,0,sizeof(B)); memset(A,0,sizeof(A)); for(int i=0; i<N; i++) { scanf("%d",&b[i]); B[b[i]]++; } if(N>n) { printf("0\n"); continue; } for(int i=0; i<N; i++) { A[a[i]]++; } int ans=0; int f=0; for(int j=0; j<=n; j++) { if(A[j]==B[j]) { } else { f=1; break; } } if(f==0) { ans++; } for(int i=0; i<n; i++) { A[a[i]]--; A[a[i+N]]++; int f=0; for(int j=0; j<=n; j++) { if(A[j]==B[j]) { } else { f=1; break; } } if(f==0) { ans++; } } printf("%d\n",ans); } return 0;}
第三题:因为数据比较大,所以需要做一点优化。no表示第一次匹配时不相同的对数,考虑到往后匹配,每次变化的只有i和i+N 这2对,所以只要对它们进行判断即可,如果此时no等于0,那么ans++
#include<bits/stdc++.h>using namespace std;int a[50005];int b[50005];int B[50005];int A[50005];//map<int ,int > ma;int main(){ int n,m; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&a[i]); } scanf("%d",&m); while(m--)//500 { int N; scanf("%d",&N); memset(B,0,sizeof(B)); memset(A,0,sizeof(A)); //ma.clear(); for(int i=0; i<N; i++) { scanf("%d",&b[i]); B[b[i]]++; } if(N>n) { printf("0\n"); continue; } for(int i=0; i<N; i++) { A[a[i]]++; } int ans=0; int f=0; int no=0; for(int j=0; j<=n; j++) { if(A[j]==B[j]) { } else { f=1; no++; // ma[j]=1; } } if(f==0) { ans++; } for(int i=0; i<n; i++) { if(i+N>=n) { break; } int c=a[i]; int d=a[i+N]; int ak1=0,ak2=0; if(A[c]==B[c]) { ak1=1; } if(A[d]==B[d]) { ak2=1; } A[a[i]]--; A[a[i+N]]++; if(a[i]==a[i+N]) { if(no==0) { ans++; } continue; } if(B[a[i]]==A[a[i]]) { if(ak1==0) { no--; } } else { if(ak1==1) { // ma[a[i]]=1; no++; } } if(B[a[i+N]]==A[a[i+N]]) { if(ak2==0) { // ma[a[i+N]]=0; no--; } } else { if(ak2==1) { // ma[a[i+N]]=1; no++; } } if(no==0) { ans++; } } printf("%d\n",ans); } return 0;}
阅读全文
0 0
- 2017计蒜之道程序设计大赛初赛第五场
- 2017计蒜之道程序设计大赛初赛第五场
- 2017计蒜之道程序设计大赛初赛第五场题解
- 2017计蒜之道程序设计大赛初赛第一场题解
- 2017计蒜之道程序设计大赛初赛第二场题解
- 2017计蒜之道程序设计大赛初赛第三场题解
- 2017计蒜之道程序设计大赛初赛第四场题解
- 2017计蒜之道程序设计大赛初赛第六场题解
- 2017 计蒜之道初赛第五场题解
- 2017 计蒜之道 初赛 第五场@
- 2017 计蒜之道 初赛 第五场
- 2016 计蒜之道 初赛 第五场
- 2017 计蒜之道 初赛 第五场 A. UCloud 机房的网络搭建
- 2017 计蒜之道 初赛 第五场 A. UCloud 机房的网络搭建(贪心)
- [Hash] 2017 计蒜之道 初赛 第五场 UCloud 的安全秘钥
- 2017 计蒜之道 初赛 第五场——A. UCloud 机房的网络搭建
- 2017计蒜之道初赛第五场-UCloud 机房的网络搭建
- [hash+随机] 2017 计蒜之道初赛第五场UCloud 的安全秘钥
- SweetAlert入门教程
- OSGi简介
- 输入输出
- RAC添加新节点绕过dbca新建实例的方法
- Ubuntu下GTK的安装、编译和测试
- 2017计蒜之道程序设计大赛初赛第五场
- c语言--矩阵逆置
- C++ MOOC 西安交通大学 中国大学生MOOC网 期末考试
- Torch SpatialAveragePooling 实例
- java 程序题 二分法查找二维数组(Dichotomy)
- 视区相关单位vw, vh..简介以及可实际应用场景
- 欢迎使用CSDN-markdown编辑器
- shell中的let命令
- 网口配置文件及路由表配置文件无法生效