东华大学2020年程序设计竞赛(同步赛)

A.shooting Game

题目链接

题目描述成中文:n个人(n<=100)一起比赛,有三种目标给你射击,红色:1分,白色:2分,黑色:3分。已知每个人射中三种目标的数量,要你求出得分最高的选手,分数相同就取id较小的一个。
输入描述:输入n。接下来n行是中,每行一个四个整数,分别是选手的id,以及红白黑各个目标数目。
输出
选手的id以及总分。
这就是一道签到题,我比较菜,搞了个结构体,代码如下。

#include <iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<cstdio>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
#define pb push_back
#define pll pair<ll,ll>
#define INF 0x3f3f3f3f
const int mod = 1e9+7;
const int maxn = 100005;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long ll;
inline ll read() { ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return s * w; }
inline void write(ll x) { if (!x) { putchar('0'); return; } char F[200]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-'); int cnt = 0;    while (tmp > 0) { F[cnt++] = tmp % 10 + '0';     tmp /= 10; }    while (cnt > 0)putchar(F[--cnt]); }
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1;   while (b) { if (b & 1)  ans *= a; b >>= 1; a *= a; }   return ans; }   ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
inline int lowbit(int x) { return x & (-x); }
#define stop system("pause")
struct node{
    ll a;
    ll b;
    ll c;
    ll d;
    ll sum;
}p[105];
int main(){
    ll n=read();
    for(int i=1;i<=n;i++){
        cin>>p[i].a>>p[i].b>>p[i].c>>p[i].d;
        p[i].sum=p[i].b+p[i].c*2+p[i].d*3;
    }
    ll ans=0,j=1;
    for(int i=1;i<=n;i++){
        if(ans<p[i].sum){
            ans=p[i].sum;
            j=i;
        }
        else if(ans==p[i].sum){
            if(j<i) j=i;
        }
    }
    cout<<j<<" "<<ans<<endl;
}

A Number Theoretical Problem

题目链接

City Supplies

题目链接

题目大意:n个城市,被一共m条路链接起来,连接相邻的两个城市之间的道路的距离都看作1个单位,城市之间的运输成本为2^k(k为道路长度)。每次都是从城市1开始运输到各个城市,要你求出总的运输成本。

算法思想:
这一题主要是要算出来1城市到各个城市的距离,其实就是一个bfs,再用一个数组来保存1城市到各个城市的距离,不过要注意结果取mod。
代码如下:

#include <iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<cstdio>
#include<vector>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
#define pb push_back
#define pll pair<ll,ll>
#define INF 0x3f3f3f3f
const int mod = 1e9+7;
const int maxn = 1e6+7;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long ll;
inline ll read() { ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); }    while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return s * w; }
inline void write(ll x) { if (!x) { putchar('0'); return; } char F[200]; ll tmp = x > 0 ? x : -x; if (x < 0)putchar('-'); int cnt = 0;    while (tmp > 0) { F[cnt++] = tmp % 10 + '0';     tmp /= 10; }    while (cnt > 0)putchar(F[--cnt]); }
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1;   while (b) { if (b & 1)  ans *= a; b >>= 1; a *= a; }   return ans; }   ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
inline int lowbit(int x) { return x & (-x); }
#define stop system("pause")
vector<int>edge[maxn];
ll s[maxn];
void bfs(){
   queue<int>f;
    f.push(1);
    while(!f.empty()){
        int cnt=f.front();
        f.pop();
        for(int i=0;i<edge[cnt].size();++i){
            int x=edge[cnt][i];
            if(s[x]==0){//未遍历
              s[x]=s[cnt]+1;//道路长度
              f.push(x);
            }
        }
    }
}
int main(){
    ll n=read(),m=read();
    for(int i=1;i<=m;i++){
       int  u=read(),v=read();
        edge[u].pb(v);
        edge[v].pb(u);
    }
    bfs();
    ll ans=0;
    for(int i=2;i<=n;i++){
        ans=(ans%mod+qpow(2,s[i],mod)%mod)%mod;
    }
    cout<<ans<<endl;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务