leijiawu 1个月前

### [递增三元组](https://www.lanqiao.cn/problems/172/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=3&problem_id=172) ``` #include <bits/stdc++.h> using namespace std; int n, a[100005], b[100005], c[100005]; long long ans = 0; // bool cmp(int a, int b) // { // return a > b; // } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; for (int i = 1; i <= n; i++) cin >> c[i]; sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); sort(c + 1, c + n + 1); // for (int i = 1; i <= n; i++) // { // for (int j = n; j >= 1; j--) // { // for (int k = n; k >= 1; k--) // { // if (a[i] >= b[j]||b[j] >= c[k]) // { // break; // } // if (a[i] < b[j] && b[j] < c[k]) // ans++; // } // if (a[i] >= b[j]) // { // break; // } // } // if(a[i]>=b[n]){ // break; // } // } for(int i=1;i<=n;i++){ //for的是中间的数,比它小的*比它大的等于含有b[i]的组合数 long long x = lower_bound(a+1,a+n+1,b[i])-a-1; long long y = n-(upper_bound(c+1,c+n+1,b[i])-c-1); ans+=x*y; } cout << ans; return 0; } ```


leijiawu 1个月前

优化技巧:先排好序,从大到小遍历,当后面的数都不满足时,就终止当前循环. [1.倍数问题](https://www.lanqiao.cn/problems/168/learning/?page=1&first_category_id=1&sort=students_count&second_category_id=3&problem_id=168) ```cpp #include <iostream> #include <algorithm> using namespace std; int n, k; long arr[100005]; bool cmp(long a, long b) { return a > b; } int main() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> arr[i]; } sort(arr + 1, arr + n + 1, cmp); long long maxans = 0; for (int i = 1; i <= n - 2; i++) { for (int j = i + 1; j <= n - 1; j++) { for (int h = j + 1; h <= n; h++) { if ((arr[i] + arr[j] + arr[h]) % k == 0) { if (maxans < arr[i] + arr[j] + arr[h]) { maxans = arr[i] + arr[j] + arr[h]; } if (arr[i] + arr[j] + arr[h] < maxans) { break; } } } if (arr[i] + arr[j] + arr[j + 1] < maxans) { break; } } if (arr[i] + arr[i+1] + arr[i + 2] < maxans) { break; } } cout << maxans; return 0; } ```


leijiawu 1个月前

```javascript <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> body { background-color: #CDCDCD; } .container { position: relative; width: 600px; height: 480px; background-color: #fff; margin: 100px auto; text-align: center; border-radius: 10px; box-shadow: 0px 0px 20px 5px #999; } .container h1 { padding: 20px 10px; } .userinput { margin: 5px 20px; /* padding-top: 20px; */ font-size: 18px; } button { width: 100px; height: 35px; margin-top: 20px; margin-bottom: 20px; margin-right: 20px; background-color: teal; color: #fff; border-radius: 5px; cursor: pointer; } button:hover { background-color: rgb(46, 97, 97); box-shadow: 2px 2px 5px #888; } p { font-size: 12px; color: red; visibility: hidden; } input { width: 300px; height: 35px; border-radius: 5px; border: 1px solid #888; } </style> </head> <body> <div class="container"> <h1>欢迎注册</h1> <div class="userinput"> 手机号: <input type="text" id="phone" placeholder="手机号">* <p id="phone-tip">手机号位数不足或已注册过提示</p> </div> <div class="userinput"> 登录密码: <input type="text" id="pwd1" placeholder="以字母开头,长度在6~18之间,只能包含字母、数字和下划线">* <p id="pwd-tip1">密码位数不足或与要求不匹配提示</p> </div> <div class="userinput"> 确认密码: <input type="text" id="pwd2" placeholder="输入与上一个相同的密码">* <p id="pwd-tip2">密码与上一密码框输入不相同提示</p> </div> <button id="register">注册</button> <button id="cacle">取消</button> </div> <script> var value1 var value2 var value3 var flag1=false var flag2=false var flag3=false var arr= new Array() function checkPhone() { var reg = /^1[3456789]\d{9}$/; value1 = document.getElementById("phone").value; if (reg.test(value1) == false) { document.getElementById("phone-tip").style.visibility = 'visible'; flag1=false } else { document.getElementById("phone-tip").style.visibility = 'hidden'; flag1=true } } function checkPwd1() { var reg = /^[a-zA-Z]\w{5,17}$/; value2 = document.getElementById("pwd1").value; if (reg.test(value2) == false) { document.getElementById("pwd-tip1").style.visibility = 'visible'; flag2=false } else { document.getElementById("pwd-tip1").style.visibility = 'hidden'; flag2=true } } function checkPwd2() { value3 = document.getElementById("pwd2").value; if (value2!=value3) { document.getElementById("pwd-tip2").style.visibility = 'visible'; flag3=false } else { document.getElementById("pwd-tip2").style.visibility = 'hidden'; flag3=true } } document.getElementById("register").addEventListener('click',function(){ checkPhone(); checkPwd1(); checkPwd2(); if(flag1&&flag2&&flag3){ userObj={userphone:value1,password:value2} arr.push(userObj) console.log(arr) } }) document.getElementById("cacle").addEventListener('click',function(){ document.getElementById("phone").value=""; document.getElementById("pwd1").value=""; document.getElementById("pwd2").value=""; document.getElementById("phone-tip").style.visibility = 'hidden'; document.getElementById("pwd-tip1").style.visibility = 'hidden'; document.getElementById("pwd-tip2").style.visibility = 'hidden'; }) document.getElementById("phone").addEventListener('input',function(){ checkPhone(); }) </script> </body> </html> ```


leijiawu 1个月前

题目: 初始5, 一年后变成5+9,二年后变成5+9+17... 输入n年,以及n年后的总数s,让我们求初始值。 所以变成求数列a1的值。由题目得,样例的a1=5,a2=2*a1-1, a3=2*a2-1, a4=2*a3-1。 a(n)=2*a(n-1)-1 两边减1,得 a(n)-1=2*a(n-1)-2, 即a(n)-1=2*(a(n-1)-1) 所以 [a(n)-1]/[a(n-1)-1]=2 设b(n)=a(n)-1 则b(n)为公比q为2的等比数列,即b(n)=b1*q^(n-1), 又b1=a1-1, 所以b(n)=(a1-1)*2^(n-1) 所以a(n)-1=(a1-1)*2^(n-1) 所以a(n)的通项公式a(n)=(a1-1)*2^(n-1)+1。 由于第1年的和s为a(n)的前2项和, 也就是S2=a1+a2, 第2年的和s为a(n)的前3项和, 也就是S3=a1+a2+a3, 第3年的和s为a(n)的前4项和, 也就是S4=a1+a2+a3+a4, 所以输入第n年的和,总数就是S(n+1)。 所以就可以套数列求和公式求解, a(n)的前n项和为S(n)=[(a1-1)*(1-q^n)]/(1-q)+n, 由q=2,得S(n)=(a1-1)*(2^n - 1)+n 所以输入第n年的总数s=S(n+1)=(a1-1)*[2^(n+1) - 1] + (n+1), 即 s=(a1-1)*[2^(n+1) - 1] + (n+1) 所以我们要求的原始数量也就是a1, 为a1 = (s-n-1)/[2^(n+1) - 1]+1, 所以 cout<<(s-n-1)/(pow(2,n+1)-1)+1; ```cpp #include <iostream> #include<math.h> using namespace std; double n; double s; long long ans=0; int main() { cin>>n>>s; cout<<(s-n-1)/(pow(2,n+1)-1)+1; return 0; } ```


leijiawu 1个月前

```cpp #include<iostream> using namespace std; long long n,k; // int arr[100005]; long long sum[100005]; long long ans=0; long long cnt[100005]; int main(){ cin>>n>>k; for(int i=1;i<=n;i++) { int t; cin>>t; sum[i]=sum[i-1]+t;//计算前缀和 cnt[sum[i]%k]++;//除以k余数相同的两个数,相减能被k整除 } // for(int i=0;i<n;i++){ // for(int j=i+1;j<=n;j++){ // if((sum[j]-sum[i])%k==0){ // ans++; // } // } // } //这种方法会超时 ans=cnt[0]; for(int i=0;i<k;i++){ ans+=(cnt[i]*(cnt[i]-1)/2); //等差数列求和:1+2+...+(n-1),这里cnt[i]就是n } cout<<ans; return 0; } ```


leijiawu 1个月前

```sql create database scsjk use scsjk select*from student select*from course select*from sc create table student (sno char(9) primary key, sname char(20), ssex char(2), sage smallint, sdept char(20) ); create table course (cno char(4) primary key, cname char(40), cpno char(4), ccredit smallint ); create table sc (sno char(9), cno char(4), grade smallint, primary key(sno,cno) ); insert into student values('95001','李勇','男','20','CS') insert into student values('95002','刘晨','女','19','CS') insert into student values('95003','王敏','女','18','MA') insert into student values('95004','张立','男','19','IS') insert into course values('1','数据库',5,4) insert into course values('2','数学',null,2) insert into course values('3','信息系统',1,4) insert into course values('4','操作系统',6,3) insert into course values('5','数据结构',7,4) insert into course values('6','数据处理',null,2) insert into course values('7','PASCAL语言',6,4) insert into sc values('95001','1',92) insert into sc values('95001','2',85) insert into sc values('95001','3',88) insert into sc values('95002','2',90) insert into sc values('95002','3',80) create view isstudent as select sno,sname,ssex,sage from student where sdept='IS' with check option; create view gradec1 as select sno,grade from sc where cno='1' with check option; create index student_index on student (sno asc) create index course_index on course (cno asc) create unique index sc_unique_index on sc (sno asc,cno asc) create index sc_snograde on sc(sno,grade desc) insert into student values('95008','吴小莉','女','20','IS') update student set sage='22' where sname='李勇' update sc set grade=grade+2 where cno='1' delete from course where cpno='6' delete from sc where cno='1' delete sc,student from sc left join student on sc.sno=student.sno where sc.sno='95001'//语法错误但是不知道为什么 ```


leijiawu 2个月前

```javascript <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> * { font-family: sans-serif; font-size: 1.0rem; letter-spacing: 1px; } .container { position: relative; width: 70%; margin: 5px auto; text-align: center; display: flex; flex-direction: column; } button { width: 90px; height: 30px; margin-top: 20px; margin-bottom: 20px; } .table-area { display: contents; } thead, tfoot { background-color: #2c5e77; color: #fff; } tbody { background-color: #e4f0f5; } table { border-collapse: collapse; border: 2px solid rgb(140 140 140); } caption { caption-side: top; padding: 10px; } th, td { border: 1px solid rgb(160 160 160); padding: 8px 10px; } td { text-align: center; } </style> </head> <body> <div class="container"> <div class="top"> 录入书名:<input type="text" class="userInput" id="userInput"> <button class="add" id="add">新增图书</button> </div> <div class="table-area"> <table> <caption> <h1>图书列表</h1> </caption> <thead> <tr> <th>序号</th> <th>书名</th> </tr> </thead> <tbody> <tr> <!-- <th>1</th> <td>时间简史</td> --> </tr> </tbody> <tfoot> <tr> <th>图书总数</th> <td>0</td> </tr> </tfoot> </table> </div> </div> <script> const add = document.getElementById("add") const userInput = document.getElementById("userInput") const tbody = document.querySelector('tbody') let count = 0 let arr = [] add.addEventListener('click',function(){ // let li = document.createElement('li') // li.innerHTML = `<li>${subStr(strTitle[i])}</li>` // ul.appendChild(li) let bookname = userInput.value // if(arr.includes(bookname)){ alert('图书已存在') } else{ let tr = document.createElement('tr') tr.innerHTML = `<th>${++count}</th><td>${bookname}</td>` tbody.appendChild(tr) arr.push(bookname) } }) </script> </body> </html> ```


leijiawu 2个月前

```js <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> body { background-color: gainsboro; } .container { position: relative; width: 600px; height: 280px; background-color: #fff; margin: 20px auto; text-align: center; border-radius: 10px; box-shadow: 0px 0px 10px 5px #888; } .userinput{ padding-top: 20px; font-size: 18px; } p{ font-size: 18px; } button { width: 80px; height: 35px; margin-top: 20px; margin-bottom: 20px; margin-right: 20px; background-color: teal; color: #fff; border-radius: 5px; cursor: pointer; } button:hover { background-color: rgb(46, 97, 97); box-shadow: 2px 2px 5px #888; } h1 { margin-top: 30px; text-align: center; } input { height: 35px; border-radius: 5px; border: 1px solid #888; } .result { position: absolute; left: 0; right: 0; margin: auto; width: 400px; height: 50px; border: 1px solid #888; border-radius: 5px; justify-content: center; } </style> </head> <body> <h1>随机字符串生成器</h1> <div class="container"> <div class="userinput"> 您希望得到的字符串长度: <input type="text" id="ipt"><br> </div> <button id="start">点击生成</button> <button id="clear">清空</button> <p>随机字符串(仅包括大小写字母,不重复):</p> <div class="result" id="result"></div> </div> <script> var unid = []; const input = document.querySelector('input') const arr="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" let result=null; function randomIndex(){ let id = Math.floor(Math.random()*52); if(!unid.includes(id)){ unid.push(id) return id; } else{ return randomIndex(); } } function randomLetter(){ for(let i=0;i<input.value;i++){ if(!result){ result=((arr[randomIndex()])) }else{ result+=((arr[randomIndex()])) } } } document.getElementById("start").addEventListener('click',function(){ randomLetter() document.getElementById("result").innerHTML=result; }) document.getElementById("clear").addEventListener('click',function(){ document.getElementById("result").innerHTML=""; result=null; unid = []; }) </script> </body> </html> ```


leijiawu 2个月前

### laravel实现删除评论功能 路由请求方式为delete ```php Route::delete('/comment/{comment}',\App\Http\Controllers\CommentDeleteController::class,) ->name('comment.delete'); ``` 控制器使用模型删除 ```php class CommentDeleteController extends Controller { public function __invoke(Comment $comment) { //删除用户自己的评论 $res = $comment->delete(); if ($res){ return response()->api('删除成功'); }else{ return response()->api('删除失败',400); } } } ``` 前端提交的路由参数不是$comment, 而是$comment->id ```js data-url="{{route('blog.comment.delete',$comment->id)}}" ``` 然后使用jquery和ajax删除页面元素 ```js $('.del-comment').click(function (){ var that = this; $.ajax({ url: $(this).data('url'), type:'delete', datatype: 'json', success:function (res){ if(res.code == 200){ //删除成功后,让删除掉的这条评论从页面自己消失 $(that).parents('.blog-comment-item').remove() notify('success', res.msg) }else { notify('error', res.msg) } } }) }) ```


leijiawu 2个月前

```sql create database scsjk use scsjk create table student (sno char(9) primary key, sname char(20), ssex char(2), sage smallint, sdept char(20) ); create table course (cno char(4) primary key, cname char(40), cpno char(4), ccredit smallint ); create table sc (sno char(9), cno char(4), grade smallint, primary key(sno,cno) ); insert into student values('95001','李勇','男','20','CS') insert into student values('95002','刘勇','女','19','CS') insert into student values('95003','王敏','女','18','MA') insert into student values('95004','张立','男','19','IS') insert into course values('1','数据库',5,4) insert into course values('2','数学',null,2) insert into course values('3','信息系统',1,4) insert into course values('4','操作系统',6,3) insert into course values('5','数据结构',7,4) insert into course values('6','数据处理',null,2) insert into course values('7','PASCAL语言',6,4) insert into sc values('95001','1',92) insert into sc values('95001','2',92) insert into sc values('95001','3',85) insert into sc values('95002','2',90) insert into sc values('95002','3',80) select*from student select*from course select*from sc ```


🎉欢迎来到沃德码🎉

本站发布各种有关编程的博客,包括C/C++、Java、PHP、HTML/CSS、服务端、数据库等,还有其它的一些内容,虽然都比较基础😅 有事没事,来逛逛吧~😉 分享快乐Coding日常😜


小工具

随机字符串生成器


打开