Codeforces Round #615 (Div. 3) 题解

A - Collecting Coins

题意:

给你四个数a,b,c,d,n.问你是否能将n拆成三个数A,B,C,使得A+a=B+b=C+c。

思路:

先计算三个数的差值的绝对值abs,如果abs大于n则肯定不行,如果小于n,还需判断(n-abs)%3是否为0,不为0则不行。

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#define inf 0x3f3f3f3f
 using namespace std;
 typedef long long ll;
 ll max(ll a,ll b) {if(a>b) return a;return b;}
 int main()
 {
     int t;
     scanf("%d",&t);
     while(t--){
             int a[3],n;
     scanf("%d%d%d%d",&a[0],&a[1],&a[2],&n);
     sort(a,a+3);
     int x=(a[2]-a[1])*2+a[1]-a[0];
     if(x>n) cout<<"NO"<<endl;
     else{
         if((n-x)%3)    cout<<"NO"<<endl;
         else    cout<<"YES"<<endl;
     }
    }
     return 0;
 }

B - Collecting Packages

题意:

给出直角坐标系中的一些坐标,你只能向上(‘U‘)或向右(‘R‘)走,问你能否走完这些坐标,如果能请输出字典序最小的行进路线

思路:

直接按x坐标排序,如果有一个点的纵坐标在上一个点的纵坐标下方,则无法走。输出顺序只需要从上一个点先走R再走U走到下一个点即可

#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#define inf 0x3f3f3f3f
 using namespace std;
 typedef long long ll;
 ll max(ll a,ll b) {if(a>b) return a;return b;}
 const int maxn=1005;
 struct node{
     int x,y;
 }a[maxn];
 int cmp(node a,node b)
 {
     if(a.x==b.x)  return a.y<b.y;
     return a.x<b.x;
 }
 int main()
 {
     int t,n;
     scanf("%d",&t);
     while(t--){
         scanf("%d",&n);
         for(int i=0;i<n;i++)    scanf("%d%d",&a[i].x,&a[i].y);
         sort(a,a+n,cmp);
         int flag=0;
         for(int i=1;i<n;i++){
             if(a[i].y<a[i-1].y){
                 cout<<"NO"<<endl;
                 flag=1;
                 break;
             }
         }
        if(!flag){
            cout<<"YES"<<endl;
            for(int i=0;i<a[0].x;i++) cout<<"R";
            for(int i=0;i<a[0].y;i++) cout<<"U";
            for(int i=1;i<n;i++){
                for(int j=a[i-1].x;j<a[i].x;j++) cout<<"R";
                for(int j=a[i-1].y;j<a[i].y;j++) cout<<"U";
            }
            cout<<endl;
        }
     }
     return 0;
 }

C - Product of Three Numbers

题意:

给你一个数n,问你是否能将n分解成三个不同的数相乘,可以的话则输出任一解

思路:

只需要将遍历从2到,如果i为n的因子,就将i记录,并将n除以i。这样的操作执行三次之后,就可以跳出循环。

如果此时的x不等于1或者循环结束后x不为1,则将x放入数组的尾部,或者将数组的最后一个元素乘上x。

如果最后数组的元素小于3那么则不行,如果等于3的话还需判断一下,三个因数是否相同。

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
 using namespace std;
 vector<int> a;
 typedef long long ll;
 int main()
 {
     int n,t;
     scanf("%d",&t);
     while(t--){
         int cnt=0;
         a.clear();
         scanf("%d",&n);
         for(ll i=2;i*i<=n;i++){
             if(n%i==0){
                 a.push_back(i);
                 cnt++;
                 n/=i;
             }
            if(cnt==3) break;
         }
        if(n!=1){
            if(a.size()==3) a.back()*=n;
            else    a.push_back(n);
        }
        if(a.size()<3) cout<<"NO"<<endl;
        else{
            if(a[0]==a[1]||a[1]==a[2]||a[0]==a[2])    cout<<"NO"<<endl;
            else    cout<<"YES"<<endl,cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
        }
     }
    return 0;
 }

原文地址:https://www.cnblogs.com/overrate-wsj/p/12230489.html

时间: 2024-08-30 15:29:48

Codeforces Round #615 (Div. 3) 题解的相关文章

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

Codeforces Round #FF (Div. 2) 题解

比赛链接:http://codeforces.com/contest/447 A. DZY Loves Hash time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output DZY has a hash table with p buckets, numbered from 0 to p?-?1. He wants to insert n 

Codeforces Round #259 (Div. 2) 题解

A. Little Pony and Crystal Mine time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n?>?1) is an n?×?n 

Codeforces Round #177 (Div. 2) 题解

[前言]咦?现在怎么流行打CF了?于是当一帮大爷在执着的打div 1的时候,我偷偷的在刷div 2.至于怎么决定场次嘛,一般我报一个数字A,随便再拉一个人选一个数字B.然后开始做第A^B场.如果觉得机密性不高,来点取模吧.然后今天做的这场少有的AK了.(其实模拟赛只做完了4题,最后1题来不及打了) 等等,话说前面几题不用写题解了?算了,让我难得风光一下啦. [A] A. Polo the Penguin and Segments time limit per test 2 seconds mem

Codeforces Round #534 (Div. 2)题解

Codeforces Round #534 (Div. 2)题解 A. Splitting into digits 题目大意 将一个数字分成几部分,几部分求和既是原数,问如何分可以使得分出来的各个数之间的差值尽可能小 解题思路 将n分成n个1相加即可 AC代码 #include<cstring> #include<string> #include<iostream> #include<cstdio> using namespace std; int main

Codeforces Round #561 (Div. 2) 题解

Codeforces Round #561 (Div. 2) 题解 题目链接 A. Silent Classroom 水题. Code #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 105; int n; char s[N], t[N]; int main() { cin >> n; for(int i = 1; i <= n; i++) { scanf(&q

Codeforces Round #608 (Div. 2) 题解

目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 程序 D. Portals 题意 做法 程序 E. Common Number 题意 做法 程序 结束语 Codeforces Round #608 (Div. 2) 题解 前言 题目链接:仅仅只是为了方便以题目作为关键字能查找到我的题解而已(逃 Codeforces 1271A Codeforce

Codeforces Round #617 (Div. 3) 题解

目录 Codeforces Round #617 (Div. 3) 题解 前言 A. Array with Odd Sum 题意 做法 程序 B. Food Buying 题意 做法 程序 C. Yet Another Walking Robot 题意 做法 程序 D. Fight with Monsters 题意 做法 程序 E1. String Coloring (easy version) 题意 做法 程序 E2. String Coloring (hard version) 题意 做法

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F

[Codeforces Round #617 (Div. 3)] 题解 A,B,C,D,E1,E2,F 1296A - Array with Odd Sum 思路: 如果一开始数组的sum和是奇数,那么直接YES, 否则:如果存在一个奇数和一个偶数,答案为YES,否则为NO 代码: int n; int a[maxn]; int main() { //freopen("D:\\code\\text\\input.txt","r",stdin); //freopen(