基本用法1

vector

#include<bits/stdc++.h>
using namespace std;
vector<string>v;
typedef long long ll;
ll n,i,j,temp,cnt;
string jj;
int main(){
	cin>>n;
	for(i=1;i<=n;i++){
		
		cin>>j;
		temp=j;
		while(temp!=0){
		cnt++;
		if(i%2!=0){
			if(temp%2==0){
			temp-=3;}
			else temp-=1;
		}
		
		if(i%2==0){
			if (temp%2==0){
			temp-=2;
		}
			else temp-=1;
			
		}
	}
	if(cnt%2==0){
		v.push_back("Bob") ;
	}
	else
	v.push_back("Alice");
	} 
	vector<string>::iterator jj;
	for(jj=v.begin();jj!=v.end();jj++){
		cout<<*jj<<"	";
	}
	return 0;
} 

pair

#include<iostream>
#include<utility>
#include<string>
using namespace std;
int main(){
pair<int,string>pa;
pa.first=233;
pa.second="wsx";
cout<<pa.first<<" "<<pa.second<<endl;	
pair<int,int>pc=make_pair(1,1);
pair<int,int>pd=make_pair(1,2);
if(pc>pd)
	cout<<"1";
	else 
	cout<<"0";
     return 0;
}
//分治法求最大子段和 
#include<map>
#include<vector>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long ll;

const int N=100000+5;
int n=10,a[N]={2,-7,6,-2,8,-2,9,6,-1,-2};

int f(int l,int r){
	int m=(l+r)/2;
	int suml=0;int ansl=a[m];
	int sumr=0;int ansr=a[m+1];
	for(int i=m;i>=1;i--){
		suml+=a[i];//字串和左 
		ansl=max(ansl,suml);//每一次的遍历数字 
	}
	for(int i=m+1;i<=r;i++){
		sumr+=a[i];
		ansr=max(ansr,sumr);
	}
	return ansl+ansr;
}

//递归的本质自己调用自己 
int maxsum(int l,int r){
	if(l==r) return a[l];//出口一定会经过 
	else{
		int m=(l+r)/2;
		int L=maxsum(l,m);//走n次这里  m的值赋给r 
		 int R=maxsum(m+1,r);//下一个走n次这里 
		 int LR=f(l,r);//找中间   下下一个走这里n次 函数套函数 
		 return max(max(L,R),LR) ;//最后的结果 
	}
} 


int main(){
	cout<<maxsum(0,9)<<endl;//给函数赋值 
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值