当前位置:网站首页># CF #808 Div.2(A - C)
# CF #808 Div.2(A - C)
2022-07-25 02:47:00 【a simple_ boy】
A Difference Operations( thinking , intuition )
Description:
Give the array a, about i (2 <= i <= n) It can be executed ai = ai - a_i-1 The operation of
Could you let me know (2 <= i <= n) Of ai Zero clearing
Solution:
yes a1 The multiple of can be cleared as 0, Second cut
Code:
void solve()
{
cin >> n;
int x;
cin >> x;
bool ok = true;
for(int i = 1; i < n; i ++)
{
int xx;
cin >> xx;
if(xx % x != 0)
ok = false;
}
if(ok)
cout << "YES\n";
else
cout << "NO\n";
}
B Difference of GCDs( thinking , structure )
Description:
give n, And interval [l, r]. You need to construct a sequence ai (1 <= i <= n) bring gcd(i, ai) Each are not identical
If there is a solution , Output YES And sequence a, No solution output NO
Solution:
because i The value is [1, n], therefore gcd If the result is different , It must be distributed in [1, n]( gcd(a, b) <= min(a, b) )
Since it is distributed like this , We might as well order gcd(i, ai) == i, because ai It's not said that you can't take duplicates , So directly for each i Go to [l, r] Look inside i The first multiple of
Code:
int n;
LL l, r;
void solve()
{
cin >> n >> l >> r;
vector<LL> res;
for(int i = 1; i <= n; i ++)
{
LL st = i * ((l + i - 1) / i); // Round up
if(st > r)
{
cout << "NO\n";
return;
}
else
res.pb(st);
}
cout << "YES\n";
for(auto x : res)
cout << x << ' ';
cout << '\n';
}
C Doremy’s IQ( greedy , Guess the conclusion )
Description:
Yes n Game and initial IQ q, Decide whether to participate in the i game , If participating in section i Games and q < ai When ,q –
Only q > 0 When , Can participate in the competition
Output one 01 strand ,1 Means to participate in the game , Ask for 1 As much as possible
Solution:
At first I thought it was DP, But found DP You can't save q(q = 1e9) This state means , Thought it was greedy but didn't think of a strategy .
After the game, I read the big man's solution , It's what I guessed , But I can't convince myself that it's right . Be positive next time WA Try it
6 4
5 4 4 4 4 4
Through this example, we find , A positive ergodic solution cannot be obtained . We need to think backwards .
You can think of it greedily , At the end, I just put q Flowers , And only possible to participate in the competition . Then the question becomes when to choose to participate in the competition .
Look backwards , If current position q_now < a_i, Play in your current position and make q_now ++, In this case, we will ensure that all the following items are taken , At present q_now Has been the best strategy .
Code:
const int N = 100005;
int n, q;
int a[N];
int res[N];
void solve()
{
memset(res, 0, sizeof res);
cin >> n >> q;
for(int i = 1; i <= n; i ++)
cin >> a[i];
int cur = 0;
for(int i = n; i >= 1; i --)
{
if(cur >= a[i])
res[i] = 1;
else if(cur < q)
cur ++, res[i] = 1;
}
for(int i = 1; i <= n; i ++)
cout << res[i];
cout << '\n';
}
边栏推荐
- @Retryable @backoff @recover retry the use of annotations
- Introduction to web security telent testing and defense
- StrError and PERROR
- Actual combat in ThreadLocal project
- 【C】 Advanced knowledge of file operation
- Vite dynamically loads static resource pictures, and fixes the 404 problem of pictures after packaging.
- English grammar_ Reflexive pronoun
- Several dpdk control frameworks
- Vulntarget vulnerability shooting range -vulntarget-b
- Digital business cloud: how to realize the application value of supplier SRM management system?
猜你喜欢

Redux best practices "Redux toolkit"

TS uses a third-party library, and there is no type declaration file error handling

Classic network learning RESNET code implementation

Explorer TSSD 2019 software installation package download and installation tutorial

SQL Server 2022 installation

Mgre.hdlc.ppp.chap.nat comprehensive experiment
It's still a synchronization problem

These 11 chrome artifacts are extremely cool to use

Sequence diagram of UML diagram series

Talk about what's going on with C # backstage GC?
随机推荐
MySQL common function summary, very practical, often encountered in interviews
Ten year structure and five-year Life-03 trouble as a technical team leader
My creation anniversary (3rd Anniversary)
Mp4 package analysis
After upgrading v2.1.0, the synchronization failed
Read and upgrade st-link chip information and SWD burning media through STM32 stlink utility tool
Inheritance (prototype)
"Introduction to interface testing" punch in to learn day07: websocket interface: how to test a completely unfamiliar protocol interface?
[TinyML]EfficientFormer:Vision Transformers at MobileNet Speed
Keil compile download error: no algorithm found for: 08000000h - 08001233h solution
Wechat sports field reservation of the finished works of the applet graduation project (6) opening defense ppt
Simulate the implementation of StrCmp function
YuQue - a useful tool for document writing and knowledge precipitation
Redux best practices "Redux toolkit"
ByteDance confirmation will be self-developed chip: for internal use only; Musk: I have uploaded my brain to the cloud; Go language product head leaves | geek headline
Server performance monitoring
R language one page and many pictures
[pyGame practice] nostalgic classic - do you remember the name of this chess game for children? (must collect)
Generator set work arrangement problem code
ICO objects in classification