复仇者联盟 排位赛#4题解(包括附加题)
2024-08-16 10:32:30
发布于:浙江
本次竞赛复仇者_必胜啊为晋升者(成为管理员)
恭喜恭喜🎆🎆🎆👏👏👏
OK,其他人也不要气馁,继续努力吧!(还要连续2次排位赛,团队人数增长的真快)
由于受团队人数的影响欢乐赛暂时停止制作,首先制作排位赛2次
由于本人太懒,只做题解,不给各位解析了(那么小应该没人看见)
话不多说,开始速通排位赛#4
T1——A / B problem
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
cin>>a>>b;
cout<<a/b<<endl;
return 0;
}
T2——01背包问题
#include<bits/stdc++.h>
using namespace std;
int dp[100005], w[10005], c[10005];
int main(){
int n, v;
cin >> n >> v;
for(int i = 1; i <= n; i++){
cin >> c[i] >> w[i];
}
for(int i = 1; i <= n; i++){
for(int j = v; j >= w[i]; j--){
dp[j] = max(dp[j - w[i]] + c[i], dp[j]);
}
}
cout << dp[v];
return 0;
}
T3——奖牌数排序
#include<bits/stdc++.h>
#define endl '\n'
const int N=1e5+10;
struct node{
std::string country;
int a,b,c,id,sum=0;
}r[N];
bool cmp(node x,node y){
if(x.a!=y.a) return x.a>y.a;
if(x.sum!=y.sum) return x.sum>y.sum;
if(x.b!=y.b) return x.b>y.b;
if(x.c!=y.c) return x.c>y.c;
return x.id<y.id;
}
int main(){
int _;
std::cin>>_;
while(_--){
int n;
std::cin>>n;
for(int i=0;i<n;++i){
std::cin>>r[i].country>>r[i].a>>r[i].b>>r[i].c;
r[i].sum=r[i].a+r[i].b+r[i].c;
r[i].id=i+1;
}
std::sort(r,r+n,cmp);
for(int i=0;i<n;++i){
std::cout<<r[i].country<<" "<<r[i].a<<" "<<r[i].b<<" "<<r[i].c<<" "<<r[i].sum<<endl;
}
}
}
T4——建筑抢修
#include<bits/stdc++.h>
using namespace std;
struct node{
int t1, t2;
bool operator < (const node &b){
return t2 < b.t2;
}
}a[200005];
struct priority_queue_big{
vector <int> v;
void push(int n){
v.push_back(n);
int i = v.size();
while(i / 2 >= 1 && v[i - 1] >= v[i / 2 - 1]){
swap(v[i - 1], v[i / 2 - 1]);
i >>= 1;
}
}
int top(){
return v[0];
}
void pop(){
v[0] = v.back();
v.pop_back();
int i = 1;
while(i * 2 <= v.size()){
int j = i << 1;
if(j < v.size() && v[j] > v[j - 1]) j++;
if(v[i - 1] >= v[j - 1]) return;
swap(v[i - 1], v[j - 1]);
i = j;
}
}
}q;
int main(){
int n;
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].t1 >> a[i].t2;
}
sort(a + 1, a + n + 1);
long long ct = 0, ctt = 0;
for(int i = 1; i <= n; i++){
ctt += a[i].t1;
q.push(a[i].t1);
if(ctt > a[i].t2){
ctt -= q.top();
q.pop();
}else ct++;
}
cout << ct;
return 0;
}
T5——导弹拦截
#include<bits/stdc++.h>
using namespace std;
int a[200005], b[200005];
int read(){
char c = getchar();
int x = 0, f = 1;
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)){
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return x * f;
}
int main(){
int n = read();
for(int i = 1; i <= n; i++){
a[i] = read(), b[i] = read();
}
long long mn = 0x3f3f3f3f3f3f3f3f;
for(int i = 0; i <= 1000; i++){
long long mx = 0;
for(int j = 1; j <= n; j++){
mx = max(mx, 1ll * (a[j] - i) * (a[j] - i) + 1ll * b[j] * b[j]);
}
mn = min(mn, mx);
}
cout << mn;
return 0;
}
T6——栈の模拟
#include <iostream>
#include <cstdio>
#include <stack>
#define int unsigned long long
using namespace std;
int read(){//快读
char c = getchar();
int x = 0;
while(!isdigit(c)){
c = getchar();
}
while(isdigit(c)){
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return x;
}
void _write(int n){//快写
if(n == 0) return;
_write(n / 10);
putchar(n % 10 + '0');
}
void write(int n, bool end = 0){//快写,增加了输出0和负数并附带换行
if(n < 0) putchar('-'), _write(-n);
else if(n == 0) putchar('0');
else _write(n);
if(end) putchar('\n');//判断是否要换行
}
void solve(){
stack <int> stk;
int n = read();
while(n--){
string s;
cin >> s;
if(s == "push"){
int tmp;
cin >> tmp;
stk.push(tmp);
}
if(s == "pop"){
if(stk.empty()) puts("Empty");
else stk.pop();
}
if(s == "query"){
if(stk.empty()) puts("Anguei!");
else write(stk.top(), 1);
}
if(s == "size") write(stk.size(), 1);
}
}
signed main(){
int t = read();
while(t--){
solve();
}
return 0;
}
T7——校门外的树(升级版)
#include<bits/stdc++.h>
using namespace std;
short a[100000005];
int main(){
int n, t, l, r;
scanf("%d%d", &n, &t);
while(t--){
scanf("%d%d", &l, &r);
a[l]--, a[r + 1]++;
}
int ct = 0, ctt = 0;
for(int i = 0; i <= n; i++){
ctt += a[i];
ct += (ctt == 0);
}cout << ct;
return 0;
}
附加题
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node{
char a[100005];
int len = 0, f = 1;
node(){
memset(a, 0, sizeof(a));
}
void __init(int n){
if(n < 0) f = -1;
while(n){
a[++len] = n % 10;
n /= 10;
}
}
void print(){
if(f == -1) putchar('-');
for(int i = len; i >= 1; i--) putchar(a[i] + '0');
}
node operator * (const node &b) const{
node c;
c.len = len + b.len;
if(f + b.f == 0){
c.f = -c.f;
}
for(int i = 1; i <= len; i++){
int x = 0;
for(int j = 1; j <= b.len; j++){
int weishu = i + j - 1;
c.a[weishu] += x + a[i] * b.a[j];
x = c.a[weishu] / 10;
c.a[weishu] %= 10;
}c.a[i + b.len] = x;
}while(c.a[c.len] == 0 && c.len > 1) c.len--;
return c;
}
node operator ^ (const int b) const{
node null;
null.f = -1;
if(b < 0) return null;
node tmp;
tmp.len = tmp.a[1] = 1;
node a1 = *this;
int t = b;
while(t){
if(t & 1){
if(a1.len + tmp.len > 1e5) return null;
tmp = tmp * a1;
}
if(a1.len + a1.len > 1e5) return null;
a1 = a1 * a1, t >>= 1;
}return tmp;
}
};
char p[1000005];
int pow(int n, int k, int p){
int tmp = 1;
while(k){
if(k & 1) tmp = tmp * n % p;
n = n * n % p, k >>= 1;
}
return tmp;
}
signed main(){
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
string s;
cin >> s;
if(s == "1_998244353"){
int t, n;
cin >> t;
while(t--){
cin >> n;
cout << pow(19, n, 998244353) << endl;
}
}
if(s == "1_?"){
int t, n;
cin >> t;
while(t--){
cin >> n;
cout << pow(19, n, 101) << endl;
}
}
if(s == "1_(10^998244353)"){
int t, n;
cin >> t;
node _19, ans;
_19.__init(19);
while(t--){
cin >> n;
ans = _19 ^ n;
ans.print();
putchar('\n');
}
}
if(s == "2p"){
memset(p, 'p', sizeof(p));
p[0] = p[1] = '.';
for(int i = 2; i <= 1000; i++){
if(p[i] == 'p'){
for(int j = i << 1; j <= 1000000; j += i) p[j] = '.';
}
}
int t, l, r;
cin >> t;
while(t--){
cin >> l >> r;
for(int i = l; i <= r; i++) cout << p[i];
cout << endl;
}
}
fclose(stdin), fclose(stdout);
return 0;
}
没加入复仇者联盟的人,可以戳我加入哦~
全部评论 4
哪个沈今出的附加题 写这么长的代码
2024-09-08 来自 广东
0布吉岛
2024-09-08 来自 浙江
0
2024-09-08 来自 广东
0不联盟,不过以后会出一个和别的团队一样的附属团队,你考虑吗?
2024-09-08 来自 浙江
0可以
2024-09-08 来自 广东
0OK
2024-09-08 来自 浙江
0
再顶
2024-08-16 来自 浙江
0顶
2024-08-16 来自 浙江
0
有帮助,赞一个