自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(35)
  • 收藏
  • 关注

原创 题解 p1049【装箱问题】

0.前言最开始用贪心水了一发,拿了80分,下个数据特判后就AC了(手动狗头)1.正文题目解析题目中“使剩余空间最小”转化一下,其实就是求总体积最大值,不难看出是01背包。注意点最后答案记得相减求最小值。代码实现贪心(参见前言),直接排序累加(题目的数据点也太水 了,竟然让我水到了80分/4个数据点)。dp,套个01背包模板(一维数组优化版),稍微改动一下即可,实现原理可参考我的这篇博客中的代码实现。Code#include<cstdio>#include&lt

2022-02-12 10:58:54 405

原创 题解 p1567【统计天数】

1.正文#include <iostream>using namespace std;int main(){// freopen("work.in","r",stdin);freopen("work.out","w",stdout); int n,i,f,l=0,s=0,maxn=0; cin >> n; for(i=1;i<=n;i++) { cin >> f; if(f > l) s++; else { if(s

2022-02-12 10:57:42 281

原创 题解 p5707【【深基2.例2】上学迟到】

0.前言蒟蒻靠自己的思路AC了一道水题!虽然思路不是最佳解,但只要过了就是好解!1.正文Code#include <iostream>using namespace std;int main(){// freopen("work.in","r",stdin); freopen("work.out","w",stdout); int s,v,x,y,h,m; int sum = 10; cin >> s >> v; if(s%v != 0) su

2022-02-12 10:56:37 392

原创 题解 p1614【爱与愁的心痛】

0.正文#include <iostream>#include <algorithm>using namespace std;int mins=0x7ffff,a[3005];int main(){// freopen("work.in","r",stdin); freopen("work.out","w",stdout); int i,j,n,m,s=1; cin >> n >> m; for(i=0;i<n;i++) cin

2022-02-12 10:55:49 423

原创 题解 UVA11292【Dragon of Loowater】

1.正文#include <cstdio>#include <iostream>#include <algorithm>using namespace std;const int N=20000;int d[N+5],x[N+5];int main(){ int n,m; while(scanf("%d%d",&n,&m) == 2 && n && m) { int i,j; for(i=

2022-02-12 10:53:14 286

原创 【笔记】快速幂

0、前言大家看到幂的次方,肯定会想:“一个暴力循环解决。”于是,暴力循环的 代码 如下:(此时 n,m 均为正整数且是 int 类型)int i;int res = 1;for(i=0;i<m;i++) res*=n;另一种:(蒟蒻作者只知道两种暴力做法QwQ)#include <cmath>int res = pow(n,m);注意:powpowpow 返回的值是 double 类型。但是暴力太慢,会 TLETLETLEpowpowpow 不实用于是,

2022-02-12 10:52:04 241

原创 【笔记】排序

0.前言排序大法好啊!1.正文快速排序#include <cstdio>using namespace std;int a[1000001];void swap(int &a,int &b) { int temp=a; a=b; b=temp; }void cmpswap(int &a,int &b) { if(a > b) swap(a,b); }void qsort(int a[],int l,int r){ if(l

2022-02-12 10:49:44 79

原创 【笔记】素数筛

0.前言写篇博客凑数doge1.正文首先是朴素算法,直接爆栗枚举,如果除得尽,就是合数,反之是素数。一个小小的优化:枚举范围从2(因为所有正整数数都是1的倍数)到n\sqrt{n}n​即可(因为如果有比n\sqrt{n}n​更大的因数,那该因数一定能和之前一个比n\sqrt{n}n​小的n的因数配对)。int pd(int x){ for (int i = 2; i <= sqrt(x); i++) if (x%i == 0) return 0; return 1;}上

2022-02-12 10:48:39 201

原创 【笔记】前缀和

0.前言中午在做的时候,发现不会前缀和,写篇博客凑数记一下。1.正文学习资料前缀和:一个数组的某项下标之前(包括此项元素)的所有数组元素的和。设 b[]为前缀和数组,a[]为原数组。表格打LaTeX公式好麻烦幸好有图片2.结语这篇博客就这么敷衍地写完了因为还不会用前缀和,多多思考,多多学习。目前做到用到前缀和的题目p1865...

2022-02-12 10:46:56 161

原创 【笔记】判断回文数

0.前言写这道题的时候,不会判断回文数,于是记录下来。参考资料1.正文第一种方法:数值翻转,直接判断翻转后的数是否与翻转前的数相等int hw(int x) { if (x < 0) return 0; int t = x, c = 0; while (t > 0) { c = c*10 + t%10; t /= 10; } return c == x;}2.结语等有时间再更完剩下的方法吧~...

2022-02-12 10:45:47 146

原创 题解 P1104 【生日】

0.前言sort是个好东西1.正文本题其实挺简单,要用到的就是结构体和快排;一开始作者是这么想:#include <iostream>#include <string>#include <algorithm>using namespace std;//结构体存储学生的名字,出生年月日struct Student{ string name; int year, month, day;}person[110];//重点都在cmpint cmp

