Codeforces Round #489 (Div. 2)

A. Nastya and an Array
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties:

  • In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero.
  • When all elements of the array become equal to zero, the array explodes.

Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the size of the array.

The second line contains n integers a1, a2, ..., an ( - 105 ≤ ai ≤ 105) — the elements of the array.

Output

Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.

Examples
input
Copy
5
1 1 1 1 1
output
Copy
1
input
Copy
3
2 0 -1
output
Copy
2
input
Copy
4
5 -6 -5 1
output
Copy
4
Note

In the first example you can add  - 1 to all non-zero elements in one second and make them equal to zero.

In the second example you can add  - 2 on the first second, then the array becomes equal to [0, 0,  - 3]. On the second second you can add 3 to the third (the only non-zero) element.

 

 

判断除0外不同数字的个数set即可

#include<bits/stdc++.h>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
using namespace std;
//const int N=; 
typedef long long ll;
int a[1100];
set<int>aa; 
int main(){
    std::ios::sync_with_stdio(false);
    int n,m,tmp;cin>>n;int f=0;
    for(int i=1;i<=n;i++){
        cin>>tmp;aa.insert(tmp);
        if(tmp==0) f=1;
    } 
    cout<<aa.size()-f;
    
    return 0;
} 
View Code
B. Nastya Studies Informatics
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Today on Informatics class Nastya learned about GCD and LCM (see links below). Nastya is very intelligent, so she solved all the tasks momentarily and now suggests you to solve one of them as well.

We define a pair of integers (a, bgood, if GCD(a, b) = x and LCM(a, b) = y, where GCD(a, b) denotes the greatest common divisorof a and b, and LCM(a, b) denotes the least common multiple of a and b.

You are given two integers x and y. You are to find the number of good pairs of integers (a, b) such that l ≤ a, b ≤ r. Note that pairs (a, b)and (b, a) are considered different if a ≠ b.

Input

The only line contains four integers l, r, x, y (1 ≤ l ≤ r ≤ 109, 1 ≤ x ≤ y ≤ 109).

Output

In the only line print the only integer — the answer for the problem.

Examples
input
Copy
1 2 1 2
output
Copy
2
input
Copy
1 12 1 12
output
Copy
4
input
Copy
50 100 3 30
output
Copy
0
Note

In the first example there are two suitable good pairs of integers (a, b): (1, 2) and (2, 1).

In the second example there are four suitable good pairs of integers (a, b): (1, 12), (12, 1), (3, 4) and (4, 3).

In the third example there are good pairs of integers, for example, (3, 30), but none of them fits the condition l ≤ a, b ≤ r.

 

 

因为乘积等于某个值的时候可以用sqrt优化,两个数一定是一个大于sqrt,一个小于sqrt,或者两者均等于sqrt
令 ax,bx 代表 原题的a,b>>>同时需要保证gcd(a,b)==1
则a*x*b*x=x*y>>>>>>a*b=y/x; 根号(y/x)暴力即可,注意>>没搞明白>>为甚麽会有y%x!=0的情况

代码中的一些小地方,比如 for(int a=1;a*a<tmp;a++)  多用乘法转换

#include<bits/stdc++.h>
#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){
    if(b==0) return a;
    else return gcd(b,a%b);
} 
int main(){
    ll l,r,x,y;
    std::ios::sync_with_stdio(false);cin.tie(0); 
    cin>>l>>r>>x>>y;ll tmp=y/x;ll ans=0;
    if(y%x){
        cout<<"0\n";return 0;
    }
    for(ll a=1;a*a<=tmp;a++){
        ll b=tmp/a;
        if(tmp%a!=0) continue;
        if(a*x<l||a*x>r) continue;
        if(b*x<l||b*x>r) continue;
        if(gcd(a,b)==1) {ans+=2;if(a==b) ans--;}
    }
    cout<<ans<<endl;
    return 0;
} 
View Code

 

C. Nastya and a Wardrobe
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month).

Unfortunately, right after the doubling the wardrobe eats one of the dresses (if any) with the 50% probability. It happens every month except the last one in the year.

Nastya owns x dresses now, so she became interested in the expected number of dresses she will have in one year. Nastya lives in Byteland, so the year lasts for k + 1 months.

Nastya is really busy, so she wants you to solve this problem. You are the programmer, after all. Also, you should find the answer modulo 109 + 7, because it is easy to see that it is always integer.

Input

The only line contains two integers x and k (0 ≤ x, k ≤ 1018), where x is the initial number of dresses and k + 1 is the number of months in a year in Byteland.

Output

In the only line print a single integer — the expected number of dresses Nastya will own one year later modulo 109 + 7.

Examples
input
Copy
2 0
output
Copy
4
input
Copy
2 1
output
Copy
7
input
Copy
3 2
output
Copy
21
Note

In the first example a year consists on only one month, so the wardrobe does not eat dresses at all.

