推歌:葬歌/洛天依 by ilem
听凭风引(指\(\textbf{K8He}\)),我打算板刷\(\textbf{ABC}\)的 \(\text{ABCD}\) 题
从ABC的333开始刷啦
-
\(\textbf{ABC333}\)
-
\(\text{Problem:A}\)
-
题意
输出\(n\)个\(n\)
-
思路
按照题意模拟即可
-
代码
没有人曾体会
#include<bits/stdc++.h> inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; signed main(){ int a=read(); for(int i=1;i<=a;i++) cout<<a; }
-
-
\(\text{Problem:B}\)
-
题意
对于给定的图以及两个二元组,判断这两个二元组长度是否相等
-
思路
按照题意打表即可
-
代码
没有人曾了解
#include<bits/stdc++.h> inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; signed main(){ string a,b; int aa,bb; cin>>a>>b; if(a=="AB"||a=="AE"||a=="BA"||a=="EA"||a=="ED"||a=="DE"||a=="DC"||a=="CD"||a=="CB"||a=="BC"){aa=1;} else aa=2; if(b=="AB"||b=="AE"||b=="BA"||b=="EA"||b=="ED"||b=="DE"||b=="DC"||b=="CD"||b=="CB"||b=="BC"){bb=1;} else bb=2; puts((aa==bb)?"Yes":"No"); }
-
-
\(\text{Problem:C}\)
-
题意
找到第\(N\)个小的可以拆=\((1111\cdots+1111\cdots+1111\cdots)\)的数
-
思路
按照题意模拟即可
-
代码
没有人曾感受我喜与悲
#include<bits/stdc++.h> #define int long long inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; priority_queue <int,vector<int>,greater<int> > q; const int N[]={1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111,11111111111,111111111111}; signed main(){ int n=read(),tot=0,ans; while(true){ ++tot; for(int i=1;i<=tot;i++) for(int j=1;j<=i;j++){ if(q.size()==n){while(!q.empty()){ans=q.top();q.pop();}cout<<ans;return 0;} else q.push(N[tot-1]+N[i-1]+N[j-1]); } } }
-
-
\(\text{Problem:D}\)
-
题意
给你一棵树,每次可以删除一个叶子节点,问最少需要多少次才能删掉节点\(1\)
-
思路
既然只能删掉叶子节点,那么考虑让这个树的节点1作=根节点,一直删直到1=叶子节点=止
那么如果一直删,直到其原本的\(N\)的子树只剩余\(N-1\)个=止,此时1就是叶子节点了
那么一个比较自然的想法就是去找到1的所有子树里\(siz\)最大的,然后就可以直接解决了
-
代码
我被肆意踏践
#include<bits/stdc++.h> #define int long long inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; const int N=0X66CCFF; int TO[N],head[N],NEXT[N],tot; inline void add(int x,int y){ TO[++tot]=y; NEXT[tot]=head[x]; head[x]=tot; } class TREE{ public: int son,siz,fa,dep; }T[N]; inline void Dfs(int q){ T[q].son=-1; T[q].siz=1; for(int j=head[q];j;j=NEXT[j]){ if(T[TO[j]].dep) continue; T[TO[j]].dep=T[q].dep+1; T[TO[j]].fa=q; Dfs(TO[j]); T[q].siz+=T[TO[j]].siz; if((T[q].son==-1) || (T[TO[j]].siz>T[T[q].son].siz)) T[q].son=TO[j]; } } signed main(){ // freopen("1.in","r",stdin); int n=read(),ans=0; for(int i=1;i<n;i++){ int x=read(),y=read(); add(x,y);add(y,x); } T[1].dep=1; Dfs(1); for(int j=head[1];j;j=NEXT[j]){ ans=max(ans,T[TO[j]].siz); // cerr<<"SZ:"<<T[TO[j]].siz<<endl; } cout<<n-ans; }
-
RE:从零开始的ABC333写ABCD题生活,堂堂完结
-
-
\(\textbf{ABC332}\)
-
\(\text{Problem:A}\)
-
题意
这里有 N 件商品,第 i 件商品价格= Pi ,你要购买 Qi 件,除了购买的费用外还要支付运费。
如果购买的总价大于等于 S 则免运费
-
思路
按照题意模拟即可
-
代码
丢弃全部尊严
#include<bits/stdc++.h> #define int long long inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; const int N=0X66CCFF; signed main(){ int n=read(),m=read(),q=read(),ans=0; while(n--){ ans+=read()*read(); } cout<<((ans<m)?ans+q:ans); }
-
-
\(\text{Problem:B}\)
-
题意
懒得翻译了
-
思路
按照题意模拟即可
-
代码
人们路过笑过骂过
#include<bits/stdc++.h> #define int long long inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; const int N=0X66CCFF; signed main(){ int n=read(),m=read(),k=read(),a=0,b=0; for(int i=1;i<=n;i++){ if(a==m) a=0; else if(b==0) b=k; else{ if(a+b>m){ int ans=a+b; a=m; b=ans-a; } else{ a=a+b; b=0; } } } cout<<a<<" "<<b; }
-
-
\(\text{Problem:C}\)
-
题意
给定一个 \(N\) 天的日程表 \(S\),现在你有 \(M\) 件普通T恤衫。
对于日程表的每一天 \(S_i\):
-
\(S_i\) = \(0\),你可以洗掉所有的T恤衫。
-
\(S_i\) = \(1\), 你需要穿一件普通T恤或者一件有标志的T恤衫。
-
\(Si\) = \(2\),你需要穿一件有标志的T恤衫。
T恤衫在被洗过之前只能穿一次。
请你求出至少需要再准备几件有标志的T恤衫。
-
-
思路
这个好像是贪心,但是其实只要尽量穿普通的,没普通的就穿有标志的即可了
-
代码
不留一声抱歉
#include<bits/stdc++.h> #define int long long inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; const int N=0X66CCFF; int n,x,y,a,b; int a[N]; signed main(){ n=read(),x=read(); for(int i=1;i<=n;i++){ char qwq=getchar(); if(qwq<=' ') qwq=getchar(); a[i]=qwq-'0'; } a=x,b=0; for(int i=1;i<=n;i++){ if(!a[i]) a=x,b=y; else if(a[i]==1) if(!b&&!a)y++; else if(!b)a--; else if(!a)b--; else a--; else if(!b)y++; else b--; } cout<<y; }
-
-
\(\text{Problem:D}\)
-
题意
给定两个 \(n×m\) 的矩阵 \(A\) 和 \(B\)。
你每次可以交换矩阵 \(A\) 的相邻两行中的所有元素或是交换两列中的所有元素。
请问要使 \(A\) 变换至 \(B\) 至少需要几步操作?
如果无法变换至 \(B\),则输出 \(-1\)。
-
思路
直接大力DFS?好像不太需要,直接对其全排列然后模拟乱搞
最开始WA了,经过\(\text{The-shadow-dragon}\)大人的指导发现需要
do-while
-
代码
我等着你诬蔑
#include<bits/stdc++.h> #define int long long inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; const int INF=0X66CCFF0712; int a[10][10],b[10][10],x[10],y[10],n,m,ans=INF; signed main(){ n=read(),m=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) a[i][j]=read(); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) b[i][j]=read(); for(int i=1;i<=n;i++) x[i]=i; do{ for(int i=1;i<=m;i++) y[i]=i; do{ bool f=1; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i][j]!=b[x[i]][y[j]]) f=0; if(f){ int val=0; for(int i=1;i<=n;i++) for(int j=i+1;j<=n;j++) if(x[i]>x[j]) val++; for(int i=1;i<=m;i++) for(int j=i+1;j<=m;j++) if(y[i]>y[j]) val++; ans=min(ans,val); } }while(next_permutation(y+1,y+m+1)); }while(next_permutation(x+1,x+n+1)); if(ans==INF) puts("-1"); else cout<<ans; }
-
-
-
\(\textbf{ABC331}\)
-
\(\text{Problem:A}\)
-
题意
每年有 \(M\) 个月,每个月有 \(D\) 天。
求 \(y\) 年 \(m\) 月 \(d\) 日的下一天的日期。
-
思路
按照题意模拟即可
-
代码
我看着你诬陷
#include<bits/stdc++.h> #define int long long inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; const int INF=0X66CCFF0712; int M,D; signed main(){ M=read(),D=read(); int y=read(),m=read(),d=read(); d=d+1; if(d>D){ m++; d-=D; } if(m>M){ y++; m-=M; } cout<<y<<" "<<m<<" "<<d; }
-
-
\(\text{Problem:B}\)
-
题意
在超市里,一包 \(6\) 个鸡蛋卖 \(S\) 元,一包 \(8\) 个鸡蛋卖 \(M\) 元,一包 \(12\) 个鸡蛋卖 \(L\) 元。
你想买至少 \(N\) 个鸡蛋,请问你至少需要花多少钱。
-
思路
按照题意模拟即可,大量套循环
-
代码
我观赏这喜剧是你导演
#include<bits/stdc++.h> #define int long long inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; const int INF=0X66CCFF0712; int M,D; signed main() { int n=read(),s=read(),m=read(),l=read(); int ans=INF; for(int i=0;i<n+1;i++) for(int j=0;j<n+1;j++) for(int k=0;k<n+1;k++){ if(i*6+j*8+k*12<n) continue; int c=i*s+j*m+k*l; ans=min(ans,c); } cout<<ans; }
-
-
\(\text{Problem:C}\)
-
题意
给你一个长度为 \(N\) 的序列 \(A=(A_1,…,A_N)\)。 对于每个 \(i=1,…,N\) 求出 \(A\) 中所有大于 \(A_i\) 的元素之和。
-
思路
前缀和+二分查找直接过了
-
代码
即分不清现实
#include<bits/stdc++.h> #define int long long inline int read(){ int s=0,f=1;char ch=getchar(); while(ch<'0'||'9'<ch){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&'9'>=ch){s=s*10+ch-'0';ch=getchar();} return f*s; } using namespace std; const int INF=0X66CCFF0712; const int N=0x66CCFF; int sqn; int n,a[N],b[N],sum[N]; signed main() { n=read(); for(int i=1;i<=n;i++){ a[i]=read(); b[i]=a[i]; } sort(b+1,b+1+n); for(int i=1;i<=n;i++) sum[i]=sum[i-1]+b[i]; for(int i=1;i<=n;i++){ int l=upper_bound(b+1,b+1+n,a[i])-b; cout<<sum[n]-sum[l-1]<<" "; } }
-
-
\(\text{Problem D}\)
去打新的ABC了,先不改了
-