Codeforces Round #486 (Div. 3) E. Divisibility by 25 题目连接: http://codeforces.com/group/T0ITBvoeEx/contest/988/problem/E Description You are given an integer n from 1 to 10^18 without leading zeroes. In one move you can swap any two adjacent digits in…
Divisibility by 25 time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given an integer nn from 11 to 10181018 without leading zeroes. In one move you can swap any two adjacent digits i…
本题是数论好题! 首先我们需要了解一个关于数论的性质: 一个数只要后两位能被25(或4)整除,这个数就能被25(或4)整除. 同理,后三位:(或8).后四位:(或16)亦是如此. 所以,我们只需要判断n中有没有能被25整除的两位数即可. 注意:由于需要判断有没有能被25整除的两位数,应暴力枚举两个数在n中的位置,因此n最好采用C++中的string类型存储. 这里只给出字符串转数字的代码: int stos(string st)//把字符串转为数字 { ;//最终转换成的数 ;i<st.size…
You are given an integer nn from 11 to 10181018 without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the…
You are given an integer nn from 11 to 10181018 without leading zeroes. In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the…
解题思路: 只有尾数为25,50,75,00的数才可能是25的倍数. 对字符串做4次处理,以25为例. a. 将字符串中的最后一个5移到最后一位.计算交换次数.(如果没有找到5,则不可能凑出25,考虑50.75.00) b. 字符串已经改变,将此时最后一个2移到倒数第二位.计算交换次数. (如果没有找到2,则也不可能凑出25,考虑50.75.00) c. 将除了最后两位之外的第一个非0的数字移到首位,计算交换次数.(如果找不到除了最后两位之外的非0数字,则不可能凑出25,考虑50.75.00)…
传送门 题意:给定一个数,可以对其做交换相邻两个数字的操作.问最少要操作几步,使得可以被25整除. 思路:问题可以转化为,要做几次交换,使得末尾两个数为00或25,50,75: 自己一开始就是先for一遍,记录四种可能对于的步数,再对四种可能讨论(有前导0的情况):自己是在数据中,该对了自己的代码, 看了队长和%王宣凯的代码,觉得那才是现场能ac的思路.--暴力交换: #include <iostream> #include <cstdio> #include <algori…
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789828.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~~ 水,中序遍历输出即可注意除根节点.叶子节点外,都需要有括号括起来 #include <iostream> #include <cstdio> #include <algorithm> #include <string>…
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789819.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~~ 题意:用户每次选择一个indice,输出之前出现的频率最高的k个indice如果恰好有两个频率一样,输出indice较小的那个 显然不能每次都要对当前所有的item排个序,会超时的由于每次只要给出前k个出现频率最高的,如果出现频率一样,则给出值最小的所以只要…
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789229.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~~ 给出一天24小时内,每个小时内,每分钟的通话费用给出n个记录,on-line表示通话的开始,off-line表示通话的结束如果on-line/off-line没有对应的另一个,忽略即可 先按人名排序,名称一样的按时间排序,这里时间统一按分钟来算,即一天有24…
dfs求最大层数并查集求连通个数 #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <string> #include <vector> using namespace std; /* dfs求最大层数 并查集求连通个数 */ +; int n; ; //最大层数 vector<int>deepro…
大数据加法给一个数num和最大迭代数k每次num=num+num的倒序,判断此时的num是否是回文数字,是则输出此时的数字和迭代次数如果k次结束还没找到回文数字,输出此时的数字和k 如果num一开始是回文数字,那么直接输出num和0即可. #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <string> using na…
排序,求整体的排名和局部的排名整体排序,for循环一遍同时存储整体目前的排名和所在局部的排名即可 #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #include <queue> #include <map> using namespace std; ; ; int local_R…
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #include <queue> using namespace std; /* 水排序 */ +; int n,c; struct Stu{ int ID; ]; int grade; }stu[maxn]; bool cmpID(Stu s1…
题目说了那么多,就是给你两个序列,分别选取元素进行一对一相乘,求得到的最大乘积. 将两个序列的正和负数分开,排个序,然后分别将正1和正2前面的相乘,负1和负2前面的相乘,累加和即可. #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #include <vector> using namespa…
给n,m以及n个硬币 问,是否存在两个硬币面值v1+v2=m 因为面值不会超过500,所以实际上最多500个不同的硬币而已 #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> using namespace std; +; int coin[maxn]; int n,m; int main() { scanf("%d %d",&…
将1~n压入最多为m元素的栈 给出k个出栈序列,问你是否能够实现. 能输出YES 否则NO 模拟一遍即可,水题. #include <iostream> #include <cstdio> #include <string.h> #include <algorithm> using namespace std; ; int m,n,k; int seq[maxn]; int stacks[maxn]; ; int main() { int val; scan…
用素数筛选法即可. 范围long int,其实大小范围和int一样,一开始以为是指long long,想这就麻烦了该怎么弄. 而现在其实就是int的范围,那难度档次就不一样了,瞬间变成水题一枚,因为int根号后大小不超过60000. 即因子的大小不会超过60000,除非本身是质数. int 4 -2147438648-+2147438647long int 4 -2147438648-+2141438647 #include <iostream> #include <cstdio>…
题意:两个整数集合,它们的相似度定义为:nc/nt*100%nc为两个集合都有的整数nt为两个集合一共有的整数注意这里的整数都是各不相同的,即重复的不考虑在内.给出n个整数集合,和k个询问,让你输出每个询问中两个集合的相似度. 因为数值范围在[0,10^9],开不了这么大的数组来标记某个数的出现,所以一开始用了map然而最后一个样例超时了因为题目说了不包含重复的元素,所以想到用set来存储set的大小即为集合不相同的整数个数那么寻找a和b集合相同的元素个数,只需要遍历一下a集合的元素,看是否能在…
分割字符串的用法+map映射给出input中出现次数最多的单词,如果次数相同,给出按字典序最小的. 这里我用了自定义分隔符来读取字符串,方法如下: //按照定义的分隔符d来分割字符串,对str进行读取 const char *d = "\n\'\"\? ";//换行,',",?,空格 char *p; p = strtok(str,d); //这样做的主要原因是避免最后输出换行 while(p) { //对p进行处理 p=strtok(NULL,d); //读取下一…
相当于是模拟OJ评测,这里注意最后输出:1.那些所有提交结果都是-1的(即均未通过编译器的),或者从没有一次提交过的用户,不需要输出.2.提交结果为-1的题目,最后输出分数是03.某个题目从没有提交过的,输出'-' #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #include <queue>…
快速排序有一个特点,就是在排序过程中,我们会从序列找一个pivot,它前面的都小于它,它后面的都大于它.题目给你n个数的序列,让你找出适合这个序列的pivot有多少个并且输出来. 大水题,正循环和倒着循环一次,统计出代码中的minnum和maxnum即可,注意最后一定要输出'\n',不然第三个测试会显示PE,格式错误. #include <iostream> #include <cstdio> #include <algorithm> #include <map&…
题意:给定N,以及N个数.找出满足m*n=N且m>=n且m-n最小的m.n值,建立大小为m*n矩阵,将N个数从大到下顺时针填入矩阵中. #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <cmath> #define LEFT 1 #define RIGHT 2 #define UP 3 #define DOWN 4…
题意:n个人,要拍成k行排队,每行 n/k人,多余的都在最后一排. 从第一排到最后一排个子是逐渐增高的,即后一排最低的个子要>=前一排的所有人 每排排列规则如下: 1.中间m/2+1为该排最高: 2.其他人按各自降序顺序,轮流排到中间最高的左边和右边: 举个例子 190 188 186 175 170 — — 190 — — — 188 190 — — — 188 190 186 — 175 188 190 186 — 175 188 190 186 170 3.当个子一样高时,名字按字典序顺序…
题意:给出每个人的家庭成员信息和自己的房产个数与房产总面积,让你统计出每个家庭的人口数.人均房产个数和人均房产面积.第一行输出家庭个数,随后每行输出家庭成员的最小编号.家庭人口数.人均房产个数.人均房产面积. 并查集,合并的时候编号小的作为父亲节点,最后父亲节点一样的即属于一个家庭,其它都是细节处理没啥好说了. #include <iostream> #include <cstdio> #include <algorithm> #include <string.h…
如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #define INF 0x3f3f3f3f using namespace std; /* 求满足下面的最大的E: 恰好有E个天的行程都大于E miles 从小到大排序,倒着循环一遍,直到最小值<=天数为止,此时的天数-1即为答案. */ +; i…
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789787.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~~ 给出n个couple和m个宾客如果宾客没有couple或者couple没来,则被认为lonely问你有多少个lonely的宾客,并且按照id的升序输出 #include <iostream> #include <cstdio> #include…
博主欢迎转载,但请给出本文链接,我尊重你,你尊重我,谢谢~http://www.cnblogs.com/chenxiwenruo/p/6789799.html特别不喜欢那些随便转载别人的原创文章又不给出链接的所以不准偷偷复制博主的博客噢~~ 先来扩展一下知识哈密顿图:哈密顿图是一个无向图,由指定的起点通往指定的重点,途中经过所有节点有且只经过一次.在图论中,通常指的是哈密顿回路,即经过图中所有顶点有且只有一次,最终回到出发点.哈密顿回路为NP完全问题,暂不存在多项式内的解法. 欧拉图:类似的有欧…
题目已经告诉如何判断欧拉回路了,剩下的有一点要注意,可能图本身并不连通. 所以这里用并查集来判断图的联通性. #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> #include <string> using namespace std; /* 并查集用来判断图的联通性,有一组样例图是不连通的... */ ; ]; struct UF{ in…
遇见模拟题 有两种做法 例如这题: 1.直接去算次数(统计哪个数在第几位,然后去运算) 2.模拟操作 贴一个别人的代码...https://blog.csdn.net/weixin_39453270/article/details/80548780 #include <bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; string str1,str2; ; void Get(char a,char b,int n,int…