ICPC南京

发现简单题打了很久很久于是就没时间写稍微中等一些的题目了
基 础 不 牢

K
签到
要几个就左移前几位
L
模拟签到
后来好好补题了,这玩意我们在场上打了3小时,而且wa了5发

#include<bits/stdc++.h>
const int N = 1e5 +5;
const int INF = 1e9+5;
using namespace std;
int a[N],b[N];
set<int> s,sb;
int t,n,m;
void test(){
	for(auto I:s){
		cout<<I<<" ";
	}cout<<endl;
	for(auto I:sb){
		cout<<I<<" ";
	}cout<<endl;
}
int main()
{
	cin >> t;
	while (t--)
	{
		cin >>n>>m;
		s.clear();
		sb.clear();
		vector<int> ex;
		for (int i = 0;i<n;i++)	{
			cin>>a[i];
			s.insert(a[i]);
		}
		for(int i=0;i<m;i++){
			cin>>b[i];
			sb.insert(b[i]);
		}
		for(auto I:sb)
		{
			if(s.count(I)){
				ex.push_back(I);
				s.erase(I);
				//sb.erase(I);
			}
		}
		//test();
		sort(a,a+n);
		int tmp=0,sum=0,pos=0,heap;
		sb.insert(0);
		sb.insert(INF);
		for(auto I:sb){
			while(a[pos]<I&&pos<n){
				if(s.count(a[pos])) tmp++;
				pos++;
			}
			sum=max(sum,tmp);
			
			tmp=0;
		}
		if(sum)	cout<<sum<<endl;
		else puts("Impossible");
	}
 } 

F
推公式,三分。推公式是高中数学期望,悲
感觉期望这个事情,有必要复习复习高中概率统计专题

#include <bits/stdc++.h>
#define eps 1e-6
using namespace std;
typedef long long ll;
int t,n,m,P;
double p;
double cal(double x)
{
	return (n*x+m)/(1-pow((1-p),x));
}
int main()
{
	cin >> t;
	while (t--)
	{
		cin >> n >> m >>P;
		p = P*1.0/10000;
		ll l = 1,r = 1e18;
		ll ans1,ans2;
		while(l + 1<= r)
		{
			ans1 = l +(r-l)/3.0;
			ans2 = l + (r-l)*2.0/3.0;
			//cout <<l<<" "<<r<< " "<<ans1<<" "<<ans2<<" "<<cal(ans1)<<" "<< cal(ans2) <<endl;
			if(cal(ans1) > cal(ans2))
			{
				if (l == ans1) break;
				l = ans1;
			}
			else{
				//if (r == ans2)	{	break;	}
					r = ans2;
			}
		}
		//cout<<l<<endl;
		//cout << l <<" "<<r<<" "<<ans1<<" "<<ans2<<endl;
		double ans[4] ={cal(l),cal(r),cal(ans2)};
		sort(ans,ans+3);
		
		printf("%.6f\n",ans[0]);	
		}
	
} 

E
一个很巧妙的解法,枚举24种排列

#include <bits/stdc++.h>
using namespace std;
int t,xx,yy;
string str;
char drc[4]={'U','D','L','R'};
int drcnt[4],per[4]={0,1,2,3};
int dr[][2]={{0,1},{0,-1},{-1,0},{1,0}};//UDLR
void count(char c){
	for(int i=0;i<4;i++){
		if(drc[i]==c){
			drcnt[i]++;
			return;
		}
	}
}
bool move(){
	int x=0,y=0,dx,dy;
	if(xx==x&&yy==y)return false;
	for(int i=0;i<4;i++){//4个方向,per[i] 
		for(int j=0;j<drcnt[per[i]];j++){
			 dx=x+dr[per[i]][0];
			 dy=y+dr[per[i]][1];
			 //cout<<dx<<" "<<dy<<endl;
			 //if(dx<0||dy<0) continue;
			 if(dx==xx&&dy==yy) return false;
			 x=dx;
			 y=dy;
		}
	}
	return true;
}
int main()
{
	cin >>t;
	while(t--)
	{
		for(int i=0;i<4;i++) drcnt[i]=0;
		cin>>xx>>yy>>str;
		for(int i=0;i<str.size();i++){
			count(str[i]);			
		}
		int flag=0;
		//int cnt=0;
		do{
			//cout<<cnt++<<":";
			//for(int i=0;i<4;i++){	for(int j=0;j<drcnt[per[i]];j++){	cout<<drc[per[i]];	}	}cout<<endl;
			
			if(move()){
				//cout<<"ans:";
				for(int i=0;i<4;i++){
					for(int j=0;j<drcnt[per[i]];j++){
						cout<<drc[per[i]];
					}
				}cout<<endl;
				flag=1;
				break;
			}
		}while(next_permutation(per,per+4));
		if(!flag) puts("Impossible");
	}
	return 0;
 } 

还有一个M,是树形dp,想补555可是dp苦手而且树形dp更苦手了

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值