2017CCPC 秦皇岛现场赛
E题
这个题因为最多就只能增加一个CCPC 所以考虑所有能增加的情况就好了
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
char ch[maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
scanf("%s",&ch);
int len = strlen(ch);
ll ans=0;
for(int i=0;i<len;i++)
{
if(ch[i]=='C'&&ch[i+1]=='C'&&ch[i+2]=='P'&&ch[i+3]=='C')ans++;
}
if((ch[0]=='C'&&ch[1]=='P'&&ch[2]=='C')){ans++;}
else
{
for(int i=0;i<len;i++)
{
if(ch[i]=='C'&&ch[i+1]=='C'&&ch[i+2]=='C') {
if(ch[i+3]=='P'&&ch[i+4]=='C')continue;
else {ans++;break;}
}
if(ch[i]=='P'&&ch[i+1]=='C'&&ch[i+2]=='P'&&ch[i+3]=='C'){ans++;break;}
if(ch[i]=='C'&&ch[i+1]=='C'&&ch[i+2]=='P'&&(ch[i+3]=='P'||i+3>=len)){ans++;break;}
}
}
printf("%lld\n",ans);
}
return 0;
}
M 题 因为没有看清楚题目,由于最后没有排序 WA了好多发
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200+50;
struct point
{
ll x,y;
ll dist;
int idx;
};
point p[maxn];
bool cmp(point a,point b)
{
return a.dist<b.dist;
}
vector<int>v;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
v.clear();
ll n,R,r;
scanf("%lld%lld%lld",&n,&R,&r);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&p[i].x,&p[i].y);
p[i].dist = p[i].x*p[i].x+p[i].y*p[i].y;
p[i].idx = i;
}
sort(p+1,p+1+n,cmp);
ll sq=0;
if(R>2*r)
{
sq = (ll)(R-r*2)*(ll)(R-r*2);
for(int i=1;i<=n;i++)
{
if(p[i].dist<=sq) v.push_back(p[i].idx);
else break;
}
if(v.size()==0)
{
v.push_back(p[1].idx);
for(int j=2;j<=n;j++)
{
if(p[j].dist==p[1].dist) v.push_back(p[j].idx);
else break;
}
}
}
else if(R<=2*r)
{
ll sq2 = (ll)(2*r-R)*(ll)(2*r-R);
for(int i=1;i<=n;i++)
{
if(p[i].dist<=sq2)v.push_back(p[i].idx);
else break;
}
if(v.size()==0)
{
v.push_back(p[1].idx);
for(int j=2;j<=n;j++)
{
if(p[j].dist==p[1].dist) v.push_back(p[j].idx);
else break;
}
}
}
sort(v.begin(),v.end());
printf("%d\n",v.size());
for(int i=0;i<v.size();i++)
{
if(i!=v.size()-1)
printf("%d ",v[i]);
else
{
printf("%d\n",v[i]);
}
}
}
return 0;
}
G题 要使得或的结果最小,就让每一位都尽可能的平均分给某一个二进制位,这样从高到低分配,用java大数处理一下
import java.math.*;
import java.util.*;
public class Main
{
public static BigInteger QuickPow02 (int n)
{
BigInteger ans = BigInteger.valueOf(1);
BigInteger base = BigInteger.valueOf(2);
while(n > 0)
{
if(n % 2 == 1)
ans = ans.multiply(base);
n /= 2;
base = base.multiply(base);
}
return ans;
}
public static BigInteger min (BigInteger a1,BigInteger a2)
{
if(a1.compareTo(a2)>=0) return a2;
else return a1;
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
BigInteger n,m,md,bi,s,q,q1,q2;
int cnt;
cnt=in.nextInt();
BigInteger tmp = BigInteger.valueOf(0);
BigInteger two2 = BigInteger.valueOf(2);
BigInteger one1 = BigInteger.valueOf(1);
BigInteger ans=BigInteger.valueOf(0);
for(int i=1;i<=cnt;i++)
{
n = in.nextBigInteger();
m = in.nextBigInteger();
s =n.divide(m);
q=n.mod(m);
q1=n.divide(m);
//System.out.println(q1);
int len=0;
ans=tmp;
if(!q.equals(tmp))q1=q1.add(one1);
//System.out.println(q1);
q2=q1;
while(!q2.equals(tmp))
{
len++;
q2=q2.divide(two2);
}
//System.out.println(len);
//System.out.println(q1);
for(int j=len-1;j>=0;j--)
{
BigInteger t = QuickPow02(j);
//System.out.println(t);
if(q1.compareTo(t)>=0) {
//System.out.println(1);
ans=ans.add(t);
BigInteger c =min(n.divide(t),m);
n = n.subtract(c.multiply(t));
q1 = n.divide(m);
if(!n.mod(m).equals(tmp)) q1=q1.add(one1);
}
}
System.out.println(ans);
}
}
}