Codeforces Round #640 (Div. 4)(ABCDEG题解)
文章目录
- A. Sum of Round Numbers
- B - Same Parity Summands
- C - K-th Not Divisible by n
- D - Alice, Bob and Candies
- E - Special Elements
- F. Binary String Reconstruction
- G - Special Permutation
A. Sum of Round Numbers
题解:把他一个整数拆分,模拟一波即可
#pragma GCC optimize(3,"Ofast","inline")#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <math.h>#include <string>#include <list>#include <set>#include <map>#include <queue>#include <stack>#include <algorithm>#include <stdlib.h>#include <vector>#define maxn 200010const int MaxN = 0x3f3f3f3f;const int MinN = 0xc0c0c00c;typedef long long ll;const int mod = 1000007;using namespace std;int a[10];int main(){int t;cin>>t;while(t--){int n;cin>>n;int cnt=0;int ans=1;while(n){if(n%10!=0){a[cnt++]=(n%10)*ans;//cout<<"debug: "<<a[cnt-1]<<endl;}ans*=10;n/=10;}cout<<cnt<<endl;for(int i=0;i<cnt;i++){cout<<a[i]<<" ";}cout<<endl;}return 0;}
B - Same Parity Summands
题解:我们可以先假设全都用奇数表示出来,只需要将前k-1项为1(最小的奇数),在判断最后一项是否为奇数,再假设可以用偶数表示,如果前k-1项都可以用偶数表示2(最小得偶数即可),在判断最后一项是否为奇数
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <math.h>
#include <string>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#define maxn 200010
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const int mod = 1000007;
using namespace std;
int a[10];
int main()
{int t;cin>>t;while(t--){int n,k;cin>>n>>k;if((n-k+1)%2==1&&(n-k+1)>0){printf("YES\n");for(int i=0;i<k-1;i++){printf("1 ");}printf("%d\n",n-k+1);continue;}else if((n-2*(k-1))%2==0&&(n-2*(k-1))>0){printf("YES\n");for(int i=0;i<k-1;i++){printf("2 ");}printf("%d\n",n-2*(k-1));continue;}printf("NO\n");}return 0;
}
C - K-th Not Divisible by n
题解:把n和n的倍数抠出来再找k即可
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <math.h>
#include <string>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#define maxn 200010
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const int mod = 1000007;
using namespace std;
int a[10];
int main()
{int t;cin>>t;while(t--){ll n,k;cin>>n>>k;ll ans=k/(n-1);ll temp=ans*n+k%(n-1);if(k%(n-1)==0) temp--;cout<<temp<<endl;}return 0;
}
D - Alice, Bob and Candies
题解:模拟题
双指针往中间夹,注意处理一下细节即可
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <math.h>
#include <string>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#define maxn 8010
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const int mod = 1000007;
using namespace std;
int a[maxn];int main()
{int t;cin>>t;while(t--){int n;cin>>n;for(int i=1;i<=n;i++) scanf("%d",&a[i]);int l=1,r=n+1;int ans1=0,ans2=0,cnt=1,x=a[1],y=0;bool flag=false;ans1=a[1];while(l+1!=r){if(flag){cnt++,x=0;while(x<=y){if(l+1==r){break;}x+=a[++l];}ans1+=x;flag=false;}else{cnt++,y=0;while(y<=x){if(l+1==r){break;}y+=a[--r];}ans2+=y;flag=true;}}cout<<cnt<<" "<<ans1<<" "<<ans2<<endl;}
}
E - Special Elements
题解:我们可以对于每个数双指针操作
复杂度n2,不过没超时
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <math.h>
#include <string>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#define maxn 8010
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const int mod = 1000007;
using namespace std;
int a[maxn];int main()
{int t;cin>>t;while(t--){int n;cin>>n;for(int i=0;i<n;i++){scanf("%d",&a[i]);}int cnt=0;for(int i=0;i<n;i++){int l=0,r=0;ll ans=a[0];while(r<n){if(a[i]==ans&&l-r!=0){cnt++;break;}else if(a[i]<ans){ans-=a[l];l++;}else{r++;ans+=a[r];}//cout<<l<<" "<<r<<endl;}}printf("%d\n",cnt);}return 0;
}
F. Binary String Reconstruction
时间有限,大一刚入坑菜鸡,没写完
G - Special Permutation
题解:感觉应该会其他做法,这题让我硬生生写出了模拟的味道,感觉是找规律+模拟
首先你可以发现长度为2或者是3的数组是不可以的(直接pass掉)
- 最小长度为4即可,当然4的倍数长度的数组也是可以的
- 然后再看n%4=1的时候,那么n-5一定就是4的倍数,这样前n-5项按照4的倍数进行处理,最后五项自己找一下排序规则
- 然后再看n%4=2的时候,那么n-6一定就是4的倍数,这样前n-6项按照4的倍数进行处理,最后六项自己找一下排序规则
- 然后再看n%4=3的时候,那么n-7一定就是4的倍数,这样前n-7项按照4的倍数进行处理,最后七项自己找一下排序规则
怎么讲其按照自己预定的顺序输出呢?可以设置一个顺序数组即可
#pragma GCC optimize(3,"Ofast","inline")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <math.h>
#include <string>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#define maxn 200010
const int MaxN = 0x3f3f3f3f;
const int MinN = 0xc0c0c00c;
typedef long long ll;
const int mod = 1000007;
using namespace std;
int a[maxn];
int x[10]={2,4,1,3};
int y[10]={1,3,5,2,4};
int z[10]={1,3,5,2,4,6};
int h[10]={1,4,7,3,5,2,6};
int main()
{int t;cin>>t;while(t--){int n;cin>>n;for(int i=1;i<=n;i++) a[i]=i;if(n==2||n==3){printf("-1\n");continue;}if(n%4==0){ //0for(int i=0;i<n;i++){int f=i%4;printf("%d ",a[x[f]+i-f]);}printf("\n");}else if(n%4==1){ //1for(int i=0;i<n-5;i++){int f=i%4;printf("%d ",a[x[f]+i-f]);}for(int i=0;i<5;i++){printf("%d ",a[y[i]+n-5]);}printf("\n");}else if(n%4==2){for(int i=0;i<n-6;i++){int f=i%4;printf("%d ",a[x[f]+i-f]);}for(int i=0;i<6;i++){printf("%d ",a[z[i]+n-6]);}printf("\n");}else if(n%4==3){for(int i=0;i<n-7;i++){int f=i%4;printf("%d ",a[x[f]+i-f]);}for(int i=0;i<7;i++){printf("%d ",a[h[i]+n-7]);}printf("\n");}}return 0;
}
Codeforces Round #640 (Div. 4)(ABCDEG题解)相关推荐
- Codeforces Round #686 (Div. 3) A-F题解
Codeforces Round #686 (Div. 3) A-F题解 A. Special Permutation 题意 给定 nnn ,输出一个长度为 nnn 的全排列,每个位置 iii 上的数 ...
- Codeforces Round #693 (Div. 3)部分题解
Codeforces Round #693 (Div. 3) 部分题解 D. Even-Odd Game 思路: 贪心:田忌赛马 (1)先将数组从大到小排序,取数时从大到小取,用一个ans变量记录取数 ...
- Codeforces Round #702 (Div. 3)A-G题解
Codeforces Round #702 (Div. 3)A-G题解 比赛链接:https://codeforces.ml/contest/1490 这场F读错题意白给一发,G二分的if(dp[mi ...
- codeforces Round #645 (Div. 2)D题解
Codeforces Round #645 (Div. 2)--D题解 作为一名菜鸡,理所当然得没有A出来,这道题数据放小就一水题了,可惜数据这块卡的死死的. 本题最重要的一点就是你要推出来一个结论: ...
- Codeforces Round #670 (Div. 2)A-D题解
Codeforces Round #670 (Div. 2)A-D题解 //写于rating值1987/2184 //补档 比赛链接:https://codeforces.ml/contest/140 ...
- Codeforces Round #674 (Div. 3)A-F题解
Codeforces Round #674 (Div. 3)A-F题解 比赛链接:https://codeforces.com/contest/1426 A题 水题不写题解 #include<b ...
- Codeforces Round #807 (Div. 2) A-C题解
Codeforces Round #807 (Div. 2) A.B.C题题解 A - Mark the Photographer 题意:马克要给2n个人照相,分两排,一排站n人,给出每个人的身高,要 ...
- Codeforces Round #723 (Div. 2) 个人题解
上1400辣! 传送门:https://codeforces.com/contest/1526 A. Mean Inequality 题意 给一个长度为偶数的数组,你需要重排这个数组,使得任意一个数不 ...
- Codeforces Round #710 (Div. 3)个人题解
Codeforces Round #710 (Div. 3) 文章目录 [Codeforces Round #710 (Div. 3)](https://codeforces.com/contest/ ...
- Educational Codeforces Round 112(Div.2) ABC题解
D题好像可以做一做,挖个坑以后做好了来填(doge Educational Codeforces Round 112(Div.2) 题目列表 1.A 2.B 3.C 1.A 原题链接 题目大意 有三种 ...
最新文章
- OpenCV 【十六】RNG随机数发生器putText绘制文字
- SetAutoResizeMode
- asp用于取代什么技术_.NET的未来:关于.NET5,每个.Net开发人员必须知道什么
- JVM内存管理------GC算法精解(五分钟教你终极算法---分代搜集算法)
- 从数据库读写RadioButtonList选中的值
- 大数据之-Hadoop伪分布式_配置历史服务器---大数据之hadoop工作笔记0027
- 机械设计软件编写心得
- 3.3 自定义控件基础 之 View的绘制
- Atitit enhance dev eff read req提升开发效率 可读性规范 目录 1. 提升效率的俩大原则	1 2. 命名规范 见名字知道意思	1 3. 层次结构缩减 单层 vs 双
- 10.3 黑马Vue电商后台管理系统 进一步完善订单模块--修改发货地址
- centos 7下搭建wiki系统
- 到底什么是dp思想(内含大量经典例题,附带详细解析)
- 计算机主机显卡安装,电脑显卡驱动怎么安装
- python loc和iloc_DataFrame的iloc与loc的区别是什么?
- spring启动流程(一):启动流程概览
- 基于深度学习的手写数字实现及超简单的英文字母识别
- starday跨境电商平台发展迅猛,主打高性价比的产品优势来了!
- android第三方播放器--饺子播放器的使用
- 方舟进官方服务器弹网页,进方舟服务器就弹白框
- 软考__第17章 战略管理
热门文章
- selenium之简单使用
- TCP连接管理【三次握手-四次挥手】
- 目标检测 | 盘点目标检测中的特征融合技巧(根据YOLO v4总结)
- 使用OpenCV实现车道线检测
- 利用边缘检测计算物体面积(内含源码)
- 面试 | 22道机器学习常见面试题目
- 第二篇:时间和全局状态(二)
- python基础===Number
- 看看Spring的源码(一)——Bean加载过程
- jdbc报Incorrect string value: '\xF0\x9F\xA4\x97' for column