Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)
A、B都是暴力搞一搞。
A:
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1e6+;
const int M=; ll w[];
int a,b;
int main()
{
for(int i=;i<=;i++)
w[i]=w[i-]+i;
read(a);read(b);
if(a>b)
swap(a,b);
ll ans=INF;
for(int i=a;i<=b;i++)
{
ans=min(ans,w[i-a]+w[b-i]);
}
printf("%lld\n",ans);
return ;
}
/*
*/
B:
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1e6+;
const int M=; ll w[];
int n,a,b;
vector<int> v[];
int main()
{
read(n);
read(a); read(b);
for(int i=;i<=n;i++)
v[].push_back(i);
for(int i=;i<=n;i++)
{
if(v[i].size()==)
break;
for(int j=;j<v[i].size();j+=)
{
if(v[i][j]==a && v[i][j^]==b || v[i][j]==b && v[i][j^]==a)
{
printf("%d\n",i+);
return ;
}
if(v[i][j^]==a || v[i][j^]==b)
v[i+].push_back(v[i][j^]);
else
v[i+].push_back(v[i][j]);
}
}
puts("Final!");
}
/*
*/
C题:刚开始没看到给你的数据差值不小于等于2,感觉不会写,看到了啪啦啪啦写完啦。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1e6+;
const int M=; int n,a[N],mn,cnt[],ans[];
int main()
{
int mn=inf;
read(n);
for(int i=;i<=n;i++)
read(a[i]),mn=min(mn,a[i]);
for(int i=;i<=n;i++)
a[i]-=mn;
int sum=;
for(int i=;i<=n;i++)
cnt[a[i]]++,ans[a[i]]++;
if(!cnt[] && !cnt[] || cnt[] && !cnt[])
{
printf("%d\n",n);
for(int i=;i<=n;i++)
printf("%d ",a[i]+mn);
puts("");
}
else
{
int ret=min(cnt[],cnt[]);
int res=(cnt[]/)*;
//printf("%d %d\n",ret,res);
if(*ret>=res)
{
printf("%d\n",n-*ret);
ans[]-=ret;
ans[]-=ret;
ans[]+=*ret; }
else
{
ans[]+=res/;
ans[]-=res;
ans[]+=res/;
printf("%d\n",n-res);
}
for(int i=;i<=;i++)
for(int j=;j<=ans[i];j++)
printf("%d ",i+mn);
puts("");
}
return ;
}
/*
*/
D题:是我写过最简单的D题,dfs计算一下每个深度的点有多少个,对于每个深度来说如果是奇数个点贡献是1,偶数个贡献是0。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; typedef long long ll;
const int inf=0x3f3f3f3f;
const int INF=0x3f3f3f3f3f3f3f3f;
const int N=1e6+;
const int M=; vector<int> edge[N];
int n,d[N];
void dfs(int u,int de)
{
d[de]++;
for(int v:edge[u])
dfs(v,de+);
}
int main()
{
read(n);
for(int i=;i<=n;i++)
{
int fa; read(fa);
edge[fa].push_back(i);
}
dfs(,);
int ans=;
for(int i=;i<=n;i++)
if(d[i]&)
ans++;
printf("%d\n",ans);
return ;
}
/*
*/
E题:比赛的时候一直看错题,以为是猜对的概率,题目是唯一确定答案的概率,一直调都不对,结果GG啦,其实也很简单,
统计一下点与点之间的情况,对于一种字符来说,第二张要翻开的卡的位置都是一样的,算一下这个概率就好啦。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; const int N=;
int n,cnt[][][N];
char s[N];
double mp[];
int main()
{
sread(s+);
n=strlen(s+);
for(int i=;i<=n;i++)
{
for(int j=i+;j<=n;j++)
{
cnt[s[i]-'a'][s[j]-'a'][j-i]++;
cnt[s[j]-'a'][s[i]-'a'][n-(j-i)]++;
}
}
for(int i=;i<;i++)
{
for(int k=;k<n;k++)
{
int tot=,sum=;
for(int j=;j<;j++)
{
sum+=cnt[i][j][k];
if(cnt[i][j][k]==)
tot++;
}
mp[i]=max(mp[i],1.0*tot/sum);
}
}
double ans=;
for(int i=;i<=n;i++)
ans+=mp[s[i]-'a']/n;
printf("%.12f\n",ans);
return ;
}
/*
*/
F题:题目大意:给你n条线段覆盖的x轴,范围在1-m之间,有一个人开始询问,每次询问一个点的覆盖次数,问你最多几次之后
还是无法确定是不是有一个点被所有线段覆盖。
思路:这题想了好久。。。 刚开始以为是和点被覆盖最大值有关,写了很久发现有问题,我们考虑对于两个点a,b来说,如果有一个
点c在a,b之间,且c < max (a, b) ,那么覆盖a的线段,和覆盖b的线段肯定不完全相同,如果完全相同,肯定有 c>=max(a,b),矛盾。
所以我们的问题就变成了从里面选出尽可能多的点,使其的覆盖次数满足先增后减,然后就很开心地最长不下降子序列搞一搞就好啦。
#include<bits/stdc++.h>
#define fi first
#define se second
#define mk make_pair
#define pii pair<int,int>
#define read(x) scanf("%d",&x)
#define sread(x) scanf("%s",x)
#define dread(x) scanf("%lf",&x)
#define lread(x) scanf("%lld",&x)
using namespace std; const int N=1e5+;;
int in[N],out[N],cnt[N],d[N],ans1[N],ans2[N];
int n,m;
int main()
{
read(n); read(m);
for(int i=;i<=n;i++)
{
int l,r;
read(l); read(r);
in[l]++;
out[r]++;
}
int all=;
for(int i=;i<=m;i++)
{
all+=in[i];
cnt[i]=all;
all-=out[i];
}
ans1[]=; d[]=cnt[];
int len=;
for(int i=;i<=m;i++)
{
if(cnt[i]>=d[len])
{
d[++len]=cnt[i];
ans1[i]=len;
}
else
{
int j=upper_bound(d+,d+len+,cnt[i])-d;
ans1[i]=j;
d[j]=cnt[i];
}
}
ans2[m]=;
d[]=cnt[m];
len=;
for(int i=m-;i>=;i--)
{
if(cnt[i]>=d[len])
{
d[++len]=cnt[i];
ans2[i]=len;
}
else
{
int j=upper_bound(d+,d+len+,cnt[i])-d;
ans2[i]=j;
d[j]=cnt[i];
}
}
int ans=;
for(int i=;i<=m;i++)
ans=max(ans,ans1[i]+ans2[i]-);
printf("%d\n",ans);
return ;
}
/*
*/
Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)的更多相关文章
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup
The last stage of Football World Cup is played using the play-off system. There are n teams left in ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)D. Peculiar apple-tree
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)C. Laboratory Work
Anya and Kirill are doing a physics laboratory work. In one of the tasks they have to measure some v ...
- Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)A. Friends Meeting
Two friends are on the coordinate axis Ox in points with integer coordinates. One of them is in the ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】
C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861B Which floor?【枚举,暴力】
B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861A k-rounding【暴力】
A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- Codeforces Round #543 (Div. 2, based on Technocup 2019 Final Round)
A. Technogoblet of Fire 题意:n个人分别属于m个不同的学校 每个学校的最强者能够选中 黑客要使 k个他选中的可以稳被选 所以就为这k个人伪造学校 问最小需要伪造多少个 思路:记 ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...
随机推荐
- 二、主目录 Makefile 分析(3)
2.8 编译选项 重新回到 主 makefile 中执行 2.8.1 u-boot 的编译顺序 代码166 到 189 行,这些是 u-boot 文件编译的顺序,由代码可以看到,首先是从cpu/$( ...
- wireshark数据包分析
最近有不少同事开始学习Wireshark,他们遇到的第一个困难就是理解不了主界面上的提示信息,于是跑来问我.问的人多了,我也总结成一篇文章,希望对大家有所帮助.Wireshark的提示可是其最有价值之 ...
- CF28D Don't fear, DravDe is kind
传送门 题意:\(n\)个位置,每个位置有价值\(v_i\)和重量\(p_i\),要选出一些位置,如果要选位置\(i\),那么前面选的重量之和要为\(l_i\),后面选的重量之和要为\(r_i\),求 ...
- A - 低阶入门膜法 - K-th Number (主席树查询区间第k小)
题目链接:https://cn.vjudge.net/contest/284294#problem/A 题目大意:主席树查询区间第k小. 具体思路:主席树入门. AC代码: #include<i ...
- Ajax跨域访问解决方案
No 'Access-Control-Allow-Origin' header is present on the requested resource. 当使用ajax访问远程服务器时,请求失败,浏 ...
- SpringBoot整合Email(电子邮件服务)
(1).导入starter依赖 <dependency> <groupId>org.springframework.boot</groupId> <artif ...
- WPF版公司的自动签到程序
1.外包公司要求早上签到,就写了一个自动打卡程序. 2.一直都想写这个程序,可是一直没有思路,知道有个软件公司找我做自动答题程序,于是自动打卡程序才应运而生.未来可以将自动答题程序开源工大家查看. 3 ...
- python魔法方法:__getattr__,__setattr__,__getattribute__
python魔法方法:__getattr__,__setattr__,__getattribute__ 难得有时间看看书....静下心来好好的看了看Python..其实他真的没有自己最开始想的那么简单 ...
- 移动端中遇到的坑(bug)!!!
1.模拟单选点击的时候,在ios手机下,点击下面的内容选择,会出现页面闪一闪!! 解决方案:样式重置html的时候加上这句 -webkit-tap-highlight-color: rgba(0, ...
- C# 发送email邮件!
利用C#邮件发送邮箱使用到两个类SmtpClient和MailMessage.可以把SmtpClient看做发送邮件信息的客户端,而把MailMessage看做需要发送的消息. 下面是我写的发送邮件的 ...