计蒜客----训练联盟赛ICPC Northeastern European Regional Contest 2018

我喜欢给自己压力,必须得定一个很高的目标,逼自己朝着这个目标前进,不管会不会实现,都是一个动力。                                      ----喻言

                                                          E. Easy Chess

Elma is learning chess figures.

She learned that a rook can move either horizontally or vertically. To enhance her understanding of rook movement Elma's grandmother gave Elma an 8 × 8 chess board and asked her to find a way to move the rook from a1 to h8 making exactly nn moves, so that all visited cells are different.

A visited cell is the initial cell a1 and each cell on which the rook lands after a move.

Input

The input contains a single integer nn (2 ≤ n ≤ 63)(2≤n≤63) — the desired number of moves.

Output

Output a space-separated list of n+1n+1 visited cells in the order they are visited by the rook. All cells must be different. The list should start with a1 and end with h8. A solution always exists.

本题答案不唯一,符合要求的答案均正确

样例输入复制

4

样例输出复制

a1 f1 c1 c8 h8

样例解释

计蒜客----训练联盟赛ICPC Northeastern European Regional Contest 2018_第1张图片

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mod=1e9+7;
int n,fg[10][10],x=1,y=1;
int main(){
	cin>>n;
	fg[1][1]=1;
	fg[8][8]=1;
	cout<<"a1 ";
	n--;
	while(n--){
		if (n<=5&&x!=8&&y!=8)
            y=8;
        else{
            int ls=0;
            for (int i=8;; i--) 
				if (fg[i][y]==0) {
                	ls=i;
                	break;
            	}
            if(ls!=0) 
				x=ls; 
			else 
				y++;
        }
        fg[x][y]=1;
        cout<

                                                        F. Fractions

You are given a positive integer nn.

Find a sequence of fractions \frac {a_i} {b_i}, i = 1...kbi​ai​​,i=1...k(where a_iai​ and b_ibi​ are positive integers) for some kk such that:

 

\begin{cases} b_i \text{ divides } n, 1

 

Input

The input consists of a single integer n (2 ≤ n ≤ 10^9)n(2≤n≤109).

Output

In the first line print "YES" if there exists such a sequence of fractions or "NO" otherwise.

If there exists such a sequence, next lines should contain a description of the sequence in the following format.

The second line should contain integer k (1 ≤ k ≤ 100000)k(1≤k≤100000) — the number of elements in the sequence. It is guaranteed that if such a sequence exists, then there exists a sequence of length at most 100000.

Next kk lines should contain fractions of the sequence with two integers a_iai​ and b_ibi​ on each line.

本题答案不唯一,符合要求的答案均正确

样例输入1复制

2

样例输出1复制

NO

样例输入2复制

6

样例输出2复制

YES
2
1 2
1 3

计蒜客----训练联盟赛ICPC Northeastern European Regional Contest 2018_第2张图片

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mod=1e9+7;
int k, ct, tt;
int prime[100010], p[20];
bool vis[100010];
int exgcd(int a, int b, int &x, int &y)
{
    if(!b) 
		return x=1, y=0, a;
    int ans=exgcd(b, a % b, x, y);
    int ls=x; 
	x=y;
	y=ls-a/b*y;
    return ans;
}
void getprime()
{
	int sq=sqrt(k), bc=k;
	for (int i=2; i<=sq; i++)
	{
		if (!vis[i])
		{
			prime[++ct]=i;
			if (!(bc%i)){
				bc/=i, p[++tt]=i;
				while(!(bc%i)) 
					bc/=i;
			}
		}
		for (int j=1; j<=ct; j++)
		{
			if (prime[j]*i>sq) 
				break;
			vis[prime[j]*i]=true;
			if (!(i%prime[j])) 
				break;
		}
	}
	if(bc!=1&&bc>sq) 
		p[++tt]=bc;
}
int main()
{
	scanf("%d", &k);
	getprime();
	int x, y;
	if (tt==1){
		printf("NO\n"); 
		return 0;
	}
	printf("YES\n");
	int gcd=exgcd(p[1], p[2], x, y);
	int g1=k/p[1], g2=k/p[2];
	if (x<0) 
		printf("2\n%d %d\n%d %d", -x, g1, g2 - y, g2);
	else 
		printf("2\n%d %d\n%d %d", g1 - x, g1, -y, g2);
	return 0;
}

                                                    G. Guest Student

Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country.

Berland State University works every day of the week, but classes for guest students are held on the following schedule. You know the sequence of seven integers a_1, a_2, . . . , a_7a1​,a2​,...,a7​ (a_i = 0ai​=0 or a_i = 1ai​=1):

  • a_1 = 1a1​=1 if and only if there are classes for guest students on Sundays;
  • a_2 = 1a2​=1 if and only if there are classes for guest students on Mondays;
  • ...
  • a_7 = 1a7​=1 if and only if there are classes for guest students on Saturdays.

The classes for guest students are held in at least one day of a week.

You want to visit the capital of Berland and spend the minimum number of days in it to study kk days as a guest student in Berland State University. Write a program to find the length of the shortest continuous period of days to stay in the capital to study exactly kk days as a guest student.

Input

The first line of the input contains integer t (1 ≤ t ≤ 10 000)t(1≤t≤10000) — the number of test cases to process. For each test case independently solve the problem and print the answer.

Each test case consists of two lines. The first of them contains integer k (1 ≤ k ≤ 10^8)k(1≤k≤108) — the required number of days to study as a guest student. The second line contains exactly seven integers a_1, a_2, . . . , a_7a1​,a2​,...,a7​ (a_i = 0ai​=0 or a_i = 1ai​=1) where a_i = 1ai​=1 if and only if classes for guest students are held on the i-th day of a week.

Output

Print tt lines, the ii-th line should contain the answer for the ii-th test case — the length of the shortest continuous period of days you need to stay to study exactly kk days as a guest student.

样例输入复制

3
2
0 1 0 0 0 0 0
100000000
1 0 0 0 1 0 1
1
1 0 0 0 0 0 0

样例输出复制

8
233333332
1

样例解释

In the first test case you must arrive to the capital of Berland on Monday, have classes on this day, spenda week until next Monday and have classes on the next Monday. In total you need to spend 8 days in thecapital of Berland.

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mod=1e9+7;
ll t,k,a[10];
int main(){
	scanf("%lld",&t);
	while(t--){
		ll ti=0,xi,jg=inf,ct;
		scanf("%lld",&k);
		for(int i=1;i<=7;i++){
			scanf("%lld",&a[i]);
			ti+=a[i];
		}
		for(int i=1;i<=7;i++){
			xi=k%ti+ti;
			ct=0;
			int j=i;
			for(ct=1;;ct++){
				if(a[j]==1)
					xi--;
				j=j%7+1;
				if(xi==0)
					break;
			}
			jg=min(jg,ct);
		}
		printf("%lld\n",jg+(k/ti-1)*7);
	}
	return 0;
}

                                                          L. Lazyland

The kingdom of Lazyland is the home to nn idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland.

Today kk important jobs for the kingdom (k ≤ n)(k≤n) should be performed. Every job should be done by one person and every person can do at most one job. The King allowed every idler to choose one job they wanted to do and the ii-th idler has chosen the job a_iai​.

Unfortunately, some jobs may not be chosen by anyone, so the King has to persuade some idlers to choose another job. The King knows that it takes b_ibi​ minutes to persuade the ii-th idler. He asked his minister of labour to calculate the minimum total time he needs to spend persuading the idlers to get all the jobs done. Can you help him?

Input

The first line of the input contains two integers nn and kk (1 ≤ k ≤ n ≤ 10^5)(1≤k≤n≤105) — the number of idlers and the number of jobs.

The second line of the input contains nn integers a_1, a_2, . . . , a_na1​,a2​,...,an​ (1 ≤ a_i ≤ k)(1≤ai​≤k) — the jobs chosen by each idler.

The third line of the input contains nn integers b_1, b_2, . . . , b_nb1​,b2​,...,bn​ (1 ≤ b_i ≤ 10^9)(1≤bi​≤109) — the time the King needs to spend to persuade the ii-th idler.

Output

The only line of the output should contain one number — the minimum total time the King needs to spend persuading the idlers to get all the jobs done.

样例输入1复制

8 7
1 1 3 1 5 3 7 1
5 7 4 8 1 3 5 2

样例输出1复制

10

样例输入2复制

3 3
3 1 2
5 3 4

样例输出2复制

0
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include//INT_MAX
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int mod=1e9+7;
struct node
{
	ll a;
	ll b;
}p[100010];
int n,q;
ll ct=1,jg=0,fg[100010];
bool cmp(node x,node y)
{
	return x.a1)
				{
					fg[p[j].b]--;
					jg+=p[j].a;
					ct=j+1;
					break;
				}
			}
		}
	}
	printf("%lld\n",jg);
	return 0;
}

 

你可能感兴趣的:(计蒜客)