zoukankan      html  css  js  c++  java
  • AtCoder Beginner Contest 150

    AB没啥好说的

    C - Count Order / 


    Time Limit: 2 sec / Memory Limit: 1024 MB

    Score : 300300 points

    Problem Statement

    We have two permutations PP and QQ of size NN (that is, PP and QQ are both rearrangements of (1, 2, ..., N)(1, 2, ..., N)).

    There are N!N! possible permutations of size NN. Among them, let PP and QQ be the aa-th and bb-th lexicographically smallest permutations, respectively. Find |ab||a−b|.

    Notes

    For two sequences XX and YYXX is said to be lexicographically smaller than YY if and only if there exists an integer kk such that Xi=Yi (1i<k)Xi=Yi (1≤i<k) and Xk<YkXk<Yk.

    Constraints

    • 2N82≤N≤8
    • PP and QQ are permutations of size NN.

    Input

    Input is given from Standard Input in the following format:

    NN
    P1P1 P2P2 ...... PNPN
    Q1Q1 Q2Q2 ...... QNQN
    

    Output

    Print |ab||a−b|.

    用康托展开,这里数据很小也可以直接STL跑next_permutation。。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define LL long long
     4 
     5 int jc[10]={1};
     6 int a[10],b[10],n;
     7 int cal(int a[],int n){
     8     int res=0;
     9     for(int i=1;i<=n;++i){
    10         int c=0;
    11         for(int j=i+1;j<=n;++j)c+=(a[j]<a[i]);
    12         res+=c*jc[n-i];
    13     }return res;
    14 }
    15 int main(){
    16     for(int i=1;i<=9;++i)jc[i]=i*jc[i-1];
    17     cin>>n;
    18     for(int i=1;i<=n;++i)cin>>a[i];
    19     for(int i=1;i<=n;++i)cin>>b[i];
    20     cout<<abs(cal(b,n)-cal(a,n))<<endl;
    21     return 0;
    22 }

    D - Semi Common Multiple / 


    Time Limit: 2 sec / Memory Limit: 1024 MB

    Score : 400 points

    Problem Statement

    Given are a sequence A=a1,a2,......aNA=a1,a2,......aN of NN positive even numbers, and an integer MM.

    Let a semi-common multiple of AA be a positive integer XX that satisfies the following condition for every kk (1kN)(1≤k≤N):

    • There exists a non-negative integer pp such that X=ak×(p+0.5)X=ak×(p+0.5).

    Find the number of semi-common multiples of AA among the integers between 11 and MM (inclusive).

    Constraints

    • 1N1051≤N≤105
    • 1M1091≤M≤109
    • 2ai1092≤ai≤109
    • aiai is an even number.
    • All values in input are integers.

    Input

    Input is given from Standard Input in the following format:

    NN MM
    a1a1 a2a2 ...... aNaN
    

    Output

    Print the number of semi-common multiples of AA among the integers between 11 and MM (inclusive).

    X=ai*(p+0.5)可以看作是X=ai/2*(2p+1),令bi=ai/2的话,那么显然X满足X%bi==0且X/bi是个奇数。

    令g=lcm(b1,b2...bn)的话,满足条件的数只可能是k*g,假设g不满足题意那么k*g也不会满足题意(g不满足,即存在一个b使得g/b是偶数,那显然k*g/b也是偶数,也不符合)。

    假设g满足题意那么只有在k为奇数得情况下k*g满足题意,这时候统计下小于等于M且满足上述条件的数即可。

    还要注意求lcm得过程可能会爆LL,为此只要当前的lcm>M那么答案显然就是零了,特判下。

    这种数学规律题神烦,代码很丑= =

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define LL long long
     4 
     5 LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);}
     6 LL lcm(LL a,LL b){return a/gcd(a,b)*b;}
     7 LL N,M,a[100010];
     8 int main(){
     9     cin>>N>>M;
    10     LL g=1,ok=1;
    11     for(int i=1;i<=N;++i){
    12         cin>>a[i];
    13         a[i]/=2;
    14         if(i==1)g=a[i];
    15         g=lcm(g,a[i]);
    16         if(g>M)ok=0;
    17     }
    18     for(int i=1;i<=N;++i){
    19         if(g/a[i]%2==0){ok=0;break;}
    20     }
    21     if(!ok){
    22         cout<<0<<endl;
    23         return 0;
    24     }
    25     LL ans=0;
    26     LL b=M/g;
    27     ans=b/2;
    28     if(b&1)ans++;
    29     cout<<ans<<endl;
    30     return 0;
    31 }
  • 相关阅读:
    【python cookbook】【数据结构与算法】12.找出序列中出现次数最多的元素
    [转]ASP.NET MVC 5
    [转]ASP.NET MVC 5 学习教程:快速入门
    Using XSLT and Open XML to Create a Word 2007 Document
    如何在VS2010中更好的编写JavaScript代码
    [转]这五种方法前四种方法只支持IE浏览器,最后一个方法支持当前主流的浏览器(火狐,IE,Chrome,Opera,Safari)
    [转]C# 超高速高性能写日志 代码开源
    windows 2003 发布遇到问题---分析器错误消息: 未能加载类型“YWPT.MvcApplication”。
    将Oracle数据库转换为SQL Server
    SQLServer2008导出表数据为SQL脚本
  • 原文地址:https://www.cnblogs.com/zzqc/p/12178278.html
Copyright © 2011-2022 走看看