cf div2 move2/3
#include <bits/stdc++.h>
using namespace std;
#define long long LL
#define first x
#define second y
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >>tt;
while(tt--)
{
int x,res;
cin >>x;
if(x==1)
{
cout <<2<<endl;
}
else
{
cout <<(x+2)/3<<endl;
}
}
return 0;
}思维题,具体可以看笔记8.05 第7题
cf div2 Permutation Chain(构造题目)
交换位置题目
#include<iostream>
#include<vector>
#include<algorithm>
#include <numeric>
using namespace std;
#define long long LL
#define first x
#define second y
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >>n;
while(n--)
{
int x;
cin >>x;
cout <<x<<endl;
vector<int> p(x);
iota(p.begin(),p.end(),1);
for(auto c:p)
cout <<c<<" ";
cout <<endl;
for(int i=0;i<x-1;i++)
{
swap(p[i],p[i+1]);
for(auto c:p)
cout <<c<<" ";
cout <<endl;
}
}
return 0;
}学习到了一个新的函数iota
web应用课
margin
margin属性为给定元素设置所有四个(上下左右)方向的外边距属性。
可以接受1~4个值(上、右、下、左的顺序)
可以分别指明四个方向:margin-top、margin-right、margin-bottom、margin-left
可取值
length:固定值
percentage:相对于包含块的宽度,以百分比值为外边距。
auto:让浏览器自己选择一个合适的外边距。有时,在一些特殊情况下,该值可以使元素居中。
外边距重叠
块的上外边距(margin-top)和下外边距(margin-bottom)有时合并(折叠)为单个边距,其大小为单个边距的最大值(或如果它们相等,则仅为其中一个),这种行为称为边距折叠。
父元素与后代元素:父元素没有上边框和padding时,后代元素的margin-top会溢出,溢出后父元素的margin-top会与后代元素取最大值。
padding
padding CSS 简写属性控制元素所有四条边的内边距区域。
可以接受1~4个值(上、右、下、左的顺序)
可以分别指明四个方向:padding-top、padding-right、padding-bottom、padding-left
可取值
length:固定值
percentage:相对于包含块的宽度,以百分比值为内边距。
box-sizing
CSS 中的 box-sizing 属性定义了 user agent 应该如何计算一个元素的总宽度和总高度。
content-box:是默认值,设置border和padding均会增加元素的宽高。
border-box:设置border和padding不会改变元素的宽高,而是挤占内容区域。
每日一题(最长算数)双指针。差分
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
int T,n;
int f[N];
int main()
{
cin >> T;
for (int q = 1; q <= T; q++)
{
cin >> n;
for (int i = 0; i < n; i++) scanf("%d", &f[i]);
int ans = 2, x; // ans记录最大长度,x记录差值
for (int i = 0; i < n - 1; i++)
{
x = f[i + 1] - f[i]; // 当前算数数组的差值
int j = i + 1;
while (j < n && f[j] - f[j - 1] == x) j++; // 双指针
ans = max(ans, j - i); // 比较最大
// i是算数数组的开头下标,j是结尾下标的下一个下标
// 在找下一个算数数组时,我们应该从上一个算数数组结尾和结尾的下一个数开始找起
i = j - 2; // 因为循环结束还会加加,要让下一次循环的i等于当前算数数组结尾下标,所以要减2
}
printf("Case #%d: %d\n", q, ans);
}
return 0;
}