In the second example after the first month there are 3 dresses with 50% probability and 4 dresses with 50% probability. Thus, in the end of the year there are 6 dresses with 50% probability and 8 dresses with 50% probability. This way the answer for this test is (6 + 8) / 2 = 7.

 

 

用dp推出等比数列通项公式即可>>>Ak=A1*q^(n-1)>>头脑清晰即可>>注意数据防爆

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll pow_(ll b){
    ll res=1,tmp=2;
    while(b){
        if(b&1) (res*=tmp)%=mod;
        b/=2;
        (tmp*=tmp)%=mod;
    }
    return res;
}
int main(){
    std::ios::sync_with_stdio(false);
    ll x,k;cin>>x>>k;
    if(k==0){
        ll ans=2*x;ans%=mod;
        cout<<ans<<endl;
        return 0;
    }
    if(x==0){
        cout<<"0"<<endl;
        return 0;
    }
    ll ans=pow_(k);
    ll tmp=(2*x-1);tmp%=mod;
    ans*=tmp;ans%=mod;
    ans+=1;ans%=mod;
    cout<<ans<<endl;
    return 0;
}
View Code

 

 

D. Nastya and a Game
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that , where p is the product of all integers on the given array, s is their sum, and k is a given constant for all subsegments.

Nastya wonders how many subsegments of the array fit the described conditions. A subsegment of an array is several consecutive integers of the array.

Input

The first line contains two integers n and k (1 ≤ n ≤ 2·105, 1 ≤ k ≤ 105), where n is the length of the array and k is the constant described above.

The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 108) — the elements of the array.

Output

In the only line print the number of subsegments such that the ratio between the product and the sum on them is equal to k.

Examples
input
Copy
1 1
1
output
Copy
1
input
Copy
4 2
6 3 8 1
output
Copy
2
Note

In the first example the only subsegment is [1]. The sum equals 1, the product equals 1, so it suits us because .

There are two suitable subsegments in the second example — [6, 3] and [3, 8, 1]. Subsegment [6, 3] has sum 9 and product 18, so it suits us because . Subsegment [3, 8, 1] has sum 12 and product 24, so it suits us because .

 

 

 


思维好题>>>怎末说呢>>>这体现了一种做题的方法吧>>>暴力之后再去想优化>>>
注意到正数的乘法最多跳除1外60次>>>暴力即可
>>同时注意乘法是否会溢出>>

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll sum[N],a[N];int nxt[N];
const ll INF=0x3f3f3f3f3f3f3f3f;
int main(){
    std::ios::sync_with_stdio(false);cin.tie(0);
    int n,k;cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
    nxt[n+1]=n+1;
    for(int i=n;i>=1;i--){
        nxt[i]=nxt[i+1];
        if(a[i]>1) nxt[i]=i;
    } 
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll s=a[i],p=a[i];
        if(s*k==p) ans++;
        for(int j=i+1;j<=n;j++){
            if(a[j]!=1){
                if(INF/a[j]<=p) break;
                p*=a[j];s+=a[j];
                if(s*k==p) ans++;
            }
            else{
                int num=nxt[j]-j;
                if(s*k<p&&p%k==0&&(s+num)*k>=p) ans++;
                s+=num;j+=num-1;    
            }
        }    
    } 
    cout<<ans<<endl;
    return 0;
} 
View Code

 

转载于:https://www.cnblogs.com/vainglory/p/9201459.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 内容概要 《计算机试卷1》是一份综合性的计算机基础和应用测试卷,涵盖了计算机硬件、软件、操作系统、网络、多媒体技术等多个领域的知识点。试卷包括单选题和操作应用两大类,单选题部分测试学生对计算机基础知识的掌握,操作应用部分则评估学生对计算机应用软件的实际操作能力。 ### 适用人群 本试卷适用于: - 计算机专业或信息技术相关专业的学生,用于课程学习或考试复习。 - 准备计算机等级考试或职业资格认证的人士,作为实战演练材料。 - 对计算机操作有兴趣的自学者,用于提升个人计算机应用技能。 - 计算机基础教育工作者,作为教学资源或出题参考。 ### 使用场景及目标 1. **学习评估**:作为学校或教育机构对学生计算机基础知识和应用技能的评估工具。 2. **自学测试**:供个人自学者检验自己对计算机知识的掌握程度和操作熟练度。 3. **职业发展**:帮助职场人士通过实际操作练习,提升计算机应用能力,增强工作竞争力。 4. **教学资源**:教师可以用于课堂教学,作为教学内容的补充或学生的课后练习。 5. **竞赛准备**:适合准备计算机相关竞赛的学生,作为强化训练和技能检测的材料。 试卷的目标是通过系统性的题目设计,帮助学生全面复习和巩固计算机基础知识,同时通过实际操作题目,提高学生解决实际问题的能力。通过本试卷的学习与练习,学生将能够更加深入地理解计算机的工作原理,掌握常用软件的使用方法,为未来的学术或职业生涯打下坚实的基础。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值