2021第四届全国大学生IT技能大赛“传智杯”AK
生活随笔
收集整理的這篇文章主要介紹了
2021第四届全国大学生IT技能大赛“传智杯”AK
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
手是真的很生了,也非常的石志樂
- 除了第四題是icpc-reginal的簽到~銅水平的題,其他的直接暴力就可以了
- AK是AK了,水準(zhǔn)是真的很低了...
- 一想到第五題vector的使用和第三題誤把空格打成換行而wa了四五發(fā),就很“哇塞”凹~
- 不過明天就答辯了,報告還沒開始寫就來水比賽,也真不愧是我了!簡直閑云散鶴
- 話不多說,上題解了:
T1:組原成績
題面
題解
按題目計算,控制格式輸出
代碼
#include <bits/stdc++.h> #include <cmath> using namespace std;int t,h,e; double w;int main() {cin >> t >> h >> e;w = 0.2*t + 0.3*h + 0.5*e;cout<<floor(w)<<endl;return 0; }T2:報告賦分
題面
題解
分三類討論,小于16頁,大于20頁和中間的,3個 if 配輸出,具體看代碼
代碼
#include <bits/stdc++.h> using namespace std;int t,a[1010],p[1010];int main() {cin>>t;for(int i=1; i<=t; i++) {cin>>a[i]>>p[i];if(p[i]<16) {a[i] -= 10;if(a[i]<=0) cout<<"0"<<endl;else cout<<a[i]<<endl;}else if(p[i]>20) {p[i] -= 20;a[i] -= p[i];if(a[i]<=0) cout<<"0"<<endl;else cout<<a[i]<<endl;}else cout<<a[i]<<endl;} return 0; }T3:競爭得分
題面
題解
我想的比較麻煩,但是這種做起來錯的概率低。通過定義另一個數(shù)組求出原來數(shù)組的最大值和最小值,保證原序列不受影響,具體實現(xiàn)看代碼。
代碼
#include <bits/stdc++.h> #include <cmath> using namespace std;int t,a[1010],b[1010]; double w;int main() {cin>>t;for(int i=1; i<=t; i++) {cin>>a[i];b[i] = a[i];}sort(b+1,b+1+t);int minn = b[1];int maxx = b[t];for(int i=1; i<=t; i++){if(a[i]==minn) cout<<"0"<<" ";else {double p = a[i]/1.0;double k = 100*(p-minn/1.0)/(maxx-minn);cout<<floor(k)<<" ";}}return 0; }T4:小卡與質(zhì)數(shù)2
題面
題解
線性篩+暴力對拍,一般遇到這種題,優(yōu)先考慮按位操作,注意篩的時候不要篩錯了,之前就因為篩出來的質(zhì)數(shù)比1e6小了而WA了一發(fā)。這不是白給嗎?當(dāng)然沒前面白給的多了...
代碼
#include <bits/stdc++.h> using namespace std; const int N = 2e6 + 10;int main() {vector<int> vis(N);auto get_prime = [&] (int n){vector<int> p;vis[0] = vis[1] = 1;for (int i = 2; i <= n; i++){if (!vis[i]) p.push_back(i);for (int j = 0; j < (int)p.size() && i * p[j] <= n; j++){vis[i * p[j]] = 1;if (i % p[j] == 0) break;}}};get_prime(2e6);vector<int> ans(N), cnt(25);for (int i = 1; i <= (int)2e6; i++){int lg = __lg(i);bitset<25> st(i);for (int j = 0; j < lg; j++){if (st[j]) ans[i] += cnt[j];}if (!vis[i]) cnt[lg]++;}for (int i = 1; i <= (int)2e6; i++){int lg = __lg(i);ans[i] += cnt[lg];}auto brute = [&] (int n){int cnt = 0;for (int i = 0; i < n; i++){int j = n ^ i;if (!vis[j]) cnt++;}return cnt;};// for (int i = 1000000; i <= 1000000; i++) // { // if (i % 100 == 0) printf("%d ok!\n", i); // cout << brute(i) << " " << ans[i] << endl;assert(brute(i) == ans[i]); // }int t; scanf("%d", &t);while (t--){int n; scanf("%d", &n);printf("%d\n", ans[n]);}return 0; }T5:蘿卜數(shù)據(jù)庫
題面
題解:
直接模擬,但是純數(shù)組會出問題,需要vector遍歷且push_back
代碼
#include <bits/stdc++.h> #include <cmath> #include <vector> using namespace std; vector<int> w[1010]; int n,k,op,a[1010],p; int ymin,ymax,c,v,x;int main() {cin >> n >> k;for(int i=1; i<=n; i++) {cin >> op;if(op==1) {cin >> p;for(int j=1; j<=p; j++) {cin >> c >> v; w[c].push_back(v);}}if(op==2) {int cnt = 0;cin >> x >> ymin >> ymax;for(unsigned int i = 0; i <= w[c].size()-1; ++i) {if(w[x][i]<=ymax && w[x][i]>=ymin) cnt++;}cout<<cnt<<endl;}}return 0; }總結(jié)
以上是生活随笔為你收集整理的2021第四届全国大学生IT技能大赛“传智杯”AK的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 好用的开源软件_推荐_良心软件
- 下一篇: ctfmon.exe开机无法自己主动启动