ACM训练

这篇具有很好参考价值的文章主要介绍了ACM训练。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

input

standard input

output

standard output

A continued fraction is an expression of the form:

a0+1a1+1a2+1⋱+1ana0+1a1+1a2+1⋱+1an

where a0,a1,…,ana0,a1,…,an​ are nonnegative integers.

Given a fraction xyxy(x,yx,y are positive integers), please expand it into a continued fraction.

Input

The first line contains an integer TT (1≤T≤1031≤T≤103), denoting the number of test cases.

The only line of each test case contains two integers x,yx,y (1≤x,y≤1091≤x,y≤109), denoting a fraction xyxy. It's guaranteed that gcd(x,y)=1gcd(x,y)=1.

Output

For each test case, output one line: first an integer nn denoting the height of the continued fraction, then n+1n+1 integers denoting a0,…,ana0,…,an. Your solution should gurarantee that 0≤n≤1000≤n≤100, 0≤ai≤1090≤ai≤109.

If there are multiple valid solutions, you only need to output one of them.

Example

input

Copy

2
105 38
1 114

output

Copy

4 2 1 3 4 2
1 0 114

Note

For the convenience of you, we give explanation of sample:

10538=2+11+13+14+1210538=2+11+13+14+12

1114=0+11141114=0+1114

代码实现:文章来源地址https://www.toymoban.com/news/detail-660605.html

int x,y;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		
	int a[N];
		cin>>x>>y;
		int cnt=0;
		if(x==1||y==1)
		{
			if(x==1)
			{
				cout<<"1 0 "<<y<<"\n";
			}
			if(y==1)
				cout<<"1 0 "<<x<<"\n";
			continue;
		}
		
		while(x>1&&y>1)
		{
			a[cnt++]=x/y;
			x=x%y;
			swap(x,y);
		}
		if(x==1)
			a[cnt]=y;
		if(y==1)
			a[cnt]=x;
		cout<<cnt<<" ";
		for(int i=0;i<=cnt;i++)
			cout<<a[i]<<" ";
		cout<<"\n";
	}
	}

L. It Rains Again

Suppose that in a Cartesian coordinate system on an infinite plane, the x-axis represents the ground and there are n rainscreens (We don't consider their thickness.) in the sky.

Every rainscreen can be described as a segment which starts from the (x1,y1)(x1,y1) and ends at (x2,y2)(x2,y2). Now if it starts to rain from the infinite high sky, I want you to tell me how many units of the x-axis will not get rained on.

To simplify the problem,the rain can only move vertically whenever it falls.

Note that two rainscreens can overlap and intersect with each other, and there is no rainscreen which is placed vertically.

Input

The first line contains one positive integer n(1≤n≤100000)n(1≤n≤100000).

Each of the next n lines contains four positive integers x1,y1,x2,y2(1≤x1<x2≤100000,1≤y1,y2≤100000)x1,y1,x2,y2(1≤x1<x2≤100000,1≤y1,y2≤100000), representing a rainscreen which starts from the (x1,y1)(x1,y1) and ends at (x2,y2)(x2,y2).

Output

The only one integer - the number of units of the x-axis which will not get rained on.

Example

input

Copy

5
1 2 2 1
1 1 2 2
3 3 4 3
5 1 6 3
6 3 7 2

output

Copy

4

acmone蔷薇,算法,c++,图论

算法思想:

使用区间和算法的模板求出相对应的被覆盖的区间吗,然后通过总的区间数减去所覆盖的

的区间数即可,然后注意最后需要加上原来的剩余哪一个区间加一即可

代码实现;

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>PII;
const int N=1e5+10;
int n;
vector<PII> segs;
void merge(vector<PII>&segs)
{
    vector<PII>res;
    sort(segs.begin(),segs.end());
    int st=-2e9,ed=-2e9;
    for(auto seg:segs)
    if(ed<seg.first)
    {
        if(st!=-2e9)
        res.push_back({st,ed});
        st=seg.first,ed=seg.second;
    }
    else
    ed=max(ed,seg.second);
    if(st!=-2e9)
    res.push_back({st,ed});
    segs=res;
}
int main()
{
    cin>>n;
    int minx=0;
    for(int i=0;i<n;i++)
    {
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        segs.push_back({x1,x2});
         
       minx=max(minx,x2);
    }
    //cout<<minx<<"\n";
        merge(segs);
        cout<<(minx-segs.size())<<endl;
        return 0;
}

K

Gather sand to form a tower is a Chinese idiom, whose Pinyin is ju` sha¯ che´ng taˇju` sha¯ che´ng taˇ. It means to pile sand into a pagoda, referring that a little makes a lot. From the fahua Sutra - convenience products.

acmone蔷薇,算法,c++,图论

Suppose the tower has NN floors. There are i×ii×i rooms on the ithith floor. Each room can accommodate MM people. How many people can the NN floor tower accommodate?

Input

The first line is a positive integer T (1≤T≤100)T (1≤T≤100), indicating that there are TT test data.

Next, there are TT lines. Each line has two positive integers NN and M (1≤N,M≤100)M (1≤N,M≤100), indicating the number of floors of the tower and the number of people that can be accommodated in each room in a test data.

Output

Each test data outputs a line containing one positive integer, that is, the total number of people that can be accommodated in the NN floor tower.

Example

input

Copy

2
2 2
3 3

output

Copy

10
42

算法思想:只需要数组的基本知识即可进行相对应得代码 叠加求和 即可

代码实现:

 

#include<bits/stdc++.h>
using namespace std;
const int N=110;
int n,m;
int t;
int sum;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>m;
		sum=0;
		for(int i=1;i<=n;i++)
		{
			sum+=i*i*m;
		}
		cout<<sum<<"\n";
	}
	
}

