• AcWing.第121场周赛


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

    比赛地址 : 

    竞赛 - AcWing

    A.    AcWing 5149. 简单计算 

    题目链接 : 

    5149. 简单计算 - AcWing题库

    思路 : 

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

    代码

    1. #include
    2. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    3. #define endl '\n'
    4. using namespace std;
    5. typedef long long LL;
    6. int gcd(int a,int b){ return b==0 ? a : gcd(b,a%b); }
    7. int lcm(int a,int b){ if(a==0||b==0) return 0; return (a*b)/gcd(a,b); }
    8. bool is_prime(int x){if(x<2) return false;
    9. for(int i=2;i<=x/i;i++) if(x%i==0) return false; return true;}
    10. //numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end()); // 去重操作
    11. const int N = 2e5+10;
    12. inline void solve(){
    13. int x,y,z; cin>>x>>y>>z;
    14. int ans = floor(1.0 * (z-y) / x) *x + y;
    15. cout << ans << endl;
    16. }
    17. int main()
    18. {
    19. IOS
    20. int _;
    21. cin >> _;
    22. // _ = 1;
    23. while(_ --) solve();
    24. return 0;
    25. }

    B.  5150.顶牛

    题目链接 : 

    5150. 顶牛 - AcWing题库

    思路 : 

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

    代码 : 

    1. #include
    2. #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    3. #define endl '\n'
    4. using namespace std;
    5. typedef long long LL;
    6. int gcd(int a,int b){ return b==0 ? a : gcd(b,a%b); }
    7. int lcm(int a,int b){ if(a==0||b==0) return 0; return (a*b)/gcd(a,b); }
    8. bool is_prime(int x){if(x<2) return false;
    9. for(int i=2;i<=x/i;i++) if(x%i==0) return false; return true;}
    10. //numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end()); // 去重操作
    11. const int N = 105;
    12. int n,a[N][N];
    13. inline void solve(){
    14. int ans = 0;
    15. vector<int> res;
    16. cin >> n;
    17. for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) cin>>a[i][j];
    18. for(int i=1;i<=n;i++){
    19. bool tag = true;
    20. for(int j=1;j<=n;j++){
    21. if(a[i][j]==1 || a[i][j]==3){
    22. tag = false;
    23. break;
    24. }
    25. }
    26. if(tag){
    27. res.push_back(i);
    28. ans ++;
    29. }
    30. }
    31. cout << ans << endl;
    32. for(int num : res) cout << num << " ";
    33. return ;
    34. }
    35. int main()
    36. {
    37. IOS
    38. int _;
    39. // cin >> _;
    40. _ = 1;
    41. while(_ --) solve();
    42. return 0;
    43. }

    C.        5151.程序调用

    原题链接 : 

    5151. 程序调用 - AcWing题库

    思路 : 

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

    代码 : 

    1. #include
    2. using namespace std;
    3. typedef long long LL;
    4. const int N = 1e5+144;
    5. LL n, m, k,a[N],ans;
    6. unordered_map mp;
    7. void swap(int &x,int &y){
    8. int tmp = x;
    9. x = y;
    10. y = tmp;
    11. }
    12. int main()
    13. {
    14. cin>>n>>m>>k;
    15. for(int i=1;i<=n;i++){
    16. cin>>a[i];
    17. mp[a[i]] = i;
    18. }
    19. for(int i=1;i<=m;i++){
    20. int b ; cin>>b;
    21. if(mp[b]%k==0) ans += mp[b]/k;
    22. else ans += mp[b]/k+1;
    23. int idx = mp[b];
    24. if(idx==1) continue;
    25. int beforeNum = a[idx-1];
    26. swap(a[idx-1],a[idx]);
    27. swap(mp[b],mp[beforeNum]);
    28. }
    29. cout << ans << endl;
    30. return 0;
    31. }

  • 相关阅读:
    浅谈在操控器类中,为何要通过osgGA::CameraManipulator的逆矩阵改变视点位置
    CalBioreagents艾美捷兔单克隆抗人Id1克隆5-3说明书
    Spring入门
    0.UML
    小程序开发.微信小程序.组件.视图容器
    印象最深的bug
    对加密世界的经济误解:现金是储蓄?稀缺性创造价值?
    java 实现链表
    Codeforces 1281F 树上背包
    【教程】微信小程序导入外部字体详细流程
  • 原文地址:https://blog.csdn.net/ros275229/article/details/132943455