zoukankan      html  css  js  c++  java
  • Codeforces Round #538 (Div. 2)

    Codeforces Round #538 (Div. 2)

    http://codeforces.com/contest/1114

    A

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define maxn 500005
     7 typedef long long ll;
     8 /*#ifndef ONLINE_JUDGE
     9         freopen("1.txt","r",stdin);
    10 #endif */
    11 
    12 int n,m;
    13 
    14 
    15 int main(){
    16     #ifndef ONLINE_JUDGE
    17       //  freopen("1.txt","r",stdin);
    18     #endif
    19     //std::ios::sync_with_stdio(false);
    20     int a,b,c,x,y,z;
    21     cin>>a>>b>>c>>x>>y>>z;
    22     if(x>=a){
    23         x-=a;
    24         if(x+y>=b){
    25             if(x+y+z>=b+c){
    26                 cout<<"YES"<<endl;
    27                 return 0;
    28             }
    29         }
    30     }
    31     cout<<"NO"<<endl;
    32 }
    View Code

    B

    sort找出m*k个大的数,记录下标即可

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define maxn 500005
     7 typedef long long ll;
     8 /*#ifndef ONLINE_JUDGE
     9         freopen("1.txt","r",stdin);
    10 #endif */
    11 
    12 ll n,m,k;///m 为头m个,k 为k个区域
    13 
    14 ll a[200005];
    15 struct sair{
    16     ll v;
    17     int pos;
    18 }b[200005];
    19 
    20 int book[200005];
    21 
    22 bool cmp(sair a,sair b){
    23     if(a.v==b.v) return a.pos>b.pos;
    24     return a.v>b.v;
    25 }
    26 
    27 int main(){
    28     #ifndef ONLINE_JUDGE
    29         freopen("1.txt","r",stdin);
    30     #endif
    31     //std::ios::sync_with_stdio(false);
    32     cin>>n>>m>>k;
    33     for(int i=1;i<=n;i++) {
    34         cin>>a[i];
    35         b[i].v=a[i];
    36         b[i].pos=i;
    37     }
    38     sort(b+1,b+n+1,cmp);
    39     m=m*k;
    40     for(int i=1;i<=n&&i<=m;i++){
    41     //    cout<<b[i].v<<endl;
    42         book[b[i].pos]=1;
    43        // cout<<b[i].pos<<endl;
    44     }
    45     ll ans=0;
    46     vector<int>ve;
    47     int co=0;
    48     m=m/k;
    49     for(int i=1;i<=n;i++){
    50         if(book[i]==1){
    51             co++;
    52             if(co==m){
    53                 ve.push_back(i);
    54                 co=0;
    55             }
    56             ans+=a[i];
    57         }
    58     }
    59     cout<<ans<<endl;
    60     for(int i=0;i<ve.size()-1;i++){
    61         cout<<ve[i]<<" ";
    62     }
    63     cout<<endl;
    64 }
    View Code

    C

    如果是素数就直接用,是合数的话就需要拆分因子,然后再进行判断

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define maxn 500005
     7 typedef long long ll;
     8 /*#ifndef ONLINE_JUDGE
     9         freopen("1.txt","r",stdin);
    10 #endif */
    11 
    12 ll n,b;
    13 
    14 bool Check(ll sq){
    15     for(ll i=2;i<=sq;i++){
    16         if(b%i==0) return false;
    17     }
    18     return true;
    19 }
    20 
    21 ll ss(ll zhi){
    22     ll tmp=n;
    23     ll ans=0;
    24     while(tmp){
    25         ans+=tmp/zhi;
    26         tmp/=zhi;
    27     }
    28     return ans;
    29 }
    30 
    31 int main(){
    32     #ifndef ONLINE_JUDGE
    33     //    freopen("1.txt","r",stdin);
    34     #endif
    35     //std::ios::sync_with_stdio(false);
    36     cin>>n>>b;
    37     ll sq=(ll)sqrt(b*1.0);
    38     ll ans=0;
    39     if(Check(sq)){
    40         while(n){
    41             ans+=n/b;
    42             n/=b;
    43         }
    44     }
    45     else{
    46         ll tmp=b;
    47         map<ll,ll>mp;
    48         ll i;
    49         ans=0x3f3f3f3f3f3f3f3f;
    50         while(tmp!=1){
    51             for(i=2;i<=sq;i++){
    52                 if(tmp%i==0){
    53                     tmp/=i;
    54                     mp[i]++;
    55                     break;
    56                 }
    57             }
    58             if(i==sq+1){
    59                 mp[tmp]++;
    60                 tmp/=tmp;
    61 
    62             }
    63         }
    64         map<ll,ll>::iterator it;
    65         ll num=0,zhi;
    66         for(it=mp.begin();it!=mp.end();it++){
    67             ans=min(ans,ss(it->first)/it->second);
    68         }
    69       /*  while(n){
    70             ans+=n/zhi;
    71             n/=zhi;
    72         }
    73         ans/=num;*/
    74     }
    75     cout<<ans<<endl;
    76 }
    View Code

    D

    好像很多人都是写区间DP,我不会区间DP,直接搜索。。。。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define maxn 1000005
     8 typedef long long ll;
     9 typedef unsigned long long ull;
    10 const ull MOD=257;
    11 /*#ifndef ONLINE_JUDGE
    12         freopen("1.txt","r",stdin);
    13 #endif */
    14 
    15 int n;
    16 vector<int>ve;
    17 int dp[5005][5005];
    18 int dfs(int l,int r){
    19     if(dp[l][r]!=-1) return dp[l][r];
    20     int ans=0x3f3f3f3f;
    21     if(l>=r) return 0;
    22     if(ve[l]==ve[r]) {
    23         ans=dfs(l+1,r-1)+1;
    24     }
    25     else{
    26         int ans1=dfs(l+1,r);
    27         int ans2=dfs(l,r-1);
    28         ans=min(ans1,ans2)+1;
    29     }
    30     return dp[l][r]=ans;
    31 }
    32 
    33 int main(){
    34     #ifndef ONLINE_JUDGE
    35       //  freopen("1.txt","r",stdin);
    36     #endif
    37     std::ios::sync_with_stdio(false);
    38     cin>>n;
    39     int a;
    40     for(int i=1;i<=n;i++) {
    41         cin>>a;
    42         ve.pb(a);
    43     }
    44     ve.erase(unique(ve.begin(),ve.end()),ve.end());
    45     int Size=ve.size();
    46     memset(dp,-1,sizeof(dp));
    47     cout<<dfs(0,Size-1)<<endl;;
    48 }
    View Code

    E

    交互题,因为可以询问60次,且最大值不超过2^32,所以可以二分找到最大值,然后在用gcd找公差

    新知识点:mt19937_64

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 #define lson l,mid,rt<<1
     4 #define rson mid+1,r,rt<<1|1
     5 #define sqr(x) ((x)*(x))
     6 #define pb push_back
     7 #define maxn 1000005
     8 typedef long long ll;
     9 typedef unsigned long long ull;
    10 const ull MOD=257;
    11 /*#ifndef ONLINE_JUDGE
    12         freopen("1.txt","r",stdin);
    13 #endif */
    14 
    15 mt19937_64 mt(time(0));
    16 int ans;
    17 
    18 void query(char ch,int x){
    19     cout<<ch<<" "<<x<<endl;
    20     cin>>ans;
    21 }
    22 
    23 int main(){
    24     #ifndef ONLINE_JUDGE
    25       //  freopen("1.txt","r",stdin);
    26     #endif
    27     std::ios::sync_with_stdio(false);
    28     int n;
    29     cin>>n;
    30     int l=0,r=1e9,mid;
    31     while(l<=r){
    32         mid=l+r>>1;
    33         query('>',mid);
    34         if(ans) l=mid+1;
    35         else r=mid-1;
    36     }
    37     int gcd=0;
    38     for(int i=1;i<=30;i++){
    39         int pos=mt()%n+1;
    40         query('?',pos);
    41         gcd=__gcd(gcd,l-ans);
    42     }
    43     cout<<"! "<<l-(n-1)*gcd<<" "<<gcd<<endl;
    44 }
    View Code

    F

    题目大意:给一个长度为 n 的序列 aq个操作:区间乘 x,求区间乘积的欧拉函数模 1e9+7的值

    打表发现300以内的素数只有62个,可以用状压的方法维护

    做法是维护区间积。而欧拉函数,就是看看区间中包含什么质因子,然后除一下乘一下好了

      1 #include<bits/stdc++.h>
      2 using namespace std;
      3 typedef long long ll;
      4 const int maxn=400005,mod=1e9+7;
      5 #define lson o<<1,l,mid
      6 #define rson o<<1|1,mid+1,r
      7 
      8 int n,q,pri[66],pl,a[maxn],inv[333],f[66],tag1[maxn*4];
      9 ll tag2[maxn*4];
     10 bool vis[333];
     11 void init(){
     12     for(int i=2;i<=300;i++){
     13         if(!vis[i]) pri[++pl]=i;
     14         for(int j=1;j<=pl && i*pri[j]<=300;j++){
     15             vis[i*pri[j]]=true;
     16             if(i%pri[j]==0) break;
     17         }
     18     }
     19     inv[1]=1;
     20     for(int i=2;i<=300;i++)inv[i]=mod-1ll*(mod/i)*inv[mod%i]%mod;
     21     for(int i=1;i<=pl;i++)f[i]=1ll*inv[pri[i]]*(pri[i]-1)%mod;
     22 }
     23 inline int qpow(int a,int b){
     24     int ans=1;
     25     for(;b;b>>=1,a=1ll*a*a%mod) if(b&1) ans=1ll*ans*a%mod;
     26     return ans;
     27 }
     28 struct node{
     29     int pro;ll has;
     30 }nd[maxn*4];
     31 void pushup(node &o,node l,node r){
     32     o.has=l.has|r.has;
     33     o.pro=1ll*l.pro*r.pro%mod;
     34 }
     35 void setmult(int o,int l,int r,int x,ll y){
     36     tag1[o]=1ll*tag1[o]*x%mod;
     37     tag2[o]|=y;
     38     nd[o].pro=1ll*nd[o].pro*qpow(x,r-l+1)%mod;
     39     nd[o].has|=y;
     40 }
     41 void pushdown(int o,int l,int r){
     42     if(!tag2[o]) return;
     43     int mid=(l+r)>>1;
     44     setmult(lson,tag1[o],tag2[o]);
     45     setmult(rson,tag1[o],tag2[o]);
     46     tag1[o]=1;tag2[o]=0;
     47 }
     48 void build(int o,int l,int r){
     49     tag1[o]=1;tag2[o]=0;
     50     if(l==r){
     51         nd[o].pro=a[l];
     52         for(int i=1;i<=pl;i++)
     53             if(a[l]%pri[i]==0) nd[o].has|=1ll<<(i-1);
     54         return;
     55     }
     56     int mid=(l+r)>>1;
     57     build(lson);build(rson);
     58     pushup(nd[o],nd[o<<1],nd[o<<1|1]);
     59 }
     60 void mult(int o,int l,int r,int ql,int qr,int x,ll y){
     61     if(l>=ql && r<=qr){
     62         setmult(o,l,r,x,y);
     63         return;
     64     }
     65     pushdown(o,l,r);
     66     int mid=(l+r)>>1;
     67     if(mid>=ql) mult(lson,ql,qr,x,y);
     68     if(mid<qr) mult(rson,ql,qr,x,y);
     69     pushup(nd[o],nd[o<<1],nd[o<<1|1]);
     70 }
     71 node query(int o,int l,int r,int ql,int qr){
     72     if(l>=ql && r<=qr) return nd[o];
     73     pushdown(o,l,r);
     74     int mid=(l+r)>>1;
     75     if(mid<ql) return query(rson,ql,qr);
     76     if(mid>=qr) return query(lson,ql,qr);
     77     node ans;
     78     pushup(ans,query(lson,ql,qr),query(rson,ql,qr));
     79     return ans;
     80 }
     81 int main(){
     82     init();
     83     scanf("%d %d",&n,&q);
     84     for(int i=1;i<=n;i++) scanf("%d",&a[i]);
     85     build(1,1,n);
     86     getchar();
     87     for(int i=1;i<=q;i++){
     88         char op[11];
     89         int l,r;
     90         scanf("%s %d %d%*c",op,&l,&r);
     91         if(op[0]=='M'){
     92             int x;ll y=0;
     93             scanf("%d%*c",&x);
     94             for(int i=1;i<=pl;i++) if(x%pri[i]==0) y|=1ll<<(i-1);
     95             mult(1,1,n,l,r,x,y);
     96         }
     97         else{
     98             node ans=query(1,1,n,l,r);
     99             int s=ans.pro;
    100             for(int i=1;i<=pl;i++) if(ans.has&(1ll<<(i-1))) s=1ll*s*f[i]%mod;
    101             printf("%d
    ",s);
    102         }
    103     }
    104 }
    View Code
  • 相关阅读:
    【卡西欧Fx-5800p系列教程】Pol()和Rec()正反算妙用
    《关于2013年全国测量人员最低工资标准的通知》
    易语言测量编程工具教程篇
    价值300元的《测量宝典》
    业界常用的和不常用cad快捷键
    角度格式批量转化弧度—易语言
    Web.config中 mode="RemoteOnly" 跟mode="On" 区别
    Oracle 批量修改某个用户下表的表空间
    JQuery radio单选框应用
    RadioButtonFor控件
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10372168.html
Copyright © 2011-2022 走看看