首页 技术 正文
技术 2022年11月7日
0 收藏 336 点赞 478 浏览 5303 个字

http://codeforces.com/contest/731

不发题面了,自己点链接

总结一下

考场上

【Codeforces】Round #376 (Div. 2)

原以为这次要加很多raiting。。。

【Codeforces】Round #376 (Div. 2)

但FST狗记邓,只加了58rating

总结一下

  • ABC切得很快(保持)
  • B题WA了2发不应该,没有想清楚
  • F题写了大暴力,但不优美,虽然过了P,但就没有想了,很严重问题,得意忘形,虽然知道FST,但有侥幸心里,真正考试就完了
  • 以为拿到了分就不干事了,严重问题,真正考试一定要写暴力拍
  • 后来没有干事,既没有hack又没有去写DE不应该

A Night at the Museum

Solution:Implementation,String

// <A.cpp> - Sun Oct 16 17:45:40 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is.#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
using namespace std;
typedef long long LL;
const int MAXN=110;
inline int gi() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
char s[MAXN];
int main()
{
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
scanf("%s",s);int l=strlen(s);
char ch='a';int ans=0;
for(int i=0;i<l;i++)
ans+=min((s[i]-ch+26)%26,(ch-s[i]+26)%26),ch=s[i];
printf("%d",ans);
return 0;
}

B Coupons and Discounts

题目大意:每天要买a[i]个东西,买的方式有两种:两天一天买一个 or 一天买两个,问是否有合法方案

Solution:Greedy+递推,考虑一天,奇数的话必须要用第一种方式,那就之后那天要买一个,几个flag即可,一路推过去,<0不合法,偶数的话直接用第二种→ 贪心,不用麻烦后面那天。

反思:居然wa了两发,7~80分啊。。(notice 最后一次是否要之后填充,flag清空)

// <B.cpp> - Sun Oct 16 17:45:40 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is.#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
using namespace std;
typedef long long LL;
const int MAXN=100010;
const int MAXM=100010;
inline int gi() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
void pri(){printf("NO");exit(0);}
int main()
{
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
int n=gi(),last=0;
for(int i=1;i<=n;i++){
int x=gi()-last;
if(x<0)pri();
if(x&1)last=1;else last=0;
}if(last)pri();else printf("YES");
return 0;
}

C Socks

有n只袜子,每只袜子有一个颜色,有一些约束(即某天的左右两边袜子颜色要相同),然后问你最少要改多少只?

显然并查集,然后贪心,一个联通块内的颜色要全相同,Greedy-找出颜色已经相同的最多数目,答案加上其他要改的即可

// <C.cpp> - Sun Oct 16 17:45:40 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is.#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
using namespace std;
typedef long long LL;
const int MAXN=200010;
inline int gi() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
int f[MAXN],a[MAXN],c[MAXN];vector<int>b[MAXN];
int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
int main()
{
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
int n=gi(),m=gi(),k=gi(),ans=0;k++;
for(int i=1;i<=n;i++)a[i]=gi(),f[i]=i;
while(m--){
int l=gi(),r=gi();
if(find(l)!=find(r))f[f[l]]=f[r];
}
for(int i=1;i<=n;i++)
b[find(i)].push_back(i);
for(int i=1;i<=n;i++){
if(f[i]!=i)continue;int now=0;
for(int j=0,to=b[i].size();j<to;j++){
c[a[b[i][j]]]++;
if(c[a[b[i][j]]]>now)now=c[a[b[i][j]]];
}
ans+=b[i].size()-now;
for(int j=0,to=b[i].size();j<to;j++)c[a[b[i][j]]]--;
}printf("%d",ans);
return 0;
}

D

挖坑~

E

挖坑~

F Video Cards

给你一列数a[],选择一个标准,使得其他的数减小至他的倍数,使得和最大?

CF给的标签:brute force(暴力)implementation(实现)number theory(数论)-醉了F是个送肉题。。。FST。。。。直接看代码吧暴力也分优美与垃圾TLE on Test 23(P都过了,2×10^5都过了,结果FST,10^4没过)-暴力加break

// <F.cpp> - Sun Oct 16 17:45:40 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is.#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long LL;
const int MAXN=200010;
inline int gi() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
int a[MAXN];LL f[MAXN];
int main()
{
int n=gi();LL ans=0;
for(int i=1;i<=n;i++)a[i]=gi();
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)f[i]=f[i-1]+a[i];
for(int i=1;i<=n;i++){
LL now=a[i];
for(int j=n;j>i;j--){
if(now+f[j]-f[i]<=ans)break;
now+=a[j]/a[i]*a[i];
}
if(now>ans)ans=now;
}printf("%I64d",ans);
return 0;
}

AC-暴力+统计

// <F.cpp> - Sun Oct 16 17:45:40 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is.#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef long long LL;
const int MAXN=200001;
inline int gi() {
register int w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
LL s[MAXN];int a[MAXN];
int main()
{
freopen("F.in","r",stdin);
freopen("F.out","w",stdout);
int n=gi();LL ans=0;
for(int i=1;i<=n;i++)a[gi()]++;
for(int i=1;i<MAXN;i++)s[i]=s[i-1]+a[i];
for(int i=1;i<MAXN;i++)
if(a[i]){
LL now=0;int t=MAXN/i;
for(int j=1;j<t;j++)
now+=1LL*(s[i*(j+1)-1]-s[i*j-1])*j*i;
now+=1LL*(s[MAXN-1]-s[i*t-1])*i*t;
if(now>ans)ans=now;
}
printf("%lld",ans);
return 0;
}

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,991
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,505
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,349
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,134
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,766
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,844