Codeforces Round #697 (Div. 3)
A.Odd Divisor
题意:问一个数是不是含有奇数因子
思路:就直接给这个数循环除以2,看看最后剩下的数是不是0,如果不是就有奇数因子,如果是就没有
想不到:1)当时想着用log2来解决问题,后来发现好像这种想法有点偏
代码:


1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<queue>
7 using namespace std;
8 const long long int maxx=2e5+10;
9 int a[maxx];
10 long long int b[maxx];
11 int main(){
12 long long int t;
13 scanf("%lld",&t);
14 while(t--){
15 __int64 n;
16 scanf("%I64d",&n);
17 if(n==1){
18 printf("NO\n");
19 }else{
20 while(n%2==0){
21 n/=2;
22 }
23 if(n>1){
24 printf("YES\n");
25 }else{
26 printf("NO\n");
27 }
28 }
29 }
30 }
B. New Year's Number
题意:问某个数是不是可以由2020和2021构成
思路:直接进行while循环,先进行一个一个的除2021,直到2021褚不开,看看每一次是不是能够%2020魏0,如果出现一次就是可以用他们构成
想错:1)当时第一次想的时候就是简单的进行先除2021再看看余数是不是2020,其实这样就定下了2020只能有一个,这样的思路就是不对的,可能往往最简单的办法,最笨的方法最有效
代码:


1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<queue>
7 using namespace std;
8 const long long int maxx=2e5+10;
9 int a[maxx];
10 long long int b[maxx];
11 int main(){
12 long long int t;
13 scanf("%lld",&t);
14 while(t--){
15 int n;
16 scanf("%d",&n);
17 int flag=0;
18 while(n>=2020){
19 if(n%2020==0){
20 flag=1;
21 break;
22 }
23 n-=2021;
24 }
25 if(flag==1||n==0){
26 printf("YES\n");
27 }else{
28 printf("NO\n");
29 }
30 }
31 }
C. Ball in Berland
题意:就是有a个女生,b个男生,然后构成的小组有k个,从中选取任意两组,问能组成多少组,注意着两组中必须是不同的四个人
思路:定一动一,从头开始先固定一组,然后用总人数减去女生a组成的组数再减男生b组成的组数+1,这样就是第二组的选取
想错:1)当时想用组合数学,发现第四个样例因为需要n*(n-1)可能是太大了,出现了数位不对的状况;2)遍历这几组人的时候,一开始没想对到底是怎么遍历,第一次用了人的编号去遍历出现了错误,应该是从边遍历,才能保证第一组就是对的,这样才会省掉时间和空间
代码:


