codeforces 1500分题目(持续更新)

题解等有空再补(拖延症晚期)

580A - Kefa and First Steps

https://codeforces.com/contest/580/problem/A

最长连续子序列的在线处理。

#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<stdio.h>
#include<string>
#include<math.h>
#include<map>
#include<stdlib.h>
#ifndef NULL
#define NULL 0
#endif
#define maxn 10000
using namespace std;

typedef long long ll;
int a[100001],f[100001];
int main()
{
	int n,maxx=0,ans=1;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n; i++) {
		if (a[i] < a[i - 1]) {
			maxx = max(maxx, ans);
			ans = 0;
		}
		ans++;
	}
	if (a[n - 1] >= a[n - 2])
		maxx = max(ans, maxx);
	cout << maxx << endl;
	return 0;
}

580C - Kefa and Park

https://codeforces.com/contest/580/problem/C

前向星+dfs。
连续的m个点就return
到达新的节点且该节点无可以继续访问的节点,就认为它是叶子节点。

#include<iostream>
#include<queue>
#include<cstring>
using namespace std;

typedef struct vec* nd;
struct vec{
	int e;
	nd next;
};
nd head[100010];
int n,m,f[100010],visit[100010],ans=0,cnt;
int read()
{
	int f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')	f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
void dfs(int s)
{
	nd p=head[s];
    int flag=0;
	for(;p!=0;p=p->next)
		if(!visit[p->e]){
			int t=cnt;
			flag=1;
			f[p->e]?cnt+=1:cnt=0;
			if(cnt>m){
				cnt=t;
				continue;
			}
			visit[p->e]=1;
			dfs(p->e);
			cnt=t;
			visit[p->e]=0;
		}
    if(flag==0)
        ans++;
}
void close(nd p)
{
	if(p==0)
		return ;
	close(p->next);
	delete(p);
}
int main()
{
	n=read(),m=read();
	memset(head,0,sizeof(head));
	for(int i=1;i<=n;i++)
		f[i]=read();
	for(int i=1;i<n;i++){
		nd p=new(vec ),ip=new(vec );
		int s=read();p->e=read();
		p->next=head[s];
		head[s]=p;
    	ip->e=s;s=p->e;
		ip->next=head[s];
		head[s]=ip;
	}
	cnt=f[1];
    visit[1]=1;
	dfs(1);
	cout<<ans<<endl;
	for(int i=1;i<=n;i++)
		close(head[i]);
	return 0;
}

479C - Exams

http://codeforces.com/problemset/problem/479/C

排序后贪心

/**********************
479C
**********************/
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;

typedef long long ll;
struct vec{
	int a,b;
}p[5010];

ll read()
{
	ll f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x;
}
bool cmp(vec x,vec y)
{
	if(x.a!=y.a)
		return x.a<y.a;
	return x.b<y.b;
}
int main()
{
	int time=0,n=read();
	for(int i=0;i<n;i++)
		p[i].a=read(),p[i].b=read();
	sort(p,p+n,cmp);
	time=p[0].b;
	for(int i=0;i<n;i++)
		if(time>p[i].b)
			time=p[i].a;
		else
			time=p[i].b;
	cout<<time<<endl;
}

550C - Divisibility by Eight

http://codeforces.com/problemset/problem/550/C

神仙题目,暴力枚举,大于四位的数只需要考虑后三位即可。
列入数abcd,可分解为(a000+bcd)%8==a000%8+bcd%8,则必然a000整除8。
在s前加两个零,以保证枚举的bcd是从1位到3位数字。

/**********************
550C
**********************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;

typedef long long ll;
string s1,s;
int a[110]={0};

ll read()
{
	ll f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x;
}
int main()
{
	cin>>s;
	s="00"+s;
	int len=s.length();
	for(int i=0;i<len;i++)
		for(int j=i+1;j<len;j++)
			for(int k=j+1;k<len;k++){
				int x=(s[i]-'0')*100+(s[j]-'0')*10+s[k]-'0';
				if(x%8==0){
					printf("YES\n%d\n",x);
					return 0;
				}
			}
	cout<<"NO"<<endl;
	return 0;
}

545C - Woodcutters

http://codeforces.com/problemset/problem/545/C

特判一下两个端点和只有一棵树的时候。
贪心。

/**********************
545C
**********************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;

typedef long long ll;
struct vec
{
	int a,b	;
} p[1000010];

ll read()
{
	ll f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x;
}
int main()
{
	int ans=0,n;
	n=read();
	for(int i=0;i<n;i++)
		p[i].a=read(),p[i].b=read();
	if(n==1)
		ans=1;
	else
		ans=2;
	for(int i=1;i<n-1;i++)
		if(p[i].a-p[i-1].a>p[i].b)
			ans++;
		else if(p[i+1].a-p[i].a>p[i].b){
			ans++;
			p[i].a+=p[i].b;
		}
	cout<<ans<<endl;
	return 0;
}

1152B - Neko Performs Cat Furrier Transform

https://codeforces.com/contest/1152/problem/B

先异或
再加一
问循环这两步,是否有可能让x变成2n-1的数.

#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#ifndef NULL
#define NULL 0
#endif
const int MAX = 10100;
const int MaxTableSize = 50100;
using namespace std;

long long a[] = { 0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215,33554431,67108863,134217727,268435455,536870911,1073741823,2147483647,4294967295,8589934591,17179869183,34359738367,68719476735,137438953471,274877906943,549755813887,1099511627775,2199023255551,4398046511103,8796093022207,17592186044415,35184372088831,70368744177663,140737488355327,281474976710655,562949953421311,1125899906842623,2251799813685247,4503599627370495,9007199254740991,18014398509481983,36028797018963967,72057594037927935,144115188075855871,288230376151711743,576460752303423487,1152921504606846975,2305843009213693951,4611686018427387903,9223372036854775807 };
long long num[41];

long long read()
{
	int x = 0, f = 1; char c = getchar();
	while (c<'0' || c>'9') {
		if (c == '-')
			f = -1;
		c = getchar();
	}
	while (c >= '0'&&c <= '9') {
		x = x * 10 + c - '0';
		c = getchar();
	}
	return x * f;
}
int main()
{
	long long x = read(),tot=0,ans=0;
	while (1) {
		int pos1 = lower_bound(a, a + 63, x) - a, tp=-1;
		if (a[pos1] == x) {
			cout << ans << '\n';
			break;
		}
		for (long long t = x, i = 0; t > 0; i++, t >>= 1)
			if (!(t & 1))
				tp = i;
		tp++,ans++;
		num[++tot] = tp;
		x ^= a[tp];
		pos1 = lower_bound(a, a + 63, x) - a;
		if (a[pos1] == x) {
			cout << ans << '\n';
			break;
		}
		x++,ans++;
	}
	for (int i = 1; i <= tot; i++)
		cout << num[i] << ' ';
	return 0;
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Codeforces估分是指在Codeforces比赛中预估自己在比赛结束后所能获得的分数。这个分数是考虑根据自己的表现和其他参赛者的表现来预估的。 Codeforces分数是根据比赛中的排名和成功解决问题的数量来计算的。在每场比赛结束后,每位参赛者会根据其在比赛中的表现被分配一个分数。比赛中排名越高的参赛者获得的分数也越高,而解决更多问题的参赛者同样也能获得更多分数。 Codeforces估分有两种方法:一种是通过比赛中的实时排名来估计当前分数,另一种是通过计算比赛中已解决问题的分数来估计最终的总分。 对于第一种方法,我们可以在比赛过程中观察自己在排名榜上的位置和其他参赛者的分数。如果自己的排名越高,说明自己的分数也会越高;如果其他人的分数与自己相差较大,说明他们可能已经解决了更多的问题,因此可能获得更高的分数。 对于第二种方法,我们可以根据已经解决的问题数量来估算总分。Codeforces的比赛系统会根据每个问题的难度和重要性分配不同的分数。因此,如果我们能成功解决更多的问题,我们也将获得更高的分数。 总的来说,Codeforces估分是一个根据比赛中的排名和解决问题的数量来估计自己分数的过程。但是,由于每场比赛的题目和参赛人数不同,预估分数可能有一定的不确定性。因此,我们建议在比赛过程中持续观察排名榜和其他参赛者的情况,以及时作出调整和优化自己的策略。 ### 回答2: Codeforces是一个在线的编程竞赛平台,每个竞赛都有一定的难度,需要通过编写代码来解决各种算法和数据结构的问题。Codeforces的估分指的是根据你在竞赛中的表现得出的一个评分。 在Codeforces竞赛中,你会根据你的解题情况和提交的答案是否正确来获得分数。每个问题都有一定的分值,解决该问题可以获得该分值的分数。如果你的答案是正确的,你将获得该问题的分数;如果你的答案是错误的,你将不会获得分数。 Codeforces的估分算法是基于Elo算法改进的。Elo算法是一种用于评估竞技选手水平的算法。该算法会根据你的表现和对手的水平来决定你的分数变化。如果你击败了一个分数比你高的选手,你的分数可能会上升得更多;如果你输给一个分数比你低的选手,你的分数可能会下降得更多。 Codeforces的估分也考虑了竞赛的参与人数。如果你在一个参与人数多的竞赛中获得了好的成绩,你的分数可能会得到进一步的提升。相反,如果你在一个参与人数少的竞赛中获得了好的成绩,你的分数可能会得到更少的提升。 总的来说,Codeforces的估分是根据你的表现、对手的水平和竞赛的参与人数来计算的。通过持续参与竞赛并取得好的成绩,你的分数将会逐渐提升。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值