AtCoder Beginner Contest 331

A - Tomorrow (atcoder.jp)

模拟进位即可

AC代码:

#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
int M,D;
int y,m,d;
void solve() {
    cin>>M>>D;
    cin>>y>>m>>d;
    int jinm=0,jiny=0;
    d+=1;
    if(d>D) d-=D,jinm+=1;
    m+=jinm;
    if(m>M) m-=M,jiny+=1;
    y+=jiny;
    cout<<y<<' '<<m<<' '<<d<<endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}

B - Buy One Carton of Milk (atcoder.jp)

数据比较小,直接考虑暴力枚举

AC代码:

#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
int n;
int S,M,L;
void solve() {
    cin>>n;
    cin>>S>>M>>L;
    int ans=2e9;
    for(int i=0;i<=n/6+1;i++){
        for(int j=0;j<=n/8+1;j++){
            for(int k=0;k<=n/12+1;k++){
                if(i*6+j*8+k*12>=n) ans=min(ans,i*S+j*M+k*L);
            }
        }
    }
    cout<<ans<<endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}

C - Sum of Numbers Greater Than Me (atcoder.jp)

从小到大枚举出现过的数值,它的答案即为sum减去它的数值乘它的个数,同时sum也相应减小

AC代码:

#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N=2e5+10,M=1e6+10;
int a[N];
int ans[M];
int n;
void solve() {
    cin>>n;
    map<int,int>mp;
    set<int>s;
    int sum=0;
    for(int i=1;i<=n;i++) cin>>a[i],mp[a[i]]++,sum+=a[i],s.insert(a[i]);
    for(auto v:s){
        sum-=mp[v]*v;
        ans[v]=sum;
    }
    for(int i=1;i<=n;i++) cout<<ans[a[i]]<<' ';
    cout<<endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}

相关推荐

  1. AtCoder Beginner Contest 331

    2023-12-05 19:14:02       41 阅读
  2. AtCoder Beginner Contest 332

    2023-12-05 19:14:02       43 阅读
  3. AtCoder Beginner Contest 332

    2023-12-05 19:14:02       44 阅读
  4. ABC336(A-C)

    2023-12-05 19:14:02       40 阅读
  5. ABC337(A-C)

    2023-12-05 19:14:02       33 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-05 19:14:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-05 19:14:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-05 19:14:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-05 19:14:02       20 阅读

热门阅读

  1. k8s中dubbo配置与实现

    2023-12-05 19:14:02       43 阅读
  2. TCP/IP

    TCP/IP

    2023-12-05 19:14:02      35 阅读
  3. 内网环境安装K8S1.20.11版本集群

    2023-12-05 19:14:02       28 阅读
  4. Porthopper服务测试程序编程

    2023-12-05 19:14:02       38 阅读
  5. Android adb:“more than one device/emulator“解决办法

    2023-12-05 19:14:02       37 阅读
  6. 11. Mysql 子查询

    2023-12-05 19:14:02       40 阅读
  7. 在jsp页面利用Ajax动态显示数据库中数据

    2023-12-05 19:14:02       30 阅读
  8. MySQL索引有哪些优缺点

    2023-12-05 19:14:02       34 阅读
  9. 前端怎么实现跨域请求

    2023-12-05 19:14:02       27 阅读
  10. 【干货】接口公共方法(字典表查询)

    2023-12-05 19:14:02       21 阅读