#include<iostream>#include<algorithm>#define MAXN 1005#define INF 0x3f3f3f3fusingnamespace std;int a[MAXN];intmain(){
int n, ans = INF;scanf("%d",&n);for(int i =0; i < n;++i)scanf("%d",&a[i]);sort(a, a + n);for(int i =1; i < n;++i)
ans =min(ans, a[i]- a[i-1]);printf("%d\n", ans);return0;}
5
1 5 4 8 20
1
5
9 3 6 1 3
0
2.游戏
//模拟#include<iostream>#include<queue>usingnamespace std;intmain(){
int n, k;
queue<int> q;
cin >> n >> k;for(int i =1;i <= n;++i)
q.push(i);//store n numbersint top, no =0;while(!q.empty()){
top = q.front();
q.pop();
no++;if(no%k !=0&&(no%10)!= k)
q.push(top);//与n有关}
cout << top << endl;;return0;}
5 2
3
7 3
4
3.Crontab
//思维#include<iostream>#include<string>#include<vector>#include<map>#include<set>#include<algorithm>usingnamespace std;typedeflonglong LL;int firstYear, lastYear;// 开始与结束的年份int range[5]={
60,24,31,12,7};int days[13]={
0,31,28,31,30,31,30,31,31,30,31,30,31};
string week[]={
"sun","mon","tue","wed","thu","fri","sat"},
mon[]={
"jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"};
map<string,int> mp;// 保存各个英文缩写对应的值
vector<pair<LL,int>> ans;// ans存放结果的 "时间,id" 对// 如果是字母开头,一定是英文缩写,直接返回mp中对应的值;否则就是数字,按位累加即可intstrToI(string &str){
if(isalpha(str[0]))return mp[str];int num =0;for(int i =0; i != str.size();++i)
num = num *10+ str[i]-'0';return num;}voiddealMinus(set<LL>&tmp, string &str){
for(int i =0; i != str.size();++i)
str[i]=tolower(str[i]);// 不区分大小写
size_t tp = str.find('-');if(tp == string::npos)
tmp.insert(strToI(str));else{
string left = str.substr(0, tp), right = str.substr(tp +1);int l =strToI(left), r =strToI(right);for(int i = l; i <= r;++i)
tmp.insert(i);}}// 先分析s是否为"*",再分析',',最后分析'-'voidfindValue(set<LL>&tmp, string &s,int j){
if(s =="*"){
for(int i =0; i != range[j];++i)if(j ==2|| j ==3)// 日期和月份是1开头的
tmp.insert(i +1);else
tmp.insert(i);return;}
s +=',';
size_t pos =0, next = s.find(',');
string str;while(next != string::npos){
str = s.substr(pos, next - pos);dealMinus(tmp, str);
pos = next +1;
next = s.find(',', pos);}}// 分析y年m月d日是星期几,顺便排除一下不合法的日期比如11月31日intgetDay(int year,int month,int day){
days[2]=28;if(year %4==0)
days[2]=29;if(day > days[month])// 该日期不存在return-1;int sum =4, q = year -1970;
sum += q /4*5+ q %4;// 每隔四年,sum应该+5if(q %4==3)// 这时说明 year-1 为闰年++sum;for(int i =1; i != month;++i)
sum += days[i];
sum += day -1;return sum %7;}// v[0] ~ v[3]不进行判断,只把tmp与pre中的内容组合起来,所有的判断放在v[4]中voidfillVector(vector<vector<LL>>&v, vector<LL>&tmp,int j, LL mul){
if(j ==0)
v[j]= tmp;else{
vector<LL>&pre = v[j -1];if(j !=4)for(int k =0; k != tmp.size();++k)for(int l =0; l != pre.size();++l)
v[j].push_back(tmp[k]* mul + pre[l]);else{
int judge[7]={
0};// 用于判断一周中的每一天是否能够执行该命令for(int k =0; k != tmp.size();++k)
judge[tmp[k]]=1;for(int l =0; l != pre.size();++l){
int month = pre[l]/1000000, day = pre[l]/10000%100;for(int year = firstYear; year <= lastYear;++year){
int dow =getDay(year, month, day);if(dow !=-1&& judge[dow