H. Hearthstone So Easy

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Hearthstone is a turn-based card game. The game flow of each round is: Player 1 draws card ⇒⇒player 1 plays cards ⇒⇒player 2 draws card ⇒⇒player 2 plays cards.

We simplify the game logic as follows:

  • During each player's draw stage, the player attempts to draw a card from his or her deck.
  • During each player's playing stage, the player can choose:
    1. to increase his/her health by kk points. Note that there is no upper limit on health.
    2. to reduce the opponent's health by kk points.

When there are no cards in the player's card deck, the player will enter a state of fatigue. At this time, the player will increase his/her fatigue value by one every times he/she tries to draw a card, and then deduct the amount of health by the fatigue value. The fatigue value of each player is initially 00 points.

pllj and freesin like playing hearthstone very much. In a certain game, both players have no cards in their decks, and both the fatigue points are 00 points, and the health points are both nn points. When a player's health is less than or equal to 00, the player immediately loses the game.

At this time, it's pllj's turn to draw card. Both players are very smart, so they play the game optimally. Who will be the winner? Please output his name.

Input

The first line contains a single integer tt (1≤t≤1051≤t≤105), which represents the number of data cases.

Each group of data is a row of two positive integers n,kn,k separated by spaces (1≤n,k≤1091≤n,k≤109), of which meaning is described before.

Output

For each case of data, output a line of string pllj or freesin to indicate the winner.

Example

input

Copy

2
10 9
5 3

output

Copy

pllj
freesin

Note

For the first data case:

  • pllj's draw stage: pllj tries to draw cards from a empty deck. His fatigue value increases by 11 to become 11, and then pllj's health deducts by one point, leaving 99 health points.
  • pllj's playing stage: pllj causes 99 points of damage to freesin. After this time, freesin has 11 point of life left.
  • freesin's draw stage: freesin tries to draw cards from a empty deck. His fatigue value increases by 11 to become 11, and then freesin's health deducts by one point, leaving 00 points. At this time, freesin loses the game.

算法实现:

简单的博弈题,只需要考虑最后一个之前即可

代码实现:

#include <bits/stdc++.h>
using namespace std;
int  main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n,k;
        cin>>n>>k;
        if(n==1) 
		cout<<"freesin"<<"\n";
        else if(n<=k+1) 
		cout<<"pllj"<<"\n";
        else 
		cout<<"freesin"<<"\n";
    }
}

