AcWing.第121场周赛

以下是acwing第121场比赛的abc三题

比赛地址 :

竞赛 - AcWing

A. AcWing 5149. 简单计算

题目链接 :

5149. 简单计算 - AcWing题库

思路 :

直接模拟,用floor()函数来实现下取整

代码

cpp 复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;
typedef long long LL;
int gcd(int a,int b){ return b==0 ? a : gcd(b,a%b); }
int lcm(int a,int b){ if(a==0||b==0) return 0; return (a*b)/gcd(a,b); }
bool is_prime(int x){if(x<2) return false;
for(int i=2;i<=x/i;i++) if(x%i==0) return false; return true;}
//numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end()); // 去重操作
const int N = 2e5+10;

inline void solve(){
    int x,y,z; cin>>x>>y>>z;
    int ans = floor(1.0 * (z-y) / x) *x + y;
    cout << ans << endl;
}
 
int main()
{
    IOS
    int _;
    cin >> _;
    // _ = 1; 
    while(_ --) solve();
    return 0;
}

B. 5150.顶牛

题目链接 :

5150. 顶牛 - AcWing题库

思路 :

如果没出现a[i][j] = 1 || a[i][j] = 3,那么代表i牛是满足题目条件的;

这样模拟即可!

代码 :

cpp 复制代码
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;
typedef long long LL;
int gcd(int a,int b){ return b==0 ? a : gcd(b,a%b); }
int lcm(int a,int b){ if(a==0||b==0) return 0; return (a*b)/gcd(a,b); }
bool is_prime(int x){if(x<2) return false;
for(int i=2;i<=x/i;i++) if(x%i==0) return false; return true;}
//numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end()); // 去重操作
const int N = 105;
int n,a[N][N];

inline void solve(){
    int ans = 0;
    vector<int> res;
    cin >> n;
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j];
    for(int i=1;i<=n;i++){
        bool tag = true;
        for(int j=1;j<=n;j++){
            if(a[i][j]==1 || a[i][j]==3){
                tag = false;
                break;
            }
        }
        if(tag){
            res.push_back(i);
            ans ++;
        }
    }
    cout << ans << endl;
    for(int num : res) cout << num << " ";
    return ;
}

int main()
{
    IOS
    int _;
    // cin >> _;
    _ = 1; 
    while(_ --) solve();
    return 0;
}

C. 5151.程序调用

原题链接 :

5151. 程序调用 - AcWing题库

思路 :

用hsah表实现模拟,否则会超时!!!

代码 :

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5+144;
LL n, m, k,a[N],ans;
unordered_map<LL,LL> mp;
void swap(int &x,int &y){
    int tmp = x;
    x = y;
    y = tmp;
}
int main()
{
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        mp[a[i]] = i;
    }
    for(int i=1;i<=m;i++){
        int b ; cin>>b;
        if(mp[b]%k==0) ans += mp[b]/k;
        else ans += mp[b]/k+1;
        int idx = mp[b];
        if(idx==1) continue;
        int beforeNum = a[idx-1];
        swap(a[idx-1],a[idx]);
        swap(mp[b],mp[beforeNum]);
    }
    cout << ans << endl;
    return 0;
}
相关推荐
乌萨奇也要立志学C++22 分钟前
【洛谷】6 道题吃透堆的应用:模板堆、第 k 小、最小函数值等全攻略
算法
合作小小程序员小小店1 小时前
web网页开发,在线%推荐算法学院培养计划,图书推荐,基于Python,FlaskWeb,用户和物品推荐MySql
python·mysql·算法·flask·推荐算法
Cx330❀2 小时前
《C++ STL:vector类(上)》:详解基础使用&&核心接口及经典算法题
开发语言·c++·经验分享·算法
那我掉的头发算什么2 小时前
【数据结构】二叉树的高频热门面试题大全
java·开发语言·数据结构·python·算法·链表·intellij idea
遇安.YuAn2 小时前
JAVA之求平方根
java·开发语言·算法
禁默3 小时前
机器学习基础入门(第三篇):监督学习详解与经典算法
学习·算法·机器学习
sensen_kiss3 小时前
INT305 Machine Learning 机器学习 Pt.1 导论与 KNN算法
人工智能·算法·机器学习
软件算法开发5 小时前
基于黑翅鸢优化的LSTM深度学习网络模型(BKA-LSTM)的一维时间序列预测算法matlab仿真
深度学习·算法·lstm·时间序列预测·黑翅鸢优化·bka-lstm
小南家的青蛙5 小时前
LeetCode第79题 - 单词搜索
算法·leetcode·职场和发展
PAK向日葵5 小时前
【算法导论】PDD 0928 笔试题解
算法·面试