From 367565b051a65b7dd95119623c5f7684979a42f1 Mon Sep 17 00:00:00 2001 From: m1ng <128229751+miam1gh0st@users.noreply.github.com> Date: Wed, 15 Nov 2023 10:15:22 +0800 Subject: [PATCH] Delete c/sourcecode/AlgorithmO/20230911 directory --- .../20230911/Toocold之区间最大子段和.cpp | 201 ------------------ .../AlgorithmO/20230911/公共交通问题.cpp | 62 ------ c/sourcecode/AlgorithmO/20230911/数列游戏.cpp | 70 ------ .../AlgorithmO/20230911/最大子段和-DP方法.cpp | 75 ------- .../AlgorithmO/20230911/最大子段和问题3.c | 51 ----- .../20230911/最大子段和问题(分治法).cpp | 92 -------- .../20230911/最简单的“最大子段和”问题.c | 54 ----- .../20230911/最简单的“最大子段和”问题2.c | 54 ----- .../AlgorithmO/20230911/穿错衣服问题.py | 28 --- c/sourcecode/AlgorithmO/20230911/篮球宝贝.cpp | 59 ----- .../AlgorithmO/20230911/自增自减运算.py | 31 --- .../AlgorithmO/20230911/英语成绩分析.cpp | 48 ----- 12 files changed, 825 deletions(-) delete mode 100644 c/sourcecode/AlgorithmO/20230911/Toocold之区间最大子段和.cpp delete mode 100644 c/sourcecode/AlgorithmO/20230911/公共交通问题.cpp delete mode 100644 c/sourcecode/AlgorithmO/20230911/数列游戏.cpp delete mode 100644 c/sourcecode/AlgorithmO/20230911/最大子段和-DP方法.cpp delete mode 100644 c/sourcecode/AlgorithmO/20230911/最大子段和问题3.c delete mode 100644 c/sourcecode/AlgorithmO/20230911/最大子段和问题(分治法).cpp delete mode 100644 c/sourcecode/AlgorithmO/20230911/最简单的“最大子段和”问题.c delete mode 100644 c/sourcecode/AlgorithmO/20230911/最简单的“最大子段和”问题2.c delete mode 100644 c/sourcecode/AlgorithmO/20230911/穿错衣服问题.py delete mode 100644 c/sourcecode/AlgorithmO/20230911/篮球宝贝.cpp delete mode 100644 c/sourcecode/AlgorithmO/20230911/自增自减运算.py delete mode 100644 c/sourcecode/AlgorithmO/20230911/英语成绩分析.cpp diff --git a/c/sourcecode/AlgorithmO/20230911/Toocold之区间最大子段和.cpp b/c/sourcecode/AlgorithmO/20230911/Toocold之区间最大子段和.cpp deleted file mode 100644 index b436414..0000000 --- a/c/sourcecode/AlgorithmO/20230911/Toocold之区间最大子段和.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* -E. Toocold之区间最大子段和 -Description -Toocold学会了怎样求区间最大子段和,现在他又玩出了新花样.他有n个数,他想知道对于区间的左端点l限定在[ll,rr]之间, 对于区间的右端点r限定在[ll2,rr2]之间的区间最大和是多少? - -Input -输入第一行cas(1<=cas<=10)表示有几个cas - -接下来每个cas的第一行是一个数n(1<=n<=100000)表示有n个数 - -第二行有n个数,a1,a2,a3...an(-1000<=ai<=1000) - -第三行一个数q(1<=q<=100000)表示有q个询问 - -接下来q行每行四个数字ll, rr, ll2, rr2.(1<=ll,rr,ll2,rr2<=n)(ll<=rr)(ll2<=rr2)(rr2>=ll)表示左端点l的范围和右端点r的范围 - -Output -每个询问输出符合范围的区间最大和 - -Sample Input -1 -6 -4 -3 1 -3 5 -2 -2 -1 4 2 5 -1 1 3 4 -Sample Output -4 -2 -*/ -#include -using namespace std; -const int MAXN=100015; -int n,m; -int a[MAXN],pre_sum[MAXN],suf_sum[MAXN],l1,l2,r1,r2; -struct tnode -{ - int sum,lmax,rmax,ans; - int l,r; -}; -tnode operator + (const tnode& a,const tnode& b) -{ - tnode c; - c.l=a.l; - c.r=b.r; - c.sum=a.sum+b.sum; - c.lmax=max(a.lmax,a.sum+b.lmax); - c.rmax=max(a.rmax+b.sum,b.rmax); - c.ans=max(a.ans,b.ans); - c.ans=max(c.ans,a.rmax+b.lmax); - return c; -} -struct Segment_Tree -{ - tnode t[4*MAXN]; - void update(int root) - { - int ch=root<<1; - t[root]=t[ch]+t[ch+1]; - } - void buildt(int root,int l,int r,int A[]) - { - if(l!=r) - { - int mid=(l+r)>>1; - int ch=root<<1; - buildt(ch,l,mid,A); - buildt(ch+1,mid+1,r,A); - update(root); - } - else - { - t[root].ans=t[root].lmax=t[root].rmax=t[root].sum=A[l]; - t[root].l=t[root].r=l; - } - } - tnode query(int root,int l,int r) - { - if(t[root].l==l&&t[root].r==r) - { - return t[root]; - } - int mid=(t[root].l+t[root].r)>>1; - int ch=root<<1; - if(r<=mid)return query(ch,l,r); - else if(l>mid)return query(ch+1,l,r); - else return query(ch,l,mid)+query(ch+1,mid+1,r); - } -}; -Segment_Tree ST1; -struct tnodes -{ - int Max; - int l,r; -}; -struct Segment_Tree_Max -{ - tnodes t[4*MAXN]; - void buildt(int root,int l,int r,int A[]) - { - t[root].l=l; - t[root].r=r; - if(l!=r) - { - int mid=(l+r)>>1; - int ch=root<<1; - buildt(ch,l,mid,A); - buildt(ch+1,mid+1,r,A); - t[root].Max=max(t[ch].Max,t[ch+1].Max); - } - else t[root].Max=A[l]; - } - int query(int root,int l,int r) - { - if(t[root].l==l&&t[root].r==r) - { - return t[root].Max; - } - int mid=(t[root].l+t[root].r)>>1; - int ch=root<<1; - if(r<=mid)return query(ch,l,r); - else if(l>mid)return query(ch+1,l,r); - else return max(query(ch,l,mid),query(ch+1,mid+1,r)); - } -}; -Segment_Tree_Max ST2,ST3; -int get_sum(int l,int r) -{ - if(l>r)return 0; - return pre_sum[r]-pre_sum[l-1]; -} -int main() -{ - int T; - scanf("%d",&T); - while(T--) - { - scanf("%d",&n); - for(int i=1;i<=n;++i) - { - scanf("%d",&a[i]); - } - ST1.buildt(1,1,n,a); - pre_sum[0]=suf_sum[n+1]=0; - for(int i=1;i<=n;++i) - { - pre_sum[i]=pre_sum[i-1]+a[i]; - } - for(int i=n;i;--i) - { - suf_sum[i]=suf_sum[i+1]+a[i]; - } - ST2.buildt(1,1,n,pre_sum); - ST3.buildt(1,1,n,suf_sum); - scanf("%d",&m); - while(m--) - { - scanf("%d %d %d %d",&l1,&r1,&l2,&r2); - if(r1=l1) - { - temp=max(temp,ST3.query(1,l1,l2-1)-pre_sum[n]+ST2.query(1,l2,r2)); - } - if(r1+1<=r2) - { - temp=max(temp,ST2.query(1,r1+1,r2)-pre_sum[n]+ST3.query(1,l1,r1)); - } - printf("%d\n",temp); - } - else if(l1<=l2&&l2<=r2&&r2<=r1)///4 - { - int temp=ST1.query(1,l2,r2).ans; - if(l2-1>=l1) - { - temp=max(temp,ST3.query(1,l1,l2-1)-pre_sum[n]+ST2.query(1,l2,r2)); - } - printf("%d\n",temp); - } - else if(l2<=l1&&l1<=r1&&r1<=r2)///5 - { - int temp=ST1.query(1,l1,r1).ans; - if(r1+1<=r2) - { - temp=max(temp,ST2.query(1,r1+1,r2)-pre_sum[n]+ST3.query(1,l1,r1)); - } - printf("%d\n",temp); - } - } - } - return 0; -} diff --git a/c/sourcecode/AlgorithmO/20230911/公共交通问题.cpp b/c/sourcecode/AlgorithmO/20230911/公共交通问题.cpp deleted file mode 100644 index b5f9dad..0000000 --- a/c/sourcecode/AlgorithmO/20230911/公共交通问题.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* -C. 公共交通问题 -Description -现在的大学生刚毕业不久如果没有家庭的支持一般是买不起心仪的车的,所以刚毕业的人一般都要乘公交车上下班,在早晚的上下班高峰时间段,道路交通很拥挤,每站都有人上下,公交车在每站都停。刚刚毕业的小明常常会被每站都停的公交车弄得很不耐烦,于是他提出了这样一个办法: - -由于公交车的站点并不是非常多,那么在繁忙的上下班高峰时间,每次公交车从始发站点往终点站点开时,我们只允许公交车停在其中的某一个站点。所有乘客都从始发站点上公交车,到达某站点后,公交车停下来,所有乘客再从这里步行到自己的目的站点。在始发站的时候,每个乘客选择自己的目的站点,公交车系统则自动计算出应停的站点。 - -现在请问:公交车停在哪一站点能够保证这次乘坐公交车的所有乘客步行的站点数之和最少? - -在这里为了更好体现算法的魅力所在,我们假定站点数可以很多,每次乘客人数也可以很多(实际生活中这两点是不可能出现的)。另外为了方便起见,在这里我们规定,刚开始公交车在始发站,并且认为乘客至少是在第一个站点及以后才有可能下车。 - -Input -有两行,第一行是公交站点数N(1<=N<=1000),第二行是N个正整数,分别表示对应站点(以该站点作为目的站点)的乘客人数M(1<=M<=1000)。 - -Output -只有一行,输出两个正整数,第一个是计算出来的公交车停靠的站点,第二个是所有乘客需要步行的站点总数,中间有一个空格。如果公交车在不同站点停车都可以让乘客步行站点最少的话,则公交车会停在最先到达的站点,这样可以省些油和时间。 - -本问题有多组测试数据。 - -Sample Input -5 -14 12 2 18 15 -6 -4 9 0 16 16 12 -Sample Output -4 83 -4 70 -*/ -#include -using namespace std; -typedef long long ll; -int a[1010]; -int main() -{ - int n; - while(cin>>n) - { - for(int i=1;i<=n;i++) - { - scanf("%d",&a[i]); - } - int ans=INT_MAX; - int pos=0; - for(int i=1;i<=n;i++) - { - int cnt=0; - for(int j=1;j<=n;j++) - { - cnt+=a[j]*(abs(j-i)); - } - if(cnt -using namespace std; -const int MAXN=1000005; -const long long inf=(1LL<<60); -int n; -long long pre_sum[MAXN],pre_min[MAXN],pre_max[MAXN],ans,a[MAXN]; -int main() -{ - scanf("%d",&n); - for(int i=1;i<=n;i++) - { - scanf("%lld",&a[i]); - pre_sum[i]=pre_sum[i-1]+a[i]; - } - for(int i=1;i<=n;i++) - { - pre_max[i]=max(pre_max[i-1],pre_sum[i-1]); - pre_min[i]=min(pre_min[i-1],pre_sum[i-1]); - ans=max(ans,abs(pre_sum[i]-pre_min[i])); - ans=max(ans,abs(pre_sum[i]-pre_max[i])); - } - printf("%d\n",ans); -} diff --git a/c/sourcecode/AlgorithmO/20230911/最大子段和-DP方法.cpp b/c/sourcecode/AlgorithmO/20230911/最大子段和-DP方法.cpp deleted file mode 100644 index d236bd6..0000000 --- a/c/sourcecode/AlgorithmO/20230911/最大子段和-DP方法.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* -Description -给出N个数字, 计算出最大的子段和。 - -Input -第一行给出一个数字 T(1<=T<=20) 代表接下来的组数. -接下来每 T 行,开始给出一个正整数 N(1<=N<=100000), 接着跟着N个整数.。数据保证中间结果和最后结果都在int范围内。 - -Output -输出最大的子段和 - -Sample Input -2 -5 6 -1 5 4 -7 -7 0 6 -1 1 -6 7 -5 -Sample Output -14 -7 -*/ -#include -using namespace std; -const int MAXN=100005; -int n; -long long a[MAXN],sum,ansum; -pairans; -int main() -{ - int T; - scanf("%d",&T); - while(T--) - { - scanf("%d",&n); - for(int i=1;i<=n;++i) - { - scanf("%lld",&a[i]); - } - bool flag=false; - for(int i=1;i<=n;++i) - { - if(a[i]>=0)flag=true; - } - if(!flag) - { - printf("0\n"); - continue; - } - int pos=0; - ansum=-1; - sum=0; - for(int i=1;i<=n;++i) - { - sum+=a[i]; - if(sum<0) - { - sum=0; - pos=i; - } - else - { - - if(sum>ansum) - { - ansum=sum; - ans=make_pair(pos+1,i); - } - else if(sum==ansum) - { - ans=min(ans,make_pair(pos+1,i)); - } - } - } - printf("%lld\n",ansum); - } - return 0; -} diff --git a/c/sourcecode/AlgorithmO/20230911/最大子段和问题3.c b/c/sourcecode/AlgorithmO/20230911/最大子段和问题3.c deleted file mode 100644 index 3018bd8..0000000 --- a/c/sourcecode/AlgorithmO/20230911/最大子段和问题3.c +++ /dev/null @@ -1,51 +0,0 @@ -/* -C. 最大子段和问题 -Description -给定n个整数(可能为负数)a1,a2,……an。求ai,ai+1,……aj,其中i<=i<=j<=n的子段和的最大值。当所有整数均为负数时我们定义其最大子段和为0(此时From为1,To为n)。例如:当(a1,a2,a3,a4,a5,a6)=(-2,11,-4,13,-5,-2)时,最大子段和为a2+a3+a4=20,i=2,j=4(下标从1开始),这个问题我们称之为“最大子段和问题”。 - -Input -本问题有多组测试数据,每组数据有两行,第一行为n(n<=1000),第二行有n’个整数,数与数之间用空格隔开。 - -Output -参见样例格式 - -Sample Input -6 --2 11 -4 13 -5 -2 -Sample Output -From=2,To=4 -MaxSum=20 -*/ -#include -int a[1001],n,max,from,to,s; - int main() -{ - int i,j,n; - while(1==scanf("%d",&n)) - { - for(i=1;i<=n;i++) - { - scanf("%d",&a[i]); - } - from=1; - to=n; - max=0; - for(i=1;i<=n;i++) - { - s=0; - for(j=i;j<=n;j++) - { - s+=a[j]; - if(max -using namespace std; -const int MAXN=100005; -int n; -long long a[MAXN],sum,ansum; -pairans; -const long long inf=(1LL)<<61; -void div_algorithm(int l,int r) -{ - if(l>r)return; - int mid=(l+r)>>1; - long long lsum=0,rsum=0,lmax=-inf,rmax=-inf; - int lpos,rpos; - for(int i=mid;i>=l;--i) - { - lsum+=a[i]; - if(lmax=0)flag=true; - } - if(!flag) - { - printf("From=0,To=0\nMaxSum=0\n"); - continue; - } - ansum=-1; - sum=0; - div_algorithm(1,n); - printf("From=%d,To=%d\nMaxSum=%lld\n",ans.first,ans.second,ansum); - } - return 0; -} diff --git a/c/sourcecode/AlgorithmO/20230911/最简单的“最大子段和”问题.c b/c/sourcecode/AlgorithmO/20230911/最简单的“最大子段和”问题.c deleted file mode 100644 index f06cf7e..0000000 --- a/c/sourcecode/AlgorithmO/20230911/最简单的“最大子段和”问题.c +++ /dev/null @@ -1,54 +0,0 @@ -/* -A. 最简单的“最大子段和”问题 -Description -给定n个整数(可能为负数)a1,a2,……an。求ai,ai+1,……aj 其中1<=i<=j<=n的子段和的最大值。当所有整数均为负数时我们定义其最大子段和为0。例如:当(a1,a2,a3,a4,a5,a6)=(-2,11,-4,13,-5,-2)时,最大子段和为a2+a3+a4=20,i=2,j=4(下标从1开始)这个问题我们称之为“最大子段和问题”。 - -在课堂上,我们假定n<=100,今天我们把n的范围规定修改为n<=200,你的任务是设计一个程序解决它。 - -Input -输入由两行,第一行为n;第二行为n个整数。 - -Output -输出也有两行,第一行为:“From=xxx,To=xxx”;第二行为:“MaxSum=xxxx”,参见样例。 - -Sample Input -6 --2 11 -4 13 -5 -2 -Sample Output -From=2,To=4 -MaxSum=20 -*/ -#include -int a[1001],n,max,from,to,s; - int main() -{ - int i,j,n; - while(1==scanf("%d",&n)) - { - for(i=1;i<=n;i++) - { - scanf("%d",&a[i]); - } - from=1; - to=n; - max=0; - for(i=1;i<=n;i++) - { - s=0; - for(j=i;j<=n;j++) - { - s+=a[j]; - if(max -int a[1001],n,max,from,to,s; - int main() -{ - int i,j,n; - while(1==scanf("%d",&n)) - { - for(i=1;i<=n;i++) - { - scanf("%d",&a[i]); - } - from=1; - to=n; - max=0; - for(i=1;i<=n;i++) - { - s=0; - for(j=i;j<=n;j++) - { - s+=a[j]; - if(max -using namespace std; -typedef long long ll; - -int main() -{ - int t; - scanf("%d",&t); - int a,b,c; - while(t--) - { - int n,m,l,r; - cin>>n>>m>>l>>r; - int ans=0; - for(int i=0;i>a>>b>>c; - if(m==0)continue; - if(a==0&&b<=r&&b>=l&&c<=2) - { - m--; - } - if(!m) - { - ans=i+1; - } - } - if(!m)cout< -using namespace std; -typedef long long ll; -double a[2010]; - -int main() -{ - int n,t; - scanf("%d",&t); - while(t--) - { - scanf("%d",&n); - double sum=0; - for(int i=0;i