复习。
一.倒计时79天-CSDN博客
1.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
void solve()
{int a[110]={},cn=0;for(int i=0;i<100;i++)cin>>a[i];for(int i=1;i<=12;i++){for(int j=1;j<=month[i];j++){string s="2023";if(i<10)s+='0';s+=to_string(i);if(j<10)s+='0';s+=to_string(j);int k=0;for(int i=0;i<100;i++){if(a[i]==s[k]-'0')++k;if(k==8){cn++;break;}}}}cout<<cn;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
2.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
int month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
void solve()
{int cn=0;for(int i=1;i<=12;i++){for(int j=1;j<=month[i];j++){string s="2022";if(i<10)s+='0';s+=to_string(i);if(j<10)s+='0';s+=to_string(j);//20220101for(int k=1;k<7;k++){if(s[k]-s[k-1]==1&&s[k+1]-s[k]==1){cn++;break;}}}}cout<<cn;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
3.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;
int a[N], b[N];
map<int, int>mp;void solve() {int n, cn = 0;cin >> n;for (int i = 0; i < n; i++) {cin >> a[i];b[i] = a[i];mp[a[i]] = i;}sort(a, a + n);for (int i = 0; i < n; i++) {if (a[i] != b[i]) {mp[b[i]] = mp[a[i]];b[mp[a[i]]] = b[i];b[i] = a[i];cn++;}}cout << cn;
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
4.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;int gcd(int a, int b) {if (a < b)swap(a, b);int c;while (c) {c = a % b;a = b;b = c;}return a;
}void solve() {int a, b;cin >> a >> b;cout << gcd(a, b);
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
5.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+5;
const int inf=0x3f3f3f3f;
int a[N],b[N];
bool cmp(int x,int y)
{return b[x]<b[y];
}
void solve()
{int n;cin>>n;for(int i=0;i<n;i++){cin>>a[i];b[a[i]]=i;}int m;cin>>m;int l=0,r=n;for(int i=0;i<m;i++){string s;int c;cin>>s>>c;if(s=="FIRST")b[c]=--l;else b[c]=++r;}sort(a,a+n,cmp);for(int i=0;i<n;i++){cout<<a[i]<<' ';}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
6.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
int k;
struct cmp{bool operator()(const int &a,const int &b){if(abs(a-b)<=k)return false;//别忘了绝对值,n次了,又忘了╥﹏╥...return a<b;}
};
set<int,cmp>se;
void solve()
{int m;cin>>m>>k;for(int i=0;i<m;i++){string s;int x;cin>>s>>x;if(s=="add"){se.insert(x);}else if(s=="del"){se.erase(x);}else{if(se.find(x)!=se.end()){cout<<"Yes"<<endl;}else cout<<"No"<<endl;}}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
7.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;
stack<int>st;void solve() {int m, n;cin >> m >> n; //m->n进制while (m) {int c = m % n;st.push(c);m /= n;}while (st.size()) {cout << st.top();st.pop();}
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;
stack<int>st;void solve() {int m, n;cin >> m >> n; //m->n进制char str[220];_itoa(m, str, n);cout << str;
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;
void solve() {string a;cin >> a; //二进制到十进制int sum=0;int le=a.size();for(int i=0;i<le;i++){if(a[i]=='1'){sum+=pow(2,le-i-1);}}cout<<sum;
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
8.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;
void solve() {int n,a,b,mx=-inf;cin>>n;for(int i=0;i<n;i++){cin>>a;if(i==0)b=a;else b=max(a+b,b);mx=max(mx,b);}cout<<mx;
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
9.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;void solve() {int t;cin >> t;while (t--) {vector<int>ve;int n;cin >> n;for (int i = 1; i <= n; i++) {ve.push_back(i);}int flag = 0;while (ve.size() > 3) {if (flag == 0) {flag = 1;for (int i = 1; i < ve.size(); i++) {//是小于ve.size(),不是n或小于等于,不然会溢出ve.erase(ve.begin() + i, ve.begin() + i + 1);}} else {flag = 0;for (int i = 2; i < ve.size(); i += 2) {ve.erase(ve.begin() + i, ve.begin() + i + 1);}}}for (auto i : ve)cout << i << ' ';cout << endl;}
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
10.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;void solve() {int n;while(cin>>n&&n){string s1,s2;set<string>se1,se2;for(int i=0;i<n;i++){cin>>s1>>s2;se1.insert(s1),se1.insert(s2);//所有人se2.insert(s2);//失败者}if(se1.size()-se2.size()==1)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
11.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
const int inf=0x3f3f3f3f;
int aa[N];
void solve()
{int n,m,a,b=0,cn=0;cin>>n>>m;for(int i=1;i<=n;i++){cin>>a;if(a!=b){++cn;b=a;}aa[i]=cn;}for(int i=1;i<=m;i++){int l,r;cin>>l>>r;cout<<aa[r]-aa[l]+1<<endl;}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
12.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
priority_queue<int,vector<int>,greater<int> >qu;
void solve()
{int q,y=0;cin>>q;while(q--){int m,x;cin>>m;if(m==1){cin>>x;qu.push(x-y);}else if(m==2){cout<<qu.top()+y<<endl;qu.pop();}else{cin>>x;y+=x;}}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
13.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;
set<string>se;
void solve()
{string s,word;while(cin>>s){for(int i=0;i<s.size();i++){if(isalpha(s[i]))s[i]=tolower(s[i]);else s[i]=' ';}stringstream ss(s);while(ss>>word){se.insert(word);}}for(auto i:se)cout<<i<<endl;
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
14.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;void solve() {//vectorvector<int>ve = {1, 3, 3, 6, 15};int tag = 3;cout << lower_bound(ve.begin(), ve.end(), tag) - ve.begin() << endl;//mapmap<int, int>mp = {{1, 2}, {1, 1}, {3, 1}, {2, 4}, {4, 5}};auto it = mp.lower_bound(2);cout << it->first << ' ' << it->second << endl;
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
例:C-又放学辣(简单)_牛客小白月赛80 (nowcoder.com)
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
int k;
map<int,int>mp;
bool check(int mid,int i)
{int cn=0;for(auto x:mp){cn+=max(0ll,x.second-mid);}if(mp[i]>=mid)cn-=(mp[i]-mid);if(cn>k)return false;else return true;
}
void solve()
{int n,m,a;cin>>n>>m>>k;for(int i=0;i<n;i++){cin>>a;mp[a]++;}for(int i=1;i<=m;i++){if(n-k<mp[i]){cout<<-1<<' ';continue;}int l=0,r=n;while(l<r){int mid=(l+r)>>1;if(check(mid,i))r=mid;else l=mid+1;}cout<<l<<' ';}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
二.倒计时78天-CSDN博客
1.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
int a[110][110],b[110][110];
struct node{int x,y,step;
};
queue<node>qu;
void solve()
{int n,m;cin>>n>>m;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}int sx,sy,ex,ey,st=0;cin>>sx>>sy>>ex>>ey;qu.push({sx,sy,st});b[sx][sy]=1;while(!qu.empty()){int mx=qu.front().x,my=qu.front().y;if(mx==ex&&my==ey){cout<<qu.front().step;break;}for(int i=0;i<4;i++){int rx=mx+dir[i][0],ry=my+dir[i][1];if(rx>=1&&rx<=n&&ry>=1&&ry<=m&&a[rx][ry]==1&&b[rx][ry]==0){node ww;b[rx][ry]=1;ww.x=rx,ww.y=ry,ww.step=qu.front().step+1;qu.push(ww);}}qu.pop();}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
/*
输入:
5 4
1 1 2 1
1 1 1 1
1 1 2 1
1 2 1 1
1 1 1 2
1 1 4 3
输出:
7
*/
2.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
string s[510];
int r[510][510];
int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
typedef pair<int,int> pii;
int n,m;
void bfs(int i,int j)
{queue<pii>qu;memset(r,0,sizeof r);bool flag=0;qu.push({i,j});while(!qu.empty()){int rx=qu.front().first,ry=qu.front().second;r[rx][ry]=1;if(s[rx][ry]=='E'){cout<<"Yes"<<endl;flag=1;break;}for(int i=0;i<4;i++){int zx=rx+dir[i][0],zy=ry+dir[i][1];if(zx>=0&&zx<n&&zy>=0&&zy<m&&r[zx][zy]==0&&s[zx][zy]!='#'){r[zx][zy]=1;qu.push({zx,zy});}}qu.pop();}if(flag==0)cout<<"No"<<endl;
}
void solve()
{while(cin>>n>>m){for(int i=0;i<n;i++)cin>>s[i];for(int i=0;i<n;i++){for(int j=0;j<m;j++){if(s[i][j]=='S'){bfs(i,j);}}}}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
3.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
string s[1100];
int ss[1100][1100];
int dir[4][2]={{0,1},{1,0},{-1,0},{0,-1}};
typedef pair<int,int> pii;
queue<pii>qu;
int ans=0;
int n,m;
void bfs(int i,int j)
{int cn=1;set<int>se1,se2;qu.push({i,j});while(!qu.empty()){int sx=qu.front().first,sy=qu.front().second;se1.insert(sx),se2.insert(sy);ss[sx][sy]=1;for(int i=0;i<4;i++){int zx=sx+dir[i][0],zy=sy+dir[i][1];if(zx>=0&&zx<n&&zy>=0&&zy<m&&ss[zx][zy]==0&&s[zx][zy]!='*'){ss[zx][zy]=1;s[zx][zy]='*';++cn;qu.push({zx,zy});se1.insert(zx),se2.insert(zy);}}qu.pop();}if(se1.size()*se2.size()==cn)ans++;
}
void solve()
{cin>>n>>m;for(int i=0;i<n;i++)cin>>s[i];for(int i=0;i<n;i++) {for(int j=0;j<m;j++){if(s[i][j]=='.'){bfs(i,j);}}}cout<<ans;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
4.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
string s1[4],s2[4];
typedef pair<int,int> pii;
int n;
vector<int>ve1,ve2;
int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{-1,-1},{1,-1},{-1,1}};
void bfs1(int i,int j)
{queue<pii>qu;qu.push({i,j});int cn1=1;while(!qu.empty()){int sx=qu.front().first,sy=qu.front().second;qu.pop();for(int i=0;i<8;i++){int rx=sx+dir[i][0],ry=sy+dir[i][1];if(rx>=0&&rx<4&&ry>=0&&ry<n&&s1[rx][ry]=='*'){s1[rx][ry]='.';cn1++;qu.push({rx,ry});}}}ve1.push_back(cn1);
}
void bfs2(int i,int j)
{queue<pii>qu;qu.push({i,j});int cn2=1;while(!qu.empty()){int sx=qu.front().first,sy=qu.front().second;qu.pop();for(int i=0;i<8;i++){int zx=sx+dir[i][0],zy=sy+dir[i][1];if(zx>=0&&zx<4&&zy>=0&&zy<n&&s2[zx][zy]=='*'){s2[zx][zy]='.';++cn2;qu.push({zx,zy});}}}ve2.push_back(cn2);
}
void solve()
{cin>>n;for(int i=0;i<4;i++)cin>>s1[i];for(int i=0;i<4;i++)cin>>s2[i];for(int i=0;i<4;i++){for(int j=0;j<n;j++){if(s1[i][j]=='*'){s1[i][j]='.';bfs1(i,j);}}}for(int i=0;i<4;i++){for(int j=0;j<n;j++){if(s2[i][j]=='*'){s2[i][j]='.';bfs2(i,j);}}}sort(ve1.begin(),ve1.end());//司机sort(ve2.begin(),ve2.end());//齐齐if(ve1.size()>ve2.size())cout<<-1;else{int sum=0;for(int i=ve2.size()-1;i>=0&&i>=ve1.size()-1;i--)//i要>=0,注意!!!{sum+=ve2[i];}cout<<sum;}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
...........................脑子转不动了(((φ(◎ロ◎;)φ)))...............待续。。。。。。.......................................
5.//还是超时。。。。。。
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e4 + 5;
const int inf = 0x3f3f3f3f;struct node {int x, y, r;
} row[N];bool check(int x1, int y1, int x2, int y2, int d) {if ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) <= d * d)return true;return false;
}void solve() {int n, m, cn = 0;cin >> n >> m;for (int i = 0; i < n; i++) { //炸雷cin >> row[i].x >> row[i].y >> row[i].r;}queue<node>qu;for (int i = 0; i < m; i++) { //炸雷火箭int xx, yy, rr;cin >> xx >> yy >> rr;qu.push({xx, yy, rr});}while (!qu.empty()) {int zx = qu.front().x;int zy = qu.front().y;int zr = qu.front().r;for (int i = 0; i < n; i++) {if (row[i].x != -1 && check(zx, zy, row[i].x, row[i].y, zr)) {qu.push({row[i].x, row[i].y, row[i].r});row[i].x = -1;cn++;}}qu.pop();}cout << cn;
}signed main() {ios_base::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);solve();return 0;
}
6.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
int v[N],w[N],s[N];//数组只要不太大,越大越好
void solve()
{int n,V,ans=0;cin>>n>>V;for(int i=0;i<n;i++){int v1,w1,s1,k=1;cin>>v1>>w1>>s1;while(k<=s1){ans++;v[ans]=v1*k;w[ans]=w1*k;s1-=k;k*=2;//二进制转换}if(s1>0){ans++;v[ans]=v1*s1;w[ans]=w1*s1;}}for(int i=1;i<=ans;i++){for(int j=V;j>=v[i];j--){s[j]=max(s[j],s[j-v[i]]+w[i]);}}cout<<s[V];
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
7.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
int v[N],w[N],s[N];
void solve()
{int n,V,ans=0;cin>>n>>V;while(n--){int p,q,r;cin>>p>>q>>r;int k=1;if(r==-1)r=1;else if(r==0)r=V/p;while(k<=r){ans++;v[ans]=p*k;w[ans]=q*k;r-=k;k*=2;}if(r>0){ans++;v[ans]=p*r;w[ans]=q*r;}}for(int i=1;i<=ans;i++){for(int j=V;j>=v[i];j--){s[j]=max(s[j],s[j-v[i]]+w[i]);}}cout<<s[V];
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
8.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e4+5;
const int inf=0x3f3f3f3f;
int counting(int a,int b,int mod)
{int result=1;while(b){if(b&1){result=result*a%mod;a=a*a%mod;b/=2;}else{a=a*a%mod;b/=2;}}return result;
}
void solve()
{int t,a,b,p;cin>>t;while(t--){cin>>a>>b>>p;cout<<counting(a,b,p)<<endl;}
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}
9.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e3+5;
const int inf=0x3f3f3f3f;
int a[N][N],b[N][N];
void solve()
{int n,m,k,cn=0;cin>>n>>m>>k;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];b[i][j]=b[i][j-1]+a[i][j];}}for(int j1=1;j1<=m;j1++){for(int j2=j1;j2<=m;j2++){int j=1;int sum=b[1][j2]-b[1][j1-1];for(int i=1;i<=n;i++){while(j<=n&&sum<=k){j++;sum+=b[j][j2]-b[j][j1-1];}cn+=j-i;sum-=b[i][j2]-b[i][j1-1];}}}cout<<cn;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(nullptr),cout.tie(nullptr);solve();return 0;
}