codeforces 305 我太水了,加把劲锕。

codeforces 305 我太水了,加把劲锕。A 不难 题意能难搞懂

大家好,欢迎来到IT知识分享网。

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://haidsoft.com/127263.html

(0)
上一篇 2025-09-12 16:00
下一篇 2025-09-12 16:15

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信