到了这里,关于ACM训练的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • NEUQ-ACM预备队训练-week9(最短路)

    洛谷原题 小K 喜欢翻看洛谷博客获取知识。每篇文章可能会有若干个(也有可能没有)参考文献的链接指向别的博客文章。小K 求知欲旺盛,如果他看了某篇文章,那么他一定会去看这篇文章的参考文献(如果他之前已经看过这篇参考文献的话就不用再看它了)。 假设洛谷博

    2024年02月03日
    浏览(19)
  • neuq-acm预备队训练week 8 P1144 最短路计数

    给出一个 N 个顶点 M条边的无向无权图,顶点编号为 1∼N。问从顶点 1 开始,到其他每个点的最短路有几条。 第一行包含 22 个正整数 N,M,为图的顶点数与边数。 接下来 M 行,每行 2个正整数 x,y,表示有一条由顶点 x 连向顶点 y 的边,请注意可能有自环与重边。 共

    2024年02月04日
    浏览(27)
  • NEUQ-acm第二期训练Week4——代码源div2

    RSA算法选择两个不同质数的积作为模数。现在有两个正整数 A,B,如果它们是不同的质数,则判定为 full credit;否则,如果A⋅B不是任意大于1的整数的平方的整数倍,则判定 partial credit;否则判定为no credit。 一行两个正整数 A,B。 full credit 或 partial credit 或 no credit。 数据规模

    2024年02月16日
    浏览(29)
  • 算法题的ACM模式与核心代码模式

    身为一名程序员,刷题网站系统我们应该再熟悉不过了,除了针对竞赛的 OJ 系统,比如:POJ;还有很多专为求职提供的刷题 OJ 系统,比如:leetcode、牛客网 等。 这两类 OJ 在刷题模式上有些区别,一般竞赛的 OJ 系统是针对 ACM 模式的,而求职的 OJ 系统是针对核心算法模式的

    2024年02月14日
    浏览(35)
  • 代码随想录-回溯算法(子集问题)|ACM模式

    目录 前言: 78. 子集 题目描述: 输入输出描述: 思路和想法: 90. 子集 II 题目描述: 输入输出描述: 思路和想法: 491. 递增子序列 题目描述: 输入输出描述: 思路和想法: 如果把 子集问题、组合问题、分割问题都抽象为一棵树的话, 那么组合问题和分割问题都是收集

    2024年02月15日
    浏览(30)
  • 代码随想录-回溯算法(分割问题)|ACM模式

    目录 前言: 131. 分割回文串 题目描述: 输入输出描述: 思路和想法: 93. 复原 IP 地址 题目描述: 输入输出描述: 思路和想法:          回溯算法中的分割问题,是可以抽象为组合问题的,其中模拟切割线、切割问题中递归如何终止以及递归循环中如何截取子串,是我们

    2024年02月15日
    浏览(33)
  • 【C++算法竞赛 · 图论】图论基础

    前言 图论基础 图的相关概念 图的定义 图的分类 按数量分类: 按边的类型分类: 边权 简单图 度 路径 连通 无向图 有向图 图的存储 方法概述 代码 复杂度 图论(Graph theory) ,是 OI 中的一样很大的一个模块,围绕它有很多高难度的算法以及高级的概念。 这篇文章将介绍关

    2024年04月12日
    浏览(33)
  • 图论与算法(1)图论概念

    在计算机科学中,图论与算法是两个重要且紧密相关的领域。图论研究图的性质和特征,而算法设计和分析解决问题的方法和步骤。图论提供了一种形式化的方法来描述和分析各种关系和连接,而算法则为解决图相关的问题提供了有效的解决方案。 图论是研究图的结构和性质

    2024年02月07日
    浏览(30)
  • 算法提高-图论-floyd算法及其扩展应用

    离散化 (只要用到200个点,但是题目给的点编号是1-1000)+ 倍增(快速幂)+ flyod变式(将递推公式改变了) 能用快速幂的原因是递推公式里面的两端路径两两之间相互独立,用结合律就可以用快速幂。矩阵乘法能用快速幂的原因也是矩阵乘法中两两矩阵之间具有结合律 帮助

    2024年02月09日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包