2022-02-11 12:12:05 256

原创 题解 CF76D 【Plus and xor】

0.前言楼上的大佬们已经讲得很清楚了;本蒻的思路和大佬们差不多;1.正文直接给代码:#include <set> #include <map> #include <list> #include <queue> #include <stack> #include <string> #include <math.h> #include <time.h> #include &l

2022-02-11 12:10:54 144

原创 题解 CF174A 【Problem About Equation】

0.前言PYTHON 题解1.正文思路如下:max 找出 water 中最大值sum 求出 water 总量如果 水总量 + 瓶子水量 小于 最大值 * 杯子数,证明瓶子水量不够分,输出“-1”求出 相等水量,即可得到 每杯水需要的加水量代码如下:maxn = 0num, bottle = map(int, input().split())water = list(map(int, input().split()))summ = sum([i for i in water])

2022-02-11 12:09:35 558

原创 题解 P1416 【攻击火星】

一行代码如何 /滑稽print(max(int(input()) - 2, 0))

2022-02-11 12:08:27 206

原创 题解 P1708 【天然气井】

0.前言来混题解了qwq1.正文过程观察样例可知最短的连接管道长度=绝对值(气井XXX坐标和−-−站XXX坐标和)+ (气井YYY坐标和−-−站YYY坐标和)注意注意开 long long,否则WA掉代码#include <bits/stdc++.h>using namespace std;long long sum_a, sum_b;int main(){ long long n, i, x, y; scanf("%lld", &n); for (i

2022-02-11 12:07:53 186

原创 题解 P1223 【排队接水】

