2017计蒜之道程序设计大赛初赛第五场
来源:互联网 发布:oracle数据库漏洞 编辑:程序博客网 时间:2024/05/21 09:47
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
第二题:我是暴力匹配的,复杂度m*n*n
#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;}
#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 的安全秘钥
- 树莓派下安装Django环境
- shell变量
- Centos下安装mysql
- 代码编写技巧
- 软件工程-系统开发方法-jackson方法
- 2017计蒜之道程序设计大赛初赛第五场
- 选择排序
- [LeetCode] Perfect Squares
- VB.NET总结
- vue--mounted
- java中IO流中的标准输入输出流
- 前端知识点整理系列(二)—— apply() call() bind()
- java中IO流中的转换流
- 图标切换,内容展开