1 #include<iostream>
2 #include<algorithm>
3 #include<cstdio>
4 #include<cstring>
5 #include<cmath>
6 #include<queue>
7 using namespace std;
8 const long long int maxx=2e5+10;
9 long long int aa[maxx];
10 long long int bb[maxx];
11 //long long int s[maxx][maxx];
12 int main(){
13 long long int t;
14 scanf("%lld",&t);
15 while(t--){
16 long long int ap,bp,k;
17 scanf("%lld %lld %lld",&ap,&bp,&k);
18 long long int a[maxx]={0};
19 long long int b[maxx]={0};
20 for(int i=0;i<k;i++){
21 scanf("%lld",&aa[i]);
22 a[aa[i]]++;
23 }
24
25 for(int i=0;i<k;i++){
26 scanf("%lld",&bb[i]);
27 b[bb[i]]++;
28 }
29 long long int sum=(k-1)*k/2;//
30 for(int i=1;i<=ap;i++){
31 if(a[i]>1){
32 sum-=(a[i]-1)*a[i]/2;
33 }
34 }
35 for(int i=1;i<=bp;i++){
36 if(b[i]>1){
37 sum-=(b[i]-1)*b[i]/2;
38 }
39 }
40 printf("%lld\n",sum);
41 for(int i=0;i<k;i++){
42 aa[i]=0;
43 bb[i]=0;
44 }
45 }
46 }
Codeforces Round #697 (Div. 3)的更多相关文章
- Codeforces Round #697 (Div. 3) G. Strange Beauty (DP,数学)
题意:给你一组数,问你最少删去多少数,使得剩下的数,每个数都能整除数组中其它某个数或被数组中其它某个数整除. 题解:我们直接枚举所有因子,\(dp[i]\)表示\(i\)在数组中所含的最大因子数(当我 ...
- Codeforces Round #697 (Div. 3) F. Unusual Matrix (思维,数学)
题意:给你一个矩阵\(a\)和\(b\),你可以对\(a\)的任意一行或任意一列的所有元素xor\(1\)任意次,问最终是否能够得到\(b\). 题解:由\(a\ xor\ b=c\),可得:\(a\ ...
- Codeforces Round #697 (Div. 3) D. Cleaning the Phone (思维,前缀和)
题意:你的手机有\(n\)个app,每个app的大小为\(a_i\),现在你的手机空间快满了,你需要删掉总共至少\(m\)体积的app,每个app在你心中的珍惜值是\(b_i\),\(b_i\)的取值 ...
- 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 ...
随机推荐
- Mardown语法
1.什么是Markdown Mardown是一种文本标记语言,使用它,能让我们更加专注于内容的输出,而不是排版样式. 我们平常使用的.txt文档书写的文字是没有样式的,使用Markdown语法就可以给 ...
- python-for表达式
for表达式用于其他区间,元组,列表等可迭代对象创建新的列表 [表达式 for 循环计数器 in 可迭代对象] for表达式与普通for循环的区别有两点 在for关键字之前定义一个表达式,该表达式通常 ...
- 【java框架】SpringBoot(5)--SpringBoot整合分布式Dubbo+Zookeeper
1.理论概述 1.1.分布式 分布式系统是若干独立计算机的集合,这些计算机对于用户来讲就像单个系统. 由多个系统集成成一个整体,提供多个功能,组合成一个板块,用户在使用上看起来是一个服务.(比如淘宝网 ...
- 软件漏洞--Hello-Shellcode
软件漏洞--Hello-Shellcode 使用上一次的栈溢出的漏洞软件 可以直接通过栈溢出来修改返回值,或者要跳转的函数地址 实现一个ShellCode来跳转自己的代码 源bug软件代码 #defi ...
- toastr通知插件的使用
/显示一个警告,没有标题 toastr.warning('My name is Inigo Montoya. You killed my father, prepare to die!') 显示一个成 ...
- 热更新基础--AssetBundle学习笔记
一.简介 AssetBundle简称AB包,特定平台的资产压缩包(包括模型.贴图.预设体.音效.材质球等资产). 作用:Resources下的资源只读且打包后不可修改,而AB包存储位置自定,后期可以动 ...
- [Kong 与 Konga 与 Postgres数据库] 之 Kuberneres 部署
1.Kong的概述 Kong是一个clould-native.快速的.可扩展的.分布式的微服务抽象层(也称为API网关.API中间件或在某些情况下称为服务网格)框架.Kong作为开源项目在2015年推 ...
- Go + gRPC-Gateway(V2) 构建微服务实战系列,小程序登录鉴权服务:第一篇(内附开发 demo)
简介 小程序可以通过微信官方提供的登录能力方便地获取微信提供的用户身份标识,快速建立小程序内的用户体系. 系列 云原生 API 网关,gRPC-Gateway V2 初探 业务流程 官方开发接入文档 ...
- Vulkan移植GpuImage(三)从A到C的滤镜
前面移植了几个比较复杂的效果后,算是确认了复杂滤镜不会对框架造成比较大的改动,开始从头移植,现已把A到C的所有滤镜用vulkan的ComputeShader实现了,讲一些其中实现的过程. Averag ...
- Spring Cloud Gateway 扩展支持动态限流
之前分享过 一篇 <Spring Cloud Gateway 原生的接口限流该怎么玩>, 核心是依赖Spring Cloud Gateway 默认提供的限流过滤器来实现 原生Request ...