第三天 Codeforces Round 871 (Div. 4) A~E

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define fir(v) (v).first
#define se(v) (v).second
#define pb(x) push_back(x)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N=1000000;
int a[N];
bool cmp(int x,int y)
{
	return x>y;
}

signed main()
{
	   IOS();
	   string s="codeforces";
	   int t;
	   cin>>t;
	   while(t--){
	   	string baga;
	   	cin>>baga;
	   	int cnt=0;
	   	for(int i=0;i<10;i++){
	   		if(baga[i]!=s[i]){
	   			cnt++;
			   }
		   }
		cout<<cnt<<endl;
	   } 

}

 

题意:找出连续最长的0的个数

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define fir(v) (v).first
#define se(v) (v).second
#define pb(x) push_back(x)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N=1000000;
int a[N];
bool cmp(int x,int y)
{
	return x>y;
}

signed main()
{
	   IOS();
	   int t;
	   cin>>t;
	   while(t--){
	   	int n;
	   	cin>>n;
	   	int cnt=0;
	   	int mx=0;
	   	for(int i=1;i<=n;i++){
	   		cin>>a[i]; 
		   }
		for(int i=1;i<=n;i++){
			if(a[i]==0){
				cnt++;
				mx=max(cnt,mx);
			}
			else cnt=0;
		}
		cout<<mx<<endl;
	   }

}

题意:一个人需要获得两项技能,问需要花费的最小时间

思路:01代表其中一种技能,10代表另一种技能,11代表两种技能,只要分类求出最小的时间就可以

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define fir(v) (v).first
#define se(v) (v).second
#define pb(x) push_back(x)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N=1000000;
int a[N];
bool cmp(int x,int y)
{
	return x>y;
}

signed main()
{
	   IOS();
	   int t;
	   cin>>t;
	   while(t--){
	   	int n;
	   	cin>>n;
	   	int baga=1e9,yalu=1e9,yoxi=1e9;
	   	for(int i=1;i<=n;i++){
	   		int x;
	   		string y;
	   		cin>>x>>y;
	   		if(y=="11"){
				yoxi=min(yoxi,x);
			}
	   		else if(y=="01"){
	   			baga=min(x,baga);
			   }
			else if(y=="10"){
				yalu=min(x,yalu);
			}
			 
			yoxi=min(yoxi,baga+yalu);
		   }
		   if(yoxi==1e9){
		   	cout<<-1<<endl;
		   }
		else 
		cout<<yoxi<<endl;
	   }
	   

}

 

 题意:一堆金子可以分成两堆,原来的1/3,和原来的2/3,给你目标数量m,问是否能分到

思路:暴力

#include <iostream>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
using namespace std;
const int N=1000000;
int a[N];
bool flag=0;
bool cmp(int x,int y)
{
	return x>y;
}
void dfs(int n,int m){
	if(n==m){
		flag=1;
		return ;
	}
	if(m%2==0 && m/2*3<=n)
		dfs(n,m/2*3);//反过来求n 
	if(m*3<=n)
		dfs(n,m*3);
	
}
signed main()
{
	IOS();
	int t;
    cin >> t;
    while(t--) {
        int n,m;
        cin >> n >> m;
        flag=0;//记得开一个局部的 
        	if(m==n){
			cout<<"YES"<<endl;
			continue;
		}
        if(m>n){
			cout<<"NO"<<endl;
			continue;
		}
        dfs(n, m);
        if(flag==1) cout <<"YES"<< endl;   
        else cout<<"NO"<<endl;
    }
    return 0;
}


 

dfs模板题

#include <iostream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#define IOS() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define fir(v) (v).first
#define se(v) (v).second
#define pb(x) push_back(x)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define pii pair<int,int>
#define all(a) (a).begin(),(a).end()
#define mp(a,b) make_pair(a,b)
using namespace std;
const int N=1000000;
string s[N];
int n,m;
int mp[1001][1001];
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int ans=0;
bool vis[1001][1001];
bool cmp(int x,int y)
{
	return x>y;
}
void dfs(int x,int y ){
	if(mp[x][y]==0||vis[x][y]==true){
		return ;
	}
	ans+=mp[x][y];
	vis[x][y]=1;
	for(int i=0;i<4;i++){
		int xx=x+dx[i];
		int yy=y+dy[i];
		if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&mp[xx][yy]!=0&&vis[xx][yy]==false){
			dfs(xx,yy);
		}
	}
}
signed main()
{
	   IOS();
	   int t;
	   cin>>t;
	   while(t--){
	   	cin>>n>>m;
	   	for(int i=1;i<=n;i++){
	   		for(int j=1;j<=m;j++){
	   			cin>>mp[i][j];
	   			vis[i][j]=false;
			   }
		   }
	   int mx=0;
	   for(int i=1;i<=n;i++){
	   		for(int j=1;j<=m;j++){
	   		if(mp[i][j]!=0&&vis[i][j]==false){
	   			dfs(i,j);
	   			mx=max(mx,ans);
	   			ans=0;
			   }
		   }
	   }
	cout<<mx<<endl;
	}
}

 

 

### PyCharm 打开文件显示全的解决方案 当遇到PyCharm打开文件显示全的情况时,可以尝试以下几种方法来解决问题。 #### 方法一:清理缓存并重启IDE 有时IDE内部缓存可能导致文件加载异常。通过清除缓存再启动程序能够有效改善此状况。具体操作路径为`File -> Invalidate Caches / Restart...`,之后按照提示完成相应动作即可[^1]。 #### 方法二:调整编辑器字体设置 如果是因为字体原因造成的内容显示问题,则可以通过修改编辑区内的文字样式来进行修复。进入`Settings/Preferences | Editor | Font`选项卡内更改合适的字号大小以及启用抗锯齿功能等参数配置[^2]。 #### 方法三:检查项目结构配置 对于某些特定场景下的源码视图缺失现象,可能是由于当前工作空间未能正确识别全部模块所引起。此时应该核查Project Structure的Content Roots设定项是否涵盖了整个工程根目录;必要时可手动添加遗漏部分,并保存变更生效[^3]。 ```python # 示例代码用于展示如何获取当前项目的根路径,在实际应用中可根据需求调用该函数辅助排查问题 import os def get_project_root(): current_file = os.path.abspath(__file__) project_dir = os.path.dirname(current_file) while not os.path.exists(os.path.join(project_dir, '.idea')): parent_dir = os.path.dirname(project_dir) if parent_dir == project_dir: break project_dir = parent_dir return project_dir print(f"Current Project Root Directory is {get_project_root()}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值