2020牛客暑期多校训练营(第七场)

B.Mask Allocation(思维)
现在假设n < m,我们知道我们现在有n * m个口罩,那么分出来的每一组必定不能大于n,因为一共有n * m个口罩,那么m个医院中每一个都是平均拿n个。

那么我们现在贪心一波,先满足这n个医院,每个医院分得n个口罩(为什么这样分?因为他要求字典序最大,所以先把最大分出来),那么现在肯定还有m-n个医院没有满足,所以现在交换一下n和m,n = m - n,m = n,再继续上述操作,根据更相减损术就可以得知:最后的n一定会为0,m一定是gcd(n,m)

AC代码

#include 
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 5e5 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9 + 7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m,sum = 0;
        vector<int> v;
        scanf("%d%d",&n,&m);
        if(n > m) swap(n,m);
        while(n != 0)
        {
            for(int i = 1;i <= n;i++)
                v.push_back(n);
            int a = m - n,b = n;
            n = a,m = b;
            if(n > m) swap(n,m);
        }
        printf("%d\n",v.size());
        for(int i = 0;i < v.size();i++)
            printf("%d ",v[i]);
        printf("\n");
    }
}

D.Fake News(数学)
这个东西…要不打表出来,要不你去证明叭…
证明在这:一位初中生的碾压性证明
打表发现只有1和24可以

#include 
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 5e5 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9 + 7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        n == 1 || n == 24 ? printf("Fake news!\n") : printf("Nobody knows it better than me!\n");
    }
}

H.Dividing(数学)
醉了,已经证出来对答案有贡献的就是(a,b),当a%b == 0 或者a % b == 1就可以了,但是奈何n和k数据太大,不知道怎样处理。

这里要用到除法分块来降低时间复杂度。

AC代码

#include 
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 5e5 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9 + 7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
ll sum,k;
void solve(ll n)
{
    ll l = 2,r;
    while(l <= n && l <= k)
    {
        r = min(n/(n/l),k);
        sum = (sum + (r-l+1)%mod*(n/l)%mod)%mod;
        l = r+1;
    }
}
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    ll n;
    cin >> n >> k;
    solve(n);solve(n-1);
    cout << (sum+k+n-1)%mod << endl;
}

你可能感兴趣的:(牛客)