复制代码

cf 466

aA     

Points on the line

具体找间距k内的点多少个其余删除 就是直接暴力了

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef double    dl ;
#define INF 0x7f
const int maxn =1e5+5; 
const int mod = 1000000007;  
#define f(i,l,r) for(int i=l;i<=r;++i)
#define g(i,l,r) for(int i=l;i>=r;--i)
 int a[maxn];
int main()
{
     
    freopen("in","r",stdin);
    freopen("out","w",stdout);
    int n,k;
    cin>>n>>K;
    f(i,1,n)cin>>a[i];
    sort(a+1,a+n+1);
    int ans=0;
    f(i,1,n)f(j,i+1,n)if(a[j]-a[i]<=k) ans=max(ans,j-i+1);
    cout<<ans<<endl;

    return 0; 
}

 
 
B     
Our Tanya is Crying Out Loud

 找数据 能除法就除 比较两种方法 的金币大小

 

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef double    dl ;
#define INF 0x7f
const int maxn =1e5+5; 
const int mod = 1000000007;  
#define f(i,l,r) for(int i=l;i<=r;++i)
#define g(i,l,r) for(int i=l;i>=r;--i)
ll n,k,a,b, res=0;

int main()
{

	freopen("in","r",stdin);

	cin>>n>>k>>a>>b;
	if(k==1) res=a*(n-1);
	else
	{
		while(n!=1)
		{
			if(n<k)
			{
				res+=a*(n-1);
				n=1;
			}
			else
			{

				if(n%k!=0)
				{
					res=res+n%k*a;
					n=n-n%k;
				}
				ll t= n/k;
				if(a*(n-t) <b)
					res+=a*(n-t);
				else res+=b;
				n/=k;
			}
		}
	}

	cout<<res<<endl;

	return 0; 
}

 

 


C     
Phone Numbers

字符串比较 二分

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef double    dl ;
#define INF 0x7f
const int maxn =1e5+5; 
const int mod = 1000000007;  
#define f(i,l,r) for(int i=l;i<=r;++i)
#define g(i,l,r) for(int i=l;i>=r;--i)
char a[maxn],b[maxn];
char mm=127;
bool vis[256];
int n,k;
char find(char x){
	while(++x<='z')if(vis[x])return x;
	return 'z'+1;
}
int main()
{
     
     cin>>n>>k;
    cin>>a+1;
    memcpy(b+1,a+1,k);
    f(i,1,n)vis[a[i]]=true,mm=min(mm,a[i]);
    
    if(k>n)
    {
    	f(i,n+1,k)b[i]=mm;
    	cout<<b+1<<endl;
   		return 0;
    }

    g(i,k,1)
    {
    	char c= find(b[i]);
    	if(c<='z')b[i]=c;
    	else continue;
    	f(j,i+1,k)b[j]=mm;
		cout<<b+1<<endl;
		return 0;
    }

 
    return 0; 
}

 



D     
Alena And The Heater

直接取数据找 最大最小就好了

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef double    dl ;
#define INF 0x7f

const int inf = 987654321;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int sqrtn = 300;

#define f(i,l,r) for(int i=l;i<=r;++i)
#define g(i,l,r) for(int i=l;i>=r;--i)
  ll a[maxn],n;
 ll b[maxn];char str[maxn];
int main()
{
     
    
  
    cin>>n;
    f(i,1,n)cin>>a[i];
    cin>>str+1;
    f(i,1,n)
    {
    	if(str[i]=='0') b[i ]=0;
    	else b[i]=1;
    }
    ll l = - 1e9 ,r =1e9;
    f(i,5,n)
    {
    	  if(b[i]!=b[i-1])
    	  {
    	  	if(b[i]==1)
    	  		f(j,i-4,i)l=max(l,a[j]+1);
    	  	else
    	  		f(j,i-4,i)r=min(r,a[j]-1);
    	  }
    	 	 
    }
	 
    cout<<l<<" "<<r<<endl;	
 
    return 0;  
}

 


 

 

E     
Cashback
 抓集合比较前缀和和处理大小

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int N=1e5+5;
ll a[N],dp[N],sum[N];
multiset<ll> s;
int main(){
	ios::sync_with_stdio(false);
	int n,c;
	cin >> n>>c;
	dp[0]=0;
	sum[0]=0;
	for(int i=1;i<=n;i++){
		cin >> a[i];
		sum[i]=sum[i-1]+a[i];
		s.insert(a[i]);
		if(i<c){
			dp[i]=dp[i-1]+a[i];
		}
		else{
			dp[i]=min(dp[i-1]+a[i],dp[i-c]+sum[i]-sum[i-c]-(*s.begin()));
			s.erase(s.find(a[i-c+1])); 
		}
	}
	
	cout << dp[n] << endl;
	return 0;
}

 


F

Machine Learning

带修改莫队 不会写


posted @ 2018-02-25 17:53  pg633  阅读(354)  评论(0编辑  收藏  举报