题意:有一个长度为\(n\)的序列,可以对所有元素++或--,求最少的操作次数,如果无论如何都不能构成,则输出\(-1\). 题解:一个等差数列一定由首项\(a_{1}\)和公差\(d\)来决定,而这两项可以有\(a_{1}\)和\(a_{2}\)来决定,所以我们可以直接暴力枚举\(a[1]\)和\(a[2]\),一共\(9\)种情况,每次向后枚举,判断每个位置上的数是否能得到,然后更新最小值即可. 代码: #include <iostream> #include <cstdio>…
http://codeforces.com/contest/978/problem/D 题目大意: 给你一个长度为n的b(i)数组,你有如下操作: 对数组中的某个元素+1,+0,-1.并且这个元素只能修改一次 问:是否有操作能吧这个数组变成等差 如果有,请输出把他变成等差的最小步数.否则输出-1: 思路: 定等差的值即可 暴力b1和b2的+1,+0,-1,即可得到等差的值…
Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/D Description Finally it is a day when Arthur has enough money for buying an apartment. H…
我实在是因为无聊至极来写Div3题解 感觉我主要的作用也就是翻译一下题目 第一次线上打CF的比赛,手速很重要. 这次由于所有题目都是1A,所以罚时还可以. 下面开始讲题 A.Remove Duplicates 题目大意:给你一个序列,让你对这个序列中重复的数进行去重.要求相对顺序不变并且有限保留右边的. 首先这道题O(n)扫一遍+hash是可以的,但是这数据范围... 开桶即可. CODE #include<cstdio> const int N=55; int a[N],n,ans[N],t…
成功掉到灰,真的心太累了,orz!!!!,不是很懂那些国外大佬为什么每次都是20多分钟AK的,QAQ A. Remove Duplicates time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya has an array aa consisting of nn integers. He wants to remove d…
D. Moodular Arithmetic Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/problem/D Description As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State Uni…
http://codeforces.com/contest/978/problem/G 感冒是真的受不了...敲代码都没力气... 题目大意: 期末复习周,一共持续n天,有m场考试 每场考试有如下信息: ①si表示知道第i门课的考试时间是在第si天的时候 ②di表示第i门课的考试时间 ③ci表示准备第i门课需要ci天的复习 在考试的那一天不能复习. 问n天中每一天都需要干啥? 三种情况,休息(输出0),复习(输出复习那一门科目的id),考试(输出m+1) 思路:按照di排序(即按照截止时间),然…
B - Moodular Arithmetic 题目大意:题意:告诉你p和k,其中(0<=k<=p-1),x属于{0,1,2,3,....,p-1},f函数要满足f(k*x%p)=k*f(x)%p,f(x)的范围必须在[0.p-1]内,问这样的f函数有多少个. 思路:数学题不会写啊啊啊啊.. 一般这种题和费马小定理有关系,寻找循环节. 我们可以发现当k = 0 是答案为 p ^ (p - 1) k = 1 时答案为p ^ p 否则 首先我们知道f(0) = 0; 我们到最小的 r 使得 k ^…
A题,题目链接:http://codeforces.com/contest/978/problem/A 解题心得:题意就是让你将这个数列去重,重复的数只保留最右边的那个,最后按顺序打印数列.set+map. #include <bits/stdc++.h> using namespace std; const int maxn = 100; int num[maxn],n; map <int,int> map1,map2; set <int> se; int main(…
题目地址:http://codeforces.com/contest/978/problem/C 题解:有n个宿舍,每个宿舍人不一样多,有m封信,每封信送给对应的第m间房间,问这封信是给第几个宿舍,第几间房的. 方法:做题目的时候没有看到信的编号是不断升高的,把题目想复杂了,wa了两次.这题把寝室的房间累加在一起,然后设一个现在送到那个寝室的变量,逐步累加算法会快很多. 代码:(代码较丑,欢迎大佬们批评指正) #include<cstdio> #include<cmath> #in…
题目地址:http://codeforces.com/contest/978/problem/B 题解:一串文件名里不能出现连续的xxx,询问进行几次操作后,文件名才不会出现xxx. 方法:只要遍历一遍字符串里有几个xxx就可以了. 代码:(代码较丑,欢迎大佬们批评指正) #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> #include<string>…
题目地址:http://codeforces.com/contest/978/problem/A 题解:给一串长度为n的数组,然后删去相同的数字(从右往左). 方法:题目n和数组ai给的范围都很小,所以可以放一个vis[1500]的数组表示1~1000内的数字是否被访问过.从右到左倒着访问,然后再把out数组倒着输出. 代码:(代码较丑,欢迎大佬们批评指正) #include<cstdio> #include<cmath> #include<algorithm> #in…
Petya studies at university. The current academic year finishes with nn special days. Petya needs to pass mm exams in those special days. The special days in this problem are numbered from 11 to nn. There are three values about each exam: sisi — the…
题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你每天都在干什么,如果这一天你有考试,输出\(m+1\),如果你要准备第\(i\)场考试,输出\(i\),否则休息,输出\(0\). 题解:数据范围小,直接模拟,但我们需要先贪心,即每次都要先准备最早的考试,然后直接写两个\(for\)循环就行了. 代码: #include <iostream> #…
题意:有一个长度为\(n\)的序列\(a\),求这个序列中有多少比\(a_{i}\)小的数,如果某两个位置上的数有矛盾,则不能算小. 题解:用\(pair\)来记录序列中元素的位置和大小,将他们升序排序,对于每对矛盾的位置,只记录\(a[u]>a[v]\)的情况,小于等于的情况没必要考虑,然后我们遍历排序后的序列,二分查找第一个大于等于它的位置,然后减去比它小的矛盾的点的个数即为答案.时间复杂度为\(O(n*logn)\) 代码: #include <iostream> #include…
题意:有个\(n\)个公寓,每个公寓\(a_{i}\)代表着编号为\(1-a_{i}\)个房间,给你房间号,问它在第几栋公寓的第几个房间. 题解:对每个公寓的房间号记一个前缀和,二分查找属于第几个公寓,然后求个差即可. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <sta…
 B. Mike and Fun Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/548/problem/A Description Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there'…
C. Divisibility by Eight Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/problem/C Description You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leadin…
A. Borya and Hanabi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/442/problem/A Description Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Ove…
B. Equivalent Strings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/559/problem/B Description Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are…
C. Amr and Chemistry Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/558/problem/C Description Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different type…
A. Vanya and Table Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/problem/A Description Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom…
A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/problem/A Description A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attr…
C. Edo and Magnets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594/problem/C Description Edo has got a collection of n refrigerator magnets! He decided to buy a refrigerator and hang the magnets on the door. The shop ca…
A. Vitaly and Night Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/595/problem/A Description One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly de…
C. Letter Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/180/problem/C Description Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervou…
C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/problem/C Description Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of h…
A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an eleva…
A. Vladik and Courtesy time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output At regular competition Vladik and Valera won a and b candies respectively. Vladik offered 1 his candy to Valera. Afte…
 A. Mike and Fax Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/548/problem/A Description While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among th…