0.前言小学奥数1.正文总时间 = a[i]∗(n−i)a[i]*(n-i)a[i]∗(n−i);代码很简单,就不贴了;但是!第一遍WA了两个点(写这篇文章的原意);数据类型的锅(甩锅高手总和应该是double类型;2.结语下次不能写错数据类型!...

2022-02-11 12:06:54 287

原创 题解 P1177 【【模板】快速排序】

0.前言贴板子~1.正文#include <cstdio>using namespace std;int a[1000001];void swap(int &a,int &b){ int temp=a; a=b; b=temp;}void cmpswap(int &a,int &b){ if(a>b) swap(a,b);}void qsort(int a[],int l,int r){ if(l>=r) return

2022-02-11 12:05:32 149

原创 题解 P1824 【进击的奶牛】

0.前言窝又双叒叕来贴笔记了~1.正文依题意隔间分布在一条直线上.所有牛中相邻两头的最近距离越大越好.典型二分答案题目(算法标签有代码#include <cstdio>#include <algorithm>using namespace std;int n,c,l=1,r,mid;int xy[100005];int max(int a,int b) { return a>b?a:b;}bool judge(int x) {

2022-02-11 12:04:26 515

原创 题解 P1767 【家族】

0.前言大水题1.正文基本思路如果不为字母,标记为 0;如果是字母,标记为 1;大法师 dfs 解决连通块问题,标记为 1 就搜索,上下左右方向各搜一遍;实现代码#include <iostream>#include <string>using namespace std;int n,cnt;string s;int l[505],bk[505][505]; // 数组开大点总煤问题int dx[4]={0,1,0,-1}; // 方向

2022-02-11 12:02:57 152

原创 题解 CF1395A 【Boboniu Likes to Color Balls】

正文具体思路形成回文串条件:1奇3偶 或 3奇1偶 或 全部为奇数或偶数无法形成条件:2奇2偶r,g,br,g,br,g,b 中任意一个为 0代码如下#include <cstdio>using namespace std;int main() { long long n,r,g,b,w,cnt; scanf("%lld",&n); for(int i=1;i<=n;i++) { scanf("%lld %lld %lld %lld"

2022-02-11 12:01:51 100

原创 题解 P2242 【公路维修问题】

正文具体思路直接将间隔的长度存入 L 数组,然后排序,循环 n-m 次将长度累计至 res,最后输出 res+m 即可。代码#include <cstdio>#include <algorithm>using namespace std;const int MAXN = 15000;int res, N[MAXN+5], L[MAXN+5];int main() { int n, m; scanf("%d %d %d", &n, &m, &a

2022-02-10 17:47:32 291

原创 题解 P1160 【队列安排】

0.前言老师布置的作业题。有点水1.正文具体思路数组实现简单的双链表操作:插入、删除。注意事项删除时记得标记,已不在队列中的忽略。代码#include <cstdio>const int N = 100000;int idx, e[N+5], fr[N+5], ne[N+5];void init(){ idx = 2; fr[1] = 0; ne[0] = 1;}void insertL(int k, int x){ fr[idx] = fr[k]

2022-02-10 17:46:14 423

原创 题解 P1082【同余方程】

0.前言笑死直接代码1.正文#include <cstdio>int a,b,x,y,k;void exgcd(int a,int b) { if (!b) { x=1; y=0; return; } exgcd(b,a%b); k=x; x=y; y=k-a/b*y; return;}int main() { scanf("%d %d",&a,&b); exgcd(a,b); printf("%d",(x+b)%b); re

2022-02-10 17:44:33 84

原创 题解 P1513 【绕钉子的长绳子】

正文挺好想的,答案就是一个圆的周长加各条边的和。因为第n条边到第1条边比较难计算,所以提前拿出来计算。#include <cmath>#include <cstdio>struct Point { double x; double y;}point[105];int n;double r;const double pi = 3.1415926535;double dis(Point a, Point b) { return sqrt(pow(a.x-b

2022-02-10 17:43:09 192

原创 题解 P6850 【NOI】

0.前言这道题连我这种蒟蒻都可以AC,那就是真的水。1.正文总分=50+a+b+c+d+e+f+g,如果是A类,还要再加上5分。最后判断即可。#include <cstdio>#include <iostream>using namespace std;int main() { int sum = 50; int t1, t2, t3, t4, t5, t6, t7, t8, t9; cin >> t1 >> t2 >> t

2022-02-10 17:41:56 225

原创 题解 UVA12917 【Prop hunt】

0.前言没错,就是来水题解的。1.正文既然大家公认水了,就直接上代码吧。#include <iostream>using namespace std;int main(){ int p,h,o; while (cin>>p>>h>>o) { if(p<=o-h) cout<<"Props win!"<<endl; else cout<<"Hunters win!"<<endl;

2022-02-10 17:41:09 125

原创 题解 UVA11729【Commando War】

0.前言题外话:UVA题目真的waiting好久啊。1.正文“不能同时给两个部下交代任务,但部下们可以同时执行他们各自的任务。”因为如果前一位部下的执行时间较长,那么就可以覆盖下一位部下的部分时间,即可节省时间。而如果前一位的执行时间较短,覆盖下一位的部分时间也会短,相比上面的方法,总时间较长。那么直接将执行时间从大到小排一遍,依次交待即可。代码:#include<cstdio>#include<iostream>#include<algorithm&gt

2022-02-10 17:36:59 325

原创 笔记【数组去重】

0.前言由于作者太蒻,只能发些没有水平的博文QWQ1.正文数组去重就是把一个数组中重复的元素去除 大家肯定知道例://去重前input:5 5 2 1 3 4 3 2//去重后output:5 2 1 3 4数组去重的基本方法就是:定义新数组,与原数组比较,将单一无重复元素放入新数组。CODE:#include <iostream>using namespace std;int main(){ int a[10] = { 0,1,1,0,2,3,2,

2022-02-10 17:34:33 134

原创 笔记【二分查找】

致谢Just now, 幸得各位大佬(违规用户名1A8F1D09、血色黄昏、Callous_Murder)相助,才将我快飞掉的二分查找拽回来,万分感谢。同时,也给我极大的教训( 不能只看老师的课件?!).笔记#include <cstdio>using namespace std;int a[1000005];int n,m,l,r,mid,ans,num;int search(int x) { l=1,r=n ; while(l<=r) {

2022-02-10 17:30:25 420

原创 停更

原因:濒临开学,自然有开学考;作者的副科并不优秀,需恶补;作业也很多;By the way:开学后作者只能周更;

2020-04-25 10:27:00 142

原创 题解 P1165 【日志分析】

前言作者昨天废了(别问,问就是作业煤写完正文原题(依旧是水题基本思路将仓库看做 栈;0 X 为入栈;1 出栈;2 得出 栈 中最大值;int stack[10005];void push(int x) { stack[++top] = x; } // 入栈void pop() { top--; } // 出栈void calc() { maxn = max(max...

2020-04-23 21:57:47 266

原创 题解 T129980 【素数对】

原题基本思路埃氏筛,求出 2~n 中的所有素数;bool isprime[10005];void esPrime(int n){ memset(isprime, true, sizeof(isprime)); isprime[1] = false; for (int i = 2; i*i <= n; i++) { if (isprime[i]) { fo...

2020-04-21 15:30:49 228

原创 题解 P5706【【深基2.例8】再分肥宅水】

原题煤错就是来凑文章的完整代码#include <cstdio>int stu;double t;void input_calc(){ // input scanf("%lf %d", &t, &stu); // calc printf("%.3lf\n%d\n", t/stu, 2*stu);}int main(){ input_...

2020-04-20 12:30:32 609

原创 题解 CF1337B 【Kana and Dragon Quest game】

原题基本思路先进行 空洞吸收 的操作,得到加血后的血量;while ((x/2+10)<=x && (n!=0)){ x = x/2+10; n--;}而后判断 雷击 是否能将现在的龙击败;if (m*10 >= x) printf("YES\n");else printf("NO\n");完整代码#include <cst...

2020-04-20 12:14:18 205

转载 读写文件

读取文件r 模式表示读取文件;Python 引用 with 语句自动调用 close() 用法 (人性化无疑:with open('/path/to/file/', 'r') as f: # r模式读取文件(文件名:f) f.read() # read()读取文件内容read() 会一次读取文件全部内容。如果文件有20G,内存直接爆炸。保险起见建议调用 read(size) :...

2020-04-17 13:03:47 248

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除