div

原生js鼠标拖拽div左右滑动

微笑、不失礼 提交于 2019-12-06 05:12:01
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="js/jquery.min.js"></script> <style> body{ position: relative; margin:0; padding:0; width:100%; height: 1000px; } #box{ height: 50px; width:200px; position: absolute; left:50%; top:50%; margin-left:-200px; margin-top:-200px; background: #CDCDCD; } #small-box{ height: 50px; width:50px; position: absolute; left:0; top:0; background: #FF66CC; cursor:move ; opacity: 0.7; } </style> </head> <body> <div id="box"> <div id="small-box"></div> </div> <script> var box=$("#small-box"); var body=$('body'); var

Codeforces Round #603 (Div. 2) E. Editor 线段树

那年仲夏 提交于 2019-12-06 04:30:00
E. Editor The development of a text editor is a hard problem. You need to implement an extra module for brackets coloring in text. Your editor consists of a line with infinite length and cursor, which points to the current character. Please note that it points to only one of the characters (and not between a pair of characters). Thus, it points to an index character. The user can move the cursor left or right one position. If the cursor is already at the first (leftmost) position, then it does not move left. Initially, the cursor is in the first (leftmost) character. Also, the user can write a

Codeforces Round #603 (Div. 2)

跟風遠走 提交于 2019-12-06 03:56:04
Codeforces Round #603 (Div. 2) A. Sweet Problem 题意:多组数据,每组数据给出3种颜色的糖果,规定每天吃2颗糖果,颜色不能相同,问最多吃几天。 思路:3种糖果按照个数多少排序得到a≤b≤c,①若a+b≤c,则每天吃 c 和 a,b中的一种,可以吃a+b天。②若a+b>c,则先吃a和c让c和b一样多,然后若剩余的a为偶数则所有糖可以都吃完,若为奇数则最后会剩余1颗,所以此种情况对应天数为(a+b+c)/2天。 #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); long long n; long long num[3]; cin>>n; while(n--){ cin>>num[0]>>num[1]>>num[2]; sort(num,num+3); if(num[0]+num[1]<=num[2]){ cout<<num[0]+num[1]<<endl; }else{ cout<<(num[0]+num[1]+num[2])/2<<endl; } } return 0; } View Code B. PIN Codes 题意:多组数据,每组数据给出n个4位密码

Codeforces Round #603 (Div. 2)

