本文最后更新于 381 天前,其中的信息可能已经有所发展或是发生改变。
不存在的数
- 签到题,模拟
- 对输入的数进行标记,从 1 遍历到 N,输出没有被标记的数字即可
std标程:
| #include <iostream> |
| #include <cstring> |
| #include <cstdio> |
| #include <algorithm> |
| #include <cmath> |
| #include <sstream> |
| #include <vector> |
| #include <queue> |
| #include <stack> |
| #include <map> |
| #include <set> |
| #include <unordered_map> |
| #include <unordered_set> |
| |
| using namespace std; |
| |
| #define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) |
| #define re register |
| #define fi first |
| #define se second |
| #define endl '\n' |
| |
| typedef long long LL; |
| typedef unsigned long long ULL; |
| typedef pair<int, int> PII; |
| typedef pair<LL, LL> PLL; |
| |
| const int N = 1e6 + 3; |
| const int INF = 0x3f3f3f3f, mod = 1e9 + 7; |
| const double eps = 1e-6, PI = acos(-1); |
| |
| int a[N]; |
| |
| void solve(){ |
| |
| int n, m; cin >> n >> m; |
| for (int i = 0; i < m; i ++) { |
| int x; cin >> x; a[x] = 1; |
| } |
| for (int i = 1; i <= n; i ++) { |
| if (a[i] == 0) cout << i << ' '; |
| } |
| } |
| |
| int main(){ |
| |
| IOS; |
| |
| int _ = 1; |
| |
| |
| |
| while(_ --){ |
| solve(); |
| } |
| |
| return 0; |
| |
| } |
一血代码:
| #include<bits/stdc++.h> |
| using namespace std; |
| |
| int main() |
| { |
| int n, m; |
| cin >> n >> m; |
| |
| map<int, int>mp; |
| |
| for( int i = 1 ; i <= m ; i++ ) { |
| int x; |
| cin >> x; |
| mp[x]++; |
| } |
| |
| for( int i = 1 ; i <= n ; i++ ) { |
| if( mp[i] ) continue; |
| else cout << i << ' '; |
| } |
| } |
疯狂校园跑
配速为1km所用时间,所以配速为时间除以路程;
知道这一点之后就可以写代码了。
std标程:
| #include <stdio.h> |
| |
| int main() |
| { |
| int t; scanf("%d", &t); |
| while (t --) |
| { |
| int s, t; scanf("%d %d", &s, &t); |
| double sps = t * 1.0 / s; |
| double spm = sps * 1000; |
| printf("%d:%02d:%03d\n", (int)(spm / 60), (int)(spm - (int)(spm / 60) * 60), ((int)(spm * 1000) % 1000)); |
| } |
| return 0; |
| } |
一血代码:
| #include <bits/stdc++.h> |
| #define int long long |
| #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) |
| #define endl '\n' |
| |
| using namespace std; |
| |
| void solve(){ |
| int n, s; |
| cin >> n >> s; |
| double res = 1.0 * 1000 * s / n; |
| int h = res / 60; |
| int m = res - h * 60; |
| int ms = 1.0 * (res - h * 60 - m) * 1000; |
| printf("%d:%02d:%03d\n", h, m, ms); |
| } |
| |
| signed main(){ |
| IOS; |
| int t = 1; |
| cin >> t; |
| while(t --) solve(); |
| return 0; |
| } |
输出语句
std标程:
| #include <bits/stdc++.h> |
| |
| using namespace std; |
| |
| void solve() |
| { |
| string s; |
| getline(cin, s); |
| |
| int l = 8, r = s.size() - 4; |
| for (int i = l; i <= r; i ++) |
| { |
| if (i != r && s[i] == '\\') |
| { |
| if (s[i + 1] == '\'') |
| { |
| cout << '\''; |
| i ++; |
| } |
| else if (s[i + 1] == '\"') |
| { |
| cout << '\"'; |
| i ++; |
| } |
| else if (s[i + 1] == '\\') |
| { |
| cout << '\\'; |
| i ++; |
| } |
| else if (s[i + 1] == 'n') |
| { |
| cout << '\n'; |
| i ++; |
| } |
| } |
| else |
| { |
| cout << s[i]; |
| } |
| } |
| } |
| |
| int main() |
| { |
| solve(); |
| return 0; |
| } |
一血代码:
| #include<iostream> |
| #include<string> |
| using namespace std; |
| int main(void) |
| { |
| string a; |
| getline(cin,a); |
| int flag=0; |
| for(int i=0;i<a.size();i++) |
| { |
| if(a[i-1]=='f'&&a[i]=='('&&a[i+1]=='"') |
| { |
| for(int j=i+2;j<a.size();j++) |
| { |
| if(a[j]=='"'&&a[j+1]==')'&&a[j+2]==';') |
| { |
| break; |
| } |
| if(a[j]=='\\') |
| { |
| j++; |
| if(a[j]=='0') |
| { |
| cout<<" "; |
| } |
| else if(a[j]=='n') |
| { |
| cout<<endl; |
| } |
| else |
| { |
| cout<<a[j]; |
| } |
| } |
| else cout<<a[j]; |
| } |
| } |
| } |
| return 0; |
| } |
疯狂汽车运输队
本题为简单的01背包,不过是需要算一下超重多少,但是最多超重100%,那么代码就如下。
std标程:
| #include<bits/stdc++.h> |
| |
| using namespace std; |
| int f[10000]; |
| int main() |
| { |
| int T; |
| cin>>T; |
| while(T--) |
| { |
| int n,m; |
| cin>>n>>m; |
| for(int i=1;i<=m*2;i++) f[i]=0; |
| for(int i=1;i<=n;i++) |
| { |
| int x,y; |
| cin>>x>>y; |
| for(int j=m*2;j>=x;j--) f[j]=max(f[j],f[j-x]+y); |
| } |
| int ans=0; |
| for(int i=m;i<=2*m;i++) |
| { |
| int x=(i-m)*1.0/(m*1.0)*10; |
| |
| x=f[i]-(int)(f[i]*x*0.1); |
| ans=max(x,ans); |
| |
| } |
| cout<<ans<<"\n"; |
| } |
| return 0; |
| } |
为什么演奏春日影
- 签到题,trick
- 选择 k = 1,则后面每次都开摆,任何正整数取模结果都是 0,因此结果全为 Yes
std标程:
| #include <bits/stdc++.h> |
| |
| using namespace std; |
| |
| int main() |
| { |
| int n, m; cin >> n >> m; |
| for (int i = 0; i < n; i ++) { |
| int x; cin >> x; |
| } |
| cout << "Yes"; |
| return 0; |
| } |
一血代码:
| #include<bits/stdc++.h> |
| using namespace std; |
| |
| map<int, int>mp; |
| |
| void calc( int x ) |
| { |
| for( int i = 2 ; i <= sqrt(x) ; i++ ) { |
| if( x % i == 0 ) { |
| mp[i]++; |
| mp[x % i]++; |
| } |
| } |
| } |
| int main() |
| { |
| int n, m; |
| cin >> n >> m; |
| |
| vector<int> a(n); |
| |
| for( int i = 0 ; i < n ; i++ ) { |
| cin >> a[i]; |
| } |
| |
| for( int i = 0 ; i < n ; i++ ) { |
| calc(a[i]); |
| } |
| |
| int mx = 0; |
| for( auto i : mp ) { |
| mx = max(mx, i.second); |
| } |
| |
| if( mx + m < n ) cout << "No"; |
| else cout << "Yes"; |
| } |
BinGo游戏
std标程:
| #include <iostream> |
| #include <cstring> |
| #include <cstdio> |
| #include <algorithm> |
| #include <cmath> |
| #include <sstream> |
| #include <vector> |
| #include <queue> |
| #include <stack> |
| #include <map> |
| #include <set> |
| #include <unordered_map> |
| #include <unordered_set> |
| |
| using namespace std; |
| |
| #define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr) |
| #define re register |
| #define fi first |
| #define se second |
| #define endl '\n' |
| |
| typedef long long LL; |
| typedef unsigned long long ULL; |
| typedef pair<int, int> PII; |
| typedef pair<LL, LL> PLL; |
| |
| const int N = 1e6 + 3; |
| const int INF = 0x3f3f3f3f, mod = 1e9 + 7; |
| const double eps = 1e-6, PI = acos(-1); |
| |
| int a[10][10]; |
| |
| bool check1() { |
| for (int i = 0; i < 5; i ++) { |
| bool flag = 1; |
| for (int j = 0; j < 5; j ++) { |
| if (a[i][j] % 2 != 0) { |
| flag = 0; break; |
| } |
| } |
| if (flag) return 1; |
| } |
| return 0; |
| } |
| |
| bool check2() { |
| for (int i = 0; i < 5; i ++) { |
| bool flag = 1; |
| for (int j = 0; j < 5; j ++) { |
| if (a[j][i] % 2 == 0) { |
| flag = 0; break; |
| } |
| } |
| if (flag) return 1; |
| } |
| return 0; |
| } |
| |
| bool check3() { |
| bool mainDiag = a[0][0] % 2 == 0; |
| bool offDiag = a[0][4] % 2 == 0; |
| for (int i = 1; i < 5; i++) { |
| if ((a[i][i] % 2 == 0) == mainDiag || (a[i][4-i] % 2 == 0) == offDiag) return false; |
| mainDiag = !mainDiag; |
| offDiag = !offDiag; |
| } |
| return true; |
| } |
| |
| void solve(){ |
| for (int i = 0; i < 5; i++) { |
| for (int j = 0; j < 5; j++) cin >> a[i][j]; |
| } |
| |
| if (check1() || check2() || check3()) { |
| cout << "BINGO" << endl; |
| } else { |
| cout << "OHNO" << endl; |
| } |
| } |
| |
| int main(){ |
| |
| IOS; |
| |
| int _ = 1; |
| |
| |
| |
| while(_ --){ |
| solve(); |
| } |
| |
| return 0; |
| |
| } |
一血代码:
| #include <bits/stdc++.h> |
| #define int long long |
| #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) |
| #define endl '\n' |
| |
| using namespace std; |
| |
| int a[10][10]; |
| bool ok; |
| |
| bool check(int x){ |
| int f = 0; |
| for(int i = 0; i < 5; i ++){ |
| if(a[i][x] % 2 != 1) break; |
| if(i == 4) f = 1; |
| } |
| for(int i = 0; i < 5; i ++){ |
| if(a[x][i] % 2 != 0) break; |
| if(i == 4) f = 1; |
| } |
| if(f) return true; |
| return false; |
| } |
| |
| void solve(){ |
| for(int i = 0; i < 5; i ++) |
| for(int j = 0; j < 5; j ++) |
| cin >> a[i][j]; |
| |
| for(int i = 0; i < 5; i ++){ |
| if(check(i)){ |
| ok = true; |
| |
| } |
| } |
| |
| bool ok1 = false, ok2 = false; |
| for(int i = 1; i < 5; i ++){ |
| if(a[i][i] % 2 == a[i - 1][i - 1] % 2){ |
| break; |
| } |
| if(i == 4) ok1 = true; |
| } |
| for(int i = 1; i < 5; i ++){ |
| if(a[i][4 - i] % 2 == a[i - 1][5 - i] % 2){ |
| break; |
| } |
| if(i == 4) ok2 = true; |
| } |
| if(ok1 && ok2) ok = true; |
| if(ok) cout << "BINGO" << endl; |
| else cout << "OHNO" << endl; |
| } |
| |
| signed main(){ |
| IOS; |
| int t = 1; |
| |
| while(t --) solve(); |
| return 0; |
| } |
下载序列
std标程:
| #include <bits/stdc++.h> |
| |
| using namespace std; |
| typedef long long LL; |
| const int N = 1e5 + 10; |
| |
| int x, m, k, n, e[N]; |
| priority_queue<LL, vector<LL>, greater<LL>> q; |
| |
| int main() { |
| cin >> x >> m >> k; |
| cin >> n; |
| for (int i = 1; i <= n; i ++) |
| { |
| int a, t; |
| cin >> a >> t; |
| e[i] = (a + x - 1) / x + t; |
| } |
| for (int i = 1; i <= m; i ++) |
| { |
| q.push(e[i]); |
| } |
| LL ans = 0; |
| for (int i = m + 1; i <= n; i ++) |
| { |
| ans = q.top(); q.pop(); |
| q.push(e[i] + ans); |
| } |
| while (q.size()) |
| { |
| ans = q.top(); q.pop(); |
| } |
| cout << ans * k; |
| return 0; |
| } |
会 赢 的
我们只需要以下操作即可:
- 选取数组中的 100(至多一个)
- 选取 1 ~ 9 之间的一个数
- 选取 10 ~ 90 之间能被10整除的数
- 如果 2、3 操作选不出任何一个数,那么可以在剩下的数里选任意一个(没有则不选)
std标程:
| #include <stdio.h> |
| |
| int n, a[1010]; |
| |
| int main() |
| { |
| scanf("%d", &n); |
| for (int i = 1; i <= n; i ++) |
| scanf("%d", &a[i]); |
| |
| for (int i = 1; i < n; i ++) |
| for (int j = i + 1; j <= n; j ++) |
| if (a[i] > a[j]) |
| { |
| int temp = a[i]; |
| a[i] = a[j]; |
| a[j] = temp; |
| } |
| |
| int ans = 0, p[5] = {0}; |
| for (int i = 1; i <= n; i ++) |
| { |
| if (p[1] == 0 && a[i] >= 1 && a[i] <= 9) |
| p[1] ++, ans ++; |
| else if (p[2] == 0 && a[i] >= 10 && a[i] <= 99 && a[i] % 10 == 0) |
| p[2] ++, ans ++; |
| else if (p[3] == 0 && a[i] == 100) |
| p[3] ++, ans ++; |
| else |
| p[0] ++; |
| } |
| if (p[1] == 0 && p[2] == 0 && p[0] > 0) ans ++; |
| |
| printf("%d", ans); |
| |
| return 0; |
| } |
一血代码:
| #include<bits/stdc++.h> |
| using namespace std; |
| typedef long long LL; |
| const int N=110; |
| int a[5]; |
| int n,res=0,cnt=0; |
| int main(){ |
| cin>>n; |
| for(int i=1;i<=n;i++){ |
| int x; |
| cin>>x; |
| if(x==0)a[0]++; |
| else if(x==100)a[1]=1; |
| else if(x>0&&x<10)a[2]++; |
| else a[3]++; |
| if(x%10==0)cnt++; |
| } |
| if(a[0])res+=a[0]; |
| if(a[1])res++; |
| if(a[2]&&a[3]){ |
| if(cnt)res+=2; |
| else res+=1; |
| }else if(a[2]||a[3])res+=1; |
| |
| cout<<res<<endl; |
| return 0; |
| } |