小陈的开学第一周程序

本文记录了小陈在开学第一周参加的编程竞赛,包括AtCoder的Attack Survival和Powerful Discount Tickets题目,PTA的魔法优惠券和最大子列和问题,以及计蒜客的Digit sum问题。文章详细介绍了题意、解题思路和代码实现过程,分享了从超时到通过AC的解决策略。
摘要由CSDN通过智能技术生成

一、AtCoder

1.Attack Survival

题意

Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players’ scores in a game, which proceeds as follows.

A game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points.

When a player correctly answers a question, each of the other N−1 players receives minus one (−1) point. There is no other factor that affects the players’ scores.

At the end of a game, the players with 0 points
or lower are eliminated, and the remaining players survive.

In the last game, the players gave a total of Q correct answers, the i-th of which was given by Player Ai. For Kizahashi, write a program that determines whether each of the N players survived this game.
输出几轮得分后每个人是否存活下来

变量范围:

  1. All values in input are integers.
  2. 2≤N≤10^5
  3. 1≤K≤10^9
  4. 1≤Q≤10^5
  5. 1≤Ai≤N(1≤i≤Q)

输入

N K Q
A1
A2
.
.
.
AQ

输出

Print N lines. The i-th line should contain Yes if Player i survived the game, and No otherwise.

样例输入

6 3 4
3
1
3
2

样例输出

No
No
Yes
No
No
No

解题思路:

刚开始就是模拟题目的意思,但是超时了,后来用b数组记录一下他们得分的次数,就过了。

程序代码(TLE):

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int main(){
	int n,k,Q;
	cin>>n>>k>>Q;
	for(int i=1;i<=n;i++)
		a[i]=k;
	for(int i=1;i<=Q;i++){
		int temp;
		cin>>temp;
		for(int j=1;j<=n;j++){
			if(j!=temp)
				a[j]--;
		}
	}
	for(int i=1;i<=n;i++){
		if(a[i]<=0)
			cout<<"No"<<endl;
		else
			cout<<"Yes"<<endl;
	}
	return 0;
}

程序代码(AC):

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int a[N];
int b[N];
int mai
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值