﹥>﹥吖頭↗ 提交于 2019-12-06 03:53:06
A - Sweet Problem 题意:有3种糖果(什么蜡烛?分不清candy和candle的一定不止我一个中国人),每天要吃两种不同的各1颗。给出3种的数量,求可以吃多少天。 题解:假如数据小的话直接每次去最高的两个--,然后sort就行了。可惜搞不得。但是每次取最高这个思路是没错的。假如三种数量很平均,那么肯定是加起来除以2的下整,不对的情况在于最多的糖不能充分利用,临界情况是恰好相等,所以: void test_case() { int a[4]; for(int i = 1; i <= 3; ++i) scanf("%d", &a[i]); sort(a + 1, a + 1 + 3); a[3] = min(a[3], a[1] + a[2]); printf("%d\n", (a[1] + a[2] + a[3]) / 2); } B - PIN Codes 题意:有n(<=10)种PIN码,PIN码就是4位可前导零的数字,每次可以改动一位数字,求使得所有PIN码两两不同的最小改法。 题解:因为一共就10种码,刚好有10种数字,所以无论如何都最多改1位就够了。每次取重复的两个出来,然后遍历其中的数字,枚举把它改成谁会和大家都不一样。注意最后还要输出前后对应的关系。 map<string, int> m; string a[15]; void test_case() {

生成一个水平+垂直居中的div

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 02:38:11
  这是前端布局经常用到的布局方式,水平垂直居中;面试也经常会问到。 一. 绝对定位实现居中 注意:使用绝对定位布局的时候,外层元素必须也设置有 position 属性,具体设置为什么值看具体情况。只要不是static就行。 1.通过定位+margin实现 将四个方向的偏移量设为0,然后用margin:auto实现居中。 1 .center { 2 /* div的基本属性 */ 3 height: 500px; 4 width: 500px; 5 background-color: blue; 6 /* 绝对定位 */ 7 position: absolute; 8 /* 通过定位+margin实现双居中 */ 9 top: 0; 10 left: 0; 11 bottom: 0; 12 right: 0; 13 margin:auto; 14 } 2.通过定位+transform实现 设置top和left偏移量为50%,此时的正中间是div开始的位置,也就是div的坐上角,所以还需要向左上方向移动50%的宽(高)度。 .center { /* div的基本属性 */ height: 500px; width: 500px; background-color: blue; /* 绝对定位 */ position: absolute; /* 通过定位+transform实现双居中 *

div定位relative和absolute测试1

一笑奈何 提交于 2019-12-06 02:06:44
div里的position定位也是比较常见的,relative是相对定位,absolute是绝对定位。 如本文测试: body自带8px的margin,这里不对其进行清空。 蓝色的div和红色的div分别设置两种定位方式,都是top值10px。 测试结果: 蓝色div( relative ):18px,相对于body向下的了10px,body自身带着上margin是8px,所以相对于浏览器上方是10+8px。 相对位置受外面的内容的margin的影响 。 红色div( absolute ):10px,相对于浏览器向下了10px,相对于body向下了2px, 直接对浏览器定位 ,不受外面的内容的margin影响 。 如果有其他div和元素,absolute绝对定位 也不会受影响。 relative也会相对于外面的那个元素,受这个元素的位置的影响,在该元素的位置基础上偏移。 测试前面有其他元素:div定位relative和absolute测试2、 测试代码: <style> #blue_div{position:relative;top:10px;} #red_div{position:absolute;top:10px;} </style> </head> <body> <div id="blue_div" style="width:200px;height:200px

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)

安稳与你 提交于 2019-12-05 16:18:10
Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 题意:有t组数据,每组数据给出n个范围[L i ,R i ],求与n个范围都有交集的最小范围[Ans_L,Ans_R]的长度([L,R]的长度定义为R-L) 思路:这个区间只要从所有区间右端点的最小值覆盖到所有区间左端点的最大值即可。 #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0);cout.tie(0); int total; cin>>total; while(total--){ int n,x,y; cin>>n; if(n==1) { cin>>x>>y; cout<<0<<endl; continue; }else{ int qian=0,hou=1e9; for(int i=1;i<=n;i++){ cin>>x>>y; qian=max(qian,x); hou=min(hou,y); } int ans=max(0,qian-hou); cout<<ans<<endl; } } return 0; } View Code B. Box 题意

div中宽高度自适应文字换行居中问题解决

£可爱£侵袭症+ 提交于 2019-12-05 14:18:40
<html> <head> <meta charset="UTF-8"/> <title>div中宽高度自适应文字换行居中demo</title> </head> <style type="text/css"> .fatherbox{ width: 200px; height: 300px; text-align: center; /* start 以下为样式内容,不重要*/ border: 1px solid red; background: green; /* end 以上为样式内容,不重要*/ } .childbox1{ display: inline-block; vertical-align: middle; /* start 以下为样式内容,不重要*/ background: blue; color: #fff; padding: 10px; /* end 以上为样式内容,不重要*/ } .childbox2{ display: inline-block; vertical-align: middle; height: 100%; } </style> <body> <div class="fatherbox"> <div class="childbox1"> 我是居中内容1<br/> 我是居中内容1<br/> 我是居中内容1<br/> 我是居中内容1 </div>

@click.prevent.self和@click.self.prevent区别

馋奶兔 提交于 2019-12-05 14:03:53
注意:prevent 阻止的是“跳转事件”而不是“弹出警告” v-on:click.prevent.self的demo如下: <div id="box"> <div @click="alert(1)"> <a href="/#" @click="alert(2)">a标签 <div @click="alert(3)">div标签</div> </a> </div> </div> 此时点击a标签会依次弹出2,1,跳转。点击div标签会依次弹出3,2,1,跳转。这发生了事件冒泡。 咱们看一下加上v-on:click.prevent.self之后的: <div @click="alert(1)"> <a href="/#" @click.prevent.self="alert(2)">a标签 <div @click="alert(3)">div标签</div> </a> </div> 此时点击a标签会依次弹出2,1。点击div标签会依次弹出3,1。此时各位看官已经发现,a标签不仅没有冒泡,也没有跳转,这就是官网说的会阻止所有的点击。 这段是“没文化不开心”网友的解释: 点击div标签,会alert3,alert1。不但阻止了alert(2),还阻止了a的默认跳转。 因为点击的时候会先prevent,阻止默认事件,阻止了跳转;然后判断是否是self,因为点击到的是div标签

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on test 233 (Hard Version) dp 数学

心已入冬 提交于 2019-12-05 12:29:47
F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong answer on test 233" . This is the harder version of the problem. In this version, 1≤n≤2⋅105. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. The problem is to finish n one-choice-questions. Each of the questions contains k options, and only one of them is correct. The answer to the i-th question is hi, and if your answer of the question i is hi, you earn 1 point, otherwise, you earn 0 points for this question. The values h1,h2,…,hn