2018 CCPC 桂林站(upc复现赛)补题

G.Greatest Common Divisor(思维)

求相邻数的差值的gcd,对gcd分解素因子,对所有的素因子做一次遍历,找出最小答案。

几个样例: ans : 0 1 0 2

3
3 6 9
1
1
1
2
2
11 76

 #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define LL long long
using namespace std;
const int MAXN= 1e5+; LL t, n, a[MAXN], fac[], cnt;
LL gcd(LL a, LL b){return b== ? a : gcd(b, a%b);}
void work(LL x){
LL temp = x;
for(LL i=; i*i<=temp; i++)
if(x%i == ) {
fac[++cnt] = i;
while(x%i == ) x /= i;
}
if(x>) fac[++cnt] = x;
}
int main()
{
LL Case = ;
cin >> t;
while(t--){
cnt = ;
bool flag1=true, flag2=true;
scanf("%lld", &n);
for(LL i=; i<=n; i++) scanf("%lld", &a[i]);
sort(a+, a+n+);
n = unique(a+, a+n+) - a - ;
printf("Case %lld: ", ++Case); if(n == ){
if(a[] == ) cout << "" << endl;
else cout << "" << endl;
continue;
} LL temp = a[]-a[];
for(LL i=; i<=n; i++)
temp = gcd(temp, a[i]-a[i-]); if(temp == ){
cout << "-1" << endl;
continue;
}
work(temp);
LL ans = 1e17;
for(LL i=; i<=cnt; i++){
if(a[] % fac[i] == ) ans = ;
ans = min(ans, fac[i]-(a[]%fac[i]));
}
cout << ans << endl;
}
}

J.石头游戏 (博弈)

Alice和Bob总是在玩游戏!今天的比赛是关于从石堆中依次取出石头。
有n堆石头,第i堆包含A [i]个石头。
由于每个堆中的宝石数量与其邻居的宝石数量不同,因此他们决定在不打破该属性的情况下从其中一个中取出一块石头。Alice先拿。
规定当谁不能拿石头将输掉比赛。
现在给出一个数字N和N个数字代表每堆石子的个数,你要确定最后的获胜者,假设他们都足够聪明。
Ps: 你应该注意到即使是一堆0石头仍然被视为一堆!

第一次看题时没有看到每次限取一颗,后来发现时比赛已经快结束了orz。读错题坑了队友。

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=1e5+;
int num[maxn],a[maxn]; int main()
{
int t,n;
scanf("%d",&t);
for(int k=;k<=t;k++)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
{
scanf("%d",&num[i]);
a[i]=num[i];
} int ans=,pos=;
if(num[]<num[])
{
int st=,t=;
while(num[st]<num[st+])
{
pos=st;
num[st]=t;
st++; t++;
}
pos++;
}
if(num[n]<num[n-])
{
int st=n,t=;
while(num[st]<num[st-])
{
pos=st;
num[st]=t;
st--; t++;
}
pos--;
}
bool flag=true;
for(int i=;i<n;i++)
{
flag=false;
if(num[i]<num[i-]&&num[i]<num[i+])
{
int st=,s=i;
while(num[s]<num[s-])
{
num[s]=st;
s--;st++;
}
num[s]=max(num[s-],num[s+])+;
st=;s=i;
while(num[s]<num[s+])
{
num[s]=st;
s++;st++;
}
num[s]=max(num[s-],num[s+])+;
}
}
if(num[]>num[]+)
num[]=num[]-;
if(num[n]>num[n-]+)
num[n]=num[n-]-;
for(int i=;i<=n;i++)
{
if(num[i]>num[i-]&&num[i]>num[i+])
num[i]=max(num[i-],num[i+])+;
ans+=a[i]-num[i];
}
if(ans&)
cout<<"Case "<<k<<": Alice"<<endl;
else
cout<<"Case "<<k<<": Bob"<<endl;
}
return ;
}

H.汉明距离 (字符串贪心构造)

在信息理论中,两个相等长度的串之间的汉明距离是指相同位置字符不同的数量。换句话说,它计算将一个字符串更改为另一个字符串所需的最小替换次数,或者可能将一个字符串转换为另一个字符串的最小更改数。
假设有两个字符串s1,s2具有相同的长度,仅限于包含小写字符,找到一个相同长度的、字典序最小的字符串s,使得s1,s2与s的汉明距离相等。

一开始发现情况太多被劝退的,实际发现也没那么难以实现。emm...一言难尽。

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstring>
#include<cmath>
using namespace std;
const int maxn=1e4+;
char c1[maxn],c2[maxn],c3[maxn];
int sum[maxn];
char MIN(char a,char b)
{
for(char i='a'; i<='z'; i++)
{
if(i!=a&&i!=b)
return i;
}
}
int main()
{
int t;
while(~scanf("%d",&t))
{
for(int i=; i<=t; i++)
{
scanf("%s%s",c1,c2);
int len=strlen(c1);
sum[len]=;
for(int j=len-; j>=; j--)
{
sum[j]=sum[j+];
if(c1[j]!=c2[j])
sum[j]++;
}
int num=;
for(int j=; j<len; j++)
{
if(abs(num) < sum[j+]||c1[j]==c2[j])
{
c3[j]='a';
if(c1[j]=='a'&&c2[j]!='a')
num++;
if(c1[j]!='a'&&c2[j]=='a')
num--;
continue;
}
else
{
char ch=MIN(c1[j],c2[j]);
if(num>)
{
if(ch<c2[j]&&num==sum[j+])
c3[j]=ch;
else
{
c3[j]=c2[j];
num--;
}
}
else if(num<)
{
if(ch<c1[j]&&-num==sum[j+])
c3[j]=ch;
else
{
c3[j]=c1[j];
num++;
}
}
else
c3[j]=ch;
}
}
c3[len]='\0';
printf("Case %d: %s\n",i,c3);
}
}
return ;
}

