SDNU_ACM_ICPC_2020_Winter_Practice_1st
Petya is a big fan of mathematics, esecially its part related to fractions. Recently he learned that a fraction is called proper iff its numerator is smaller than its denominator (a < b) and that the fraction is called irreducible if its numerator and its denominator are coprime (they do not have positive common divisors except 1).
During his free time, Petya thinks about proper irreducible fractions and converts them to decimals using the calculator. One day he mistakenly pressed addition button ( + ) instead of division button (÷) and got sum of numerator and denominator that was equal to n instead of the expected decimal notation.
Petya wanted to restore the original fraction, but soon he realized that it might not be done uniquely. That's why he decided to determine maximum possible proper irreducible fraction such that sum of its numerator and denominator equals n. Help Petya deal with this problem.
Input
In the only line of input there is an integer n (3 ≤ n ≤ 1000), the sum of numerator and denominator of the fraction.
Output
Output two space-separated positive integers a and b, numerator and denominator of the maximum possible proper irreducible fraction satisfying the given sum.
Examples
3
1 2
4
1 3
12
5 7
#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,b;
cin>>n; for(int i=n/;i>=;--i)
{
b=n-i;
int w=;
for(int j=;j<=i;j++)
{
if(b%j==&&i%j==)
{
w=;
break;
} }
if(w==)
{
cout<<i<<" "<<b;
return ;
}
}
cout<<"1 "<<n-;
return ;
}
B
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.
Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.
Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.
Input
The only line of the input contains two integers: n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ n).
Output
Print the minimum possible and the maximum possible number of apartments good for Maxim.
Example
6 3
1 3
Note
In the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good.
#include <iostream>
using namespace std;
int main()
{
long long n,k;
cin>>n>>k;
if(k==||k==n)
{
cout<<"0 0";
return ;
}
else
{
long long t=*k,w=n-k;
if(t<=n)
cout<<"1 "<<*k;
else
cout<<"1 "<<w;
}
return ;
}
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day.
Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created.
All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so — their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule.
Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport.
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart.
The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 107), here ci is the cost of delaying the i-th flight for one minute.
Output
The first line must contain the minimum possible total cost of delaying the flights.
The second line must contain n different integers t1, t2, ..., tn (k + 1 ≤ ti ≤ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them.
Example
5 2
4 2 1 10 2
3 6 7 4 5 E
Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.
Initially there are k cycles, i-th of them consisting of exactly vi vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle with at least 2 vertices (for example, x vertices) among all available cycles and replace it by two cycles with p and x - p vertices where 1 ≤ p < x is chosen by the player. The player who cannot make a move loses the game (and his life!).
Peter wants to test some configurations of initial cycle sets before he actually plays with Dr. Octopus. Initially he has an empty set. In the i-th test he adds a cycle with ai vertices to the set (this is actually a multiset because it can contain two or more identical cycles). After each test, Peter wants to know that if the players begin the game with the current set of cycles, who wins?
Peter is pretty good at math, but now he asks you to help.
Input
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make.
The second line contains n space separated integers a1, a2, ..., an (1 ≤ ai ≤ 109), i-th of them stands for the number of vertices in the cycle added before the i-th test.
Output
Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.
Examples
3
1 2 3
2
1
1
5
1 1 5 1 1
2
2
2
2
2
Note
In the first sample test:
In Peter's first test, there's only one cycle with 1 vertex. First player cannot make a move and loses.
In his second test, there's one cycle with 1 vertex and one with 2. No one can make a move on the cycle with 1 vertex. First player can replace the second cycle with two cycles of 1 vertex and second player can't make any move and loses.
In his third test, cycles have 1, 2 and 3 vertices. Like last test, no one can make a move on the first cycle. First player can replace the third cycle with one cycle with size 1 and one with size 2. Now cycles have 1, 1, 2, 2 vertices. Second player's only move is to replace a cycle of size 2 with 2 cycles of size 1. And cycles are 1, 1, 1, 1, 2. First player replaces the last cycle with 2 cycles with size 1 and wins.
In the second sample test:
Having cycles of size 1 is like not having them (because no one can make a move on them).
In Peter's third test: There a cycle of size 5 (others don't matter). First player has two options: replace it with cycles of sizes 1 and 4 or 2 and 3.
- If he replaces it with cycles of sizes 1 and 4: Only second cycle matters. Second player will replace it with 2 cycles of sizes 2. First player's only option to replace one of them with two cycles of size 1. Second player does the same thing with the other cycle. First player can't make any move and loses.
- If he replaces it with cycles of sizes 2 and 3: Second player will replace the cycle of size 3 with two of sizes 1 and 2. Now only cycles with more than one vertex are two cycles of size 2. As shown in previous case, with 2 cycles of size 2 second player wins.
#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
int n,a[];
cin>>n;
int sum=;
for(int i=;i<n;i++)
{
cin>>a[i];
sum+=a[i]-;
if(sum%!=)
cout<<""<<endl;
else
cout<<""<<endl;
}
return ;
}
SDNU_ACM_ICPC_2020_Winter_Practice_1st的更多相关文章
随机推荐
- 【Python】数值运算操作符
- EF CodeFirst 一对一、一对多、多对多关系
一对一关系 如图,无需专门指定,系统会默认在Person表中生成字段Pet_Id为Pet表的外键(一对一). Require:必要的(一对一) Optional:可选的(一对零) Principa ...
- abb画学号
MODULE Module2 VAR signaldi signaldi26; VAR signaldi signaldi37; VAR signaldi signaldi48; PROC main2 ...
- 《Java程序设计》第十一周学习总结
20175334 <Java程序设计>第十一周学习总结 教材学习内容总结 第十三章 URL类 一个URL对象通常包含最基本的三部分信息:协议.地址.资源. URL对象调用 InputStr ...
- Java连载77-Integer常用方法、Integer、int、String三者相互转化、自动装箱、自动拆箱
一.关于Integer中常用的方法 package com.bjpowernode.java_learning; public class D77_1_ { public static void ...
- python前后台交互相关配置
全局配置:全局样式.配置文件 在js下创建setting.js ,配置全局的settings.js import settings from '@/assets/js/settings' Vue.pr ...
- Equalize
You are given two binary strings aa and bb of the same length. You can perform the following two ope ...
- analog filter
理想的filter如下: 但是实际的filter如下: 在实际应用中,我们更多的是用Fo和Q这两个parameter来design analog filter. Low-Pass Filter tra ...
- C语言编译和链接详解(通俗易懂,深入本质)
我们平时所说的程序,是指双击后就可以直接运行的程序,这样的程序被称为可执行程序(Executable Program).在 Windows 下,可执行程序的后缀有.exe和.com(其中.exe比较常 ...
- HTML学习(2)编辑器
HTML编辑常用的编辑器:Notepad++.Sublime Text.VS Code 可以使用Emmet插件来提高编码速度. 注:emmet只支持32位的Notepad++. 注意这里要把这两个dl ...