Codeforces Round #641 (Div. 2)
只写了A~D
题意:f(n)就是n的第二小因数,问执行k次 n=f(n)+n 后的结果。
题解:如果一直找第二小的因子的话,1e9肯定得t。看下边样例解释就会惊奇的发现,执行次数多了,n一定会变成2的倍数,然后就可以剪枝了。如果n不是2的倍数,那么就执行 n=f(n)+n,k-- 直到n是2的倍数(当然k得>0),最后再加上k*2。
1 #include<bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4
5 int main()
6 {
7 ios::sync_with_stdio(false);
8 cin.tie(0);
9 cout.tie(0);
10 int t;
11 cin>>t;
12 while(t--){
13 ll n,k;
14 cin>>n>>k;
15 while(k){
16 if(n%2==0) break;
17 for(ll i=2;i<=n;i++){
18 if(n%i==0){
19 n+=i;
20 break;
21 }
22 }
23 k--;
24 }
25 n=n+k*2;
26 cout<<n<<endl;
27 }
28 return 0;
29 }
题意:让你找出一个序列使得他在原序列满足一下条件 i%j==0&&a[i]>a[j]; 问最长的序列长度
题解:找1~n每个数当因子时最长的符合条件的序列。
1 #include<bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4
5 ll a[100100];
6 ll dp[100100];
7
8 int main()
9 {
10 ios::sync_with_stdio(false);
11 cin.tie(0);
12 cout.tie(0);
13 ll t;
14 cin>>t;
15 while(t--){
16 ll n;
17 cin>>n;
18 for(ll i=1;i<=n;i++) cin>>a[i];
19 ll ans=0 ;
20 for (ll i=n;i>=1;i--){
21 dp[i]=1;
22 for (ll j=i;j<=n;j+=i){
23 if(a[j]>a[i])
24 dp[i]=max(dp[i],dp[j]+1);
25 }
26 ans = max(dp[i],ans);
27 }
28 cout<<ans<<endl;
29 }
30 return 0;
31 }
题意:求这个序列所有数两两之间的 lcm 的 gcd。
题解:和a1 lcm 后的所有数的 gcd 就是lcm(a1,gcd(a2,a3, ......)),a2就是lcm(a2,gcd(a3,a4, ......)).....,然后再把这些数就行gcd
证明结论:
gcd( lcm (a,b), lcm(a,c) )
= gcd( a*b/gcd(a,b), a*c/gcd(a,c) )
= a*gcd( b/gcd(a,b), c/gcd(a,c) );
lcm( a, gcd(b, c) )=a*gcd(b, c) / gcd(a,gcd(b, c));
最大公约数的百度百科的性质那一栏也能找到这个结论。
1 #include<bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4
5 ll a[100100];
6 ll p[200100];
7
8 int main()
9 {
10 ios::sync_with_stdio(false);
11 cin.tie(0);
12 cout.tie(0);
13 ll n;
14 cin>>n;
15 for(ll i=1;i<=n;i++) cin>>a[i];
16 ll ans;
17 p[n]=a[n];
18 for(ll i=n-1;i>0;i--){
19 p[i]=__gcd(p[i+1],a[i]);
20 }
21 ans=a[1]*p[2]/__gcd(a[1],p[2]);
22 for(ll i=2;i<=n;i++){
23 ans=__gcd(ans,p[i+1]*a[i]/__gcd(a[i],p[i+1]));
24 }
25 cout<<ans<<endl;
26 return 0;
27 }
题意:数组里一段数可以都变成他的中位数,问整个序列能不能变成k。
题解:
①判断一下序列里是否有k这个数,没有的话就直接输出no;
②如果整个序列 >=k 的个数比 <k 的个数多,就输出yes;
③判断一下序列里是否有一段长度>2的连续子序列使得 >=k 的个数比 <k 的个数多,有的话就输出yes,没有就输出no;(代码略丑)
1 #include<bits/stdc++.h>
2 #define ll long long
3 using namespace std;
4
5 int a[100100];
6 int p[100100];
7
8 int main()
9 {
10 ios::sync_with_stdio(false);
11 cin.tie(0);
12 cout.tie(0);
13 int t;
14 cin>>t;
15 while(t--){
16 int n,k;
17 cin>>n>>k;
18 for(int i=1;i<=n;i++) cin>>a[i],p[i]=0;
19 int flag=0;
20 for(int i=1;i<=n;i++){
21 if(a[i]==k) flag=1;
22 if(a[i]>=k) p[i]=1;
23 else p[i]=-1;
24 }
25 if(!flag) {cout<<"no"<<endl;continue;}
26 flag=0;
27 for(int i=1;i<=n;i++){
28 p[i]+=p[i-1];
29 }
30 if(p[n]>0) flag=1;
31 int minn=p[0];
32 for(int i=2;i<=n;i++){
33 if(p[i]>minn){
34 flag=1;
35 break;
36 }
37 if(p[i-1]<minn){
38 minn=p[i-1];
39 }
40 }
41 if(!flag) {cout<<"no"<<endl;continue;}
42 cout<<"yes"<<endl;
43 }
44 return 0;
45 }
Codeforces Round #641 (Div. 2)的更多相关文章
- Codeforces Round #641 (Div. 2) D. Orac and Medians (贪心)
题意:有一个长度为\(n\)的数组,问能否通过多次使某个区间的所有元素变成这个区间的中位数,来使整个数组变成题目所给定的\(k\). 题解:首先这个\(k\)一定要在数组中存在,然后我们对中位数进行考 ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- Codeforces Round #262 (Div. 2) 1003
Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...
- Codeforces Round #262 (Div. 2) 1004
Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- uber_go_guide解析(一)
前言 实力有限,guide啃着好费劲 原地址https://github.com/xxjwxc/uber_go_guide_cn 加我自己的体会和补充 基于Golang 1.14 正文 Interfa ...
- Eclipse-Che 安装(Centos)
安装docker,然后执行:docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v /home/cheData:/dat ...
- 树莓派-4WD智能小车操作小结
树莓派-4WD智能小车操作小结 树莓派4B-4WD智能小车,双层结构,第一层结构为:小车扩展板(底层)+树莓派主板,通过铜柱隔离固定,小车扩展板相当于计算机的外设扩展板:上面一层为第二层,是三个舵机承 ...
- HBASE Shell基本命令
定义 HBASE是一种分布式.可扩展.支持海量数据存储的NoSQL数据库. HBASE数据模型 逻辑上,HBASE的数据模型同关系型数据库类似,数据存储到一张表中,有行有列,但是从HBASE的底层物理 ...
- 【Linux】如何查找命令及历史记录history
如何查找命令及历史记录 文章目录 如何查找命令及历史记录 1.如何找到一个命令 2.命令的历史记录 3.一些实用的快捷键 4.小结 5.参考资料 如何找到一个命令.命令的历史记录.一些实用的快捷键.总 ...
- Git软件安装过程
Git程序安装过程 官网: https://git-scm.com/ 下载: https://git-scm.com/downloads 我的操作系统是 Windows + 64位的 https:// ...
- 【Linux】dlopen failed: /lib/lsiRAID.so: cannot open shared object file: No such file or directory
遇到这个问题,首先第一反应,是看其他的服务器中是否有这个库文件,如果有的话直接cp过来一份就行 但是检查发现,其他的系统中也不存在lsiRAID.so这个库文件,很神奇.. 但是看日志持续报错,查看s ...
- 【Oracle】从删除的recyclebin中查看并恢复数据
如果数据库中用了drop删除表,后面没有加上purge的话,会出现在oracle的回收机制中 dba_recyclebin可以查看当前删除的都是哪些 这个只是部分截图,可以看到删除的对象是什么,删除的 ...
- 腾讯云COS对象存储占据数据容灾C位
说到公有云容灾,大家首先想到的是云上数据备份. 然而,随着企业核心业务逐渐从线下迁移到云上,客户提出了更高的要求.如何确保云上业务的高可用.数据的高可靠,这对云厂商提出了新的挑战. 腾讯云作为全球领先 ...
- [Usaco2008 Mar]River Crossing渡河问题
题目描述 Farmer John以及他的N(1 <= N <= 2,500)头奶牛打算过一条河,但他们所有的渡河工具,仅仅是一个木筏. 由于奶牛不会划船,在整个渡河过程中,FJ必须始终在木 ...