2018 CCPC 桂林站(upc复现赛)补题的更多相关文章

  1. 2018 CCPC 桂林站(upc复现赛)总结

    比赛一开始盯上了A题和G题,一个小时过去了还没有出题,心里有些乱.这时我看D题很多人过了,于是宝儿去看D题,说D题简单,转化成二进制暴力,于是就去做了.写的时候好像思路有点卡,WA了一发,后来马上发现 ...

  2. 2019浙师大校赛(浙大命题)(upc复现赛)总结

    2019浙师大校赛(浙大命题)(upc复现赛)总结 早上九点开始.起得迟了,吃了早饭慌慌张张跑过去,刚到比赛就开始了. 开始分别从前往后和从后往前看题,一开始A题,第一发WA,第二次读题发现漏看了还有 ...

  3. 2018 CCPC 吉林站 H Lovers

    2018 CCPC 吉林站 H Lovers 传送门:https://www.spoj.com/problems/LIS2/en/ 题意: q次操作 1.将第l~r个数的左边和和右边都加上一个数d, ...

  4. 2018 CCPC 桂林游记

    TYPE: Onsite Contest NAME: 2018 - CCPC - Guilin PLAT: HUSTOJ TIME: 2018/10/28 09:00-14:00 CST LOCA: ...

  5. 2017河工大校赛补题CGH and 赛后小结

    网页设计课上实在无聊,便开始补题,发现比赛时候僵着的东西突然相通了不少 首先,"追妹"这题,两个队友讨论半天,分好多种情况最后放弃(可是我连题目都没看啊),今天看了之后试试是不是直 ...

  6. 第十届山东省acm省赛补题(1)

    今天第一场个人训练赛的题目有点恐怖啊,我看了半个小时多硬是一道都不会写.我干脆就直接补题去了.... 先补的都是简单题,难题等我这周末慢慢来吧... A Calandar Time Limit: 1 ...

  7. 2018 CCPC 吉林站 H Lovers || HDU 6562 (线段树哦)

    http://acm.hdu.edu.cn/showproblem.php?pid=6562 题意: q次操作 1.将第l~r个数的左边和和右边都加上一个数d, 使得这个数变成 dsiddsid的形式 ...

  8. 哈尔滨工程大学ACM预热赛 补题

    链接:https://ac.nowcoder.com/acm/contest/554/A来源:牛客网 小虎刚刚上了幼儿园,老师让他做一个家庭作业:首先画3个格子,第二行有2个格子,第三行有1个格子. ...

  9. ZJUT11 多校赛补题记录

    牛客第一场 (通过)Integration (https://ac.nowcoder.com/acm/contest/881/B) (未补)Euclidean Distance (https://ac ...

随机推荐

  1. ChartCtrl源码剖析之——CChartLegend类

    CChartLegend类用来绘制每一个波形的描述信息,它处于该控件的区域,如下图所示: CChartLegend类的头文件. #if !defined(AFX_CHARTLEGEND_H__CD72 ...

  2. INT_PTR数据类型

    A signed integer type for pointer precision. Use when casting a pointer to an integer to perform poi ...

  3. XDCTF2015代码审计全解

    此次CTF WEB2是一个大题,一共4个flag,分别代表:获取源码.拿下前台管理.拿下后台.getshell. 目标站:http://xdsec-cms-12023458.xdctf.win/ 根据 ...

  4. 【练习总结】题目:筛法遍历素数(Java)

    初学Java,学到流程控制的循环,有个练习题是暴力遍历素数. 因为看过av32186751,知道有个筛法,就想试试. 又受到线性筛法(一)--素数筛法(一) - nerd呱呱 - 博客园中,的这段启发 ...

  5. c语言程序设计案例教程(第2版)笔记(五)-软件开发基础知识

    零散知识点: 软件的主要特征 软件是一种逻辑产品,而不是有型的物质: 软件需要设计.开发,但不是传统意义上的产品制造: 软件不会磨损,但软件需要维护,即:修改代码或增加模块: 虽然软件行业正在向基于组 ...

  6. Service官方教程(2)*IntentService与Service示例、onStartCommand()3个返回值的含义。

    1.Creating a Started Service A started service is one that another component starts by calling start ...

  7. B/S和C/S示意图

    B/S C/S

  8. [转]Monkey测试简介

    转自:http://www.cnblogs.com/manuosex/p/3215270.html 在android手机上做自动化测试,monkey比cts,Android UnitTest 好用多了 ...

  9. [译]curl_multi_add_handle

    NAMEcurl_multi_add_handle - add an easy handle to a multi session添加easy handle到multi session中 SYNOPS ...

  10. [转]访问 OData 服务 (WCF Data Services)

    本文转自:http://msdn.microsoft.com/zh-SG/library/dd728283(v=vs.103) WCF 数据服务 支持开放式数据协议 (OData) 将数据作为包含可通 ...