A:不难,题意能难搞懂。
题意:给定n个数,从中选出k个,使他们的个位,十位,百位,上的数字只有一个不是0。
思路:数据小,先判0和100,再判各位和十位。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> #include <stack> #include <map> #include <string> #define LL long long #define DB double using namespace std; int re[109]; int v[109]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&re[i]); sort(re,re+n); int ans = (re[0]==0); int rr[109],cnt = 0; if(re[0]==0) rr[cnt++] = 0; if(re[n-1]==100) ans++,rr[cnt++] = 100; if(re[0]==0) re[0] = re[1]; if(re[0]) ans++,rr[cnt++] = re[0]; if(re[0]<10) { for(int j=0;j<n;j++) if(re[j]%10==0&&re[j]!=100) { ans++; rr[cnt++] = re[j]; break; } } ans = min(ans,n); printf("%d\n",ans); for(int i=0;i<ans;i++) { if(i) printf(" "); printf("%d",rr[i]); }printf("\n"); return 0; }
讯享网
B题,犯了一个很sb的错,当我lock的瞬间发现数据类型定义错了。今天发现两个数相乘会超longlong。
讯享网#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> #include <stack> #include <map> #include <string> #define LL long long #define DB double using namespace std; unsigned LL p,q; int n; unsigned LL re[109]; int solve() { for(int i=0;i<n;i++) { if(re[i]&&q&&p/q<re[i]) return 0; p-=re[i]*q; if(p<0) return 0; if(i==n-1) { if(p!=0) return 0; } swap(p,q); } return 1; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif cin>>p>>q;//cout<<p<<" "<<q<<endl; scanf("%d",&n); for(int i=0;i<n;i++) cin>>re[i]; if(solve()) printf("YES\n"); else printf("NO\n"); return 0; }
C题:随便yy了一下。居然过了。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <cmath> #include <stack> #include <map> #include <string> #define LL long long #define DB double using namespace std; LL a; int n; const int N = ; LL re[N]; LL v[N]; int main() { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif scanf("%d",&n); int cnt = -1 ; for(int i=0;i<n;i++) { cin>>a; if(cnt==-1) { re[++cnt] = a; v[cnt] = 1; }else { if(re[cnt]==a) { v[cnt]++; }else { re[++cnt] = a; v[cnt] = 1; } } } LL k = 0; for(int i=0;i<cnt;i++) { LL tmp = v[i]; for(int j=0;j<(re[i+1]-re[i])&&tmp;j++) { if(tmp%2) { k++; }tmp/=2; } v[i+1] += tmp; } //cout<<re[cnt]<<" "<<k<<endl; LL ans= re[cnt] - k; LL tmp = v[cnt]; while(tmp) { if(tmp%2==0) ans++; tmp/=2; } cout<<ans<<endl; return 0; }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/109697.html