Codeforces 1256A 1257A

来源:https://www.cnblogs.com/biaobiao88/archive/2019/11/14/11854396.html
-Advertisement-
Play Games

題目鏈接:https://codeforces.com/problemset/problem/1256/A A. Payment Without Change time limit per test 1 second memory limit per test 256 megabytes input ...


題目鏈接:https://codeforces.com/problemset/problem/1256/A

A. Payment Without Change time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

You have aa coins of value nn and bb coins of value 11. You always pay in exact change, so you want to know if there exist such xx and yy that if you take xx (0xa0≤x≤a) coins of value nn and yy (0yb0≤y≤b) coins of value 11, then the total value of taken coins will be SS.

You have to answer qq independent test cases.

Input

The first line of the input contains one integer qq (1q1041≤q≤104) — the number of test cases. Then qq test cases follow.

The only line of the test case contains four integers aa, bb, nn and SS (1a,b,n,S1091≤a,b,n,S≤109) — the number of coins of value nn, the number of coins of value 11, the value nn and the required total value.

Output

For the ii-th test case print the answer on it — YES (without quotes) if there exist such xx and yy that if you take xx coins of value nn and yy coins of value 11, then the total value of taken coins will be SS, and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example input Copy
4
1 2 3 4
1 2 3 6
5 2 6 27
3 3 5 18
output Copy
YES
NO
NO
YES
思路:輸入a,b,n,s,每個代表的意思為:a個含有價值n的硬幣、b個含有價值1的硬幣、價值為n的硬幣、由這些硬幣組成的目標數。先判斷b個為1的硬幣是否能直接達到s,能的話則直接輸出,不能的話則進行下一步。
先判斷價值為n的硬幣最多能取多少個,即s對n取整,再將s減去s/n,再判斷剩下的能不能由b個價值為1的硬幣組成,能的話則滿足,不能的話則不滿足。
AC代碼
#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    int q;
    cin >> q;
    while(q--)
    {
        int a = 0,b = 0,sum = 0,n = 0,s = 0,temp = 0,min1 = 0;
        cin >> a >> b >> n >> s;
        if(b >= s)
        {
            cout << "YES" << endl;
            continue;
        }
        temp = s / n;
        min1 = min(a,temp);
        sum = s - min1 * n;
        if(b >= sum)
        {
            cout << "YES" << endl;
            continue;
        }
        else
        {
            cout << "NO" << endl;
            continue;
        }
    }    
    return 0;
}

題目鏈接:https://codeforces.com/contest/1257/problem/A

A. Two Rival Students time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

You are the gym teacher in the school.

There are nn students in the row. And there are two rivalling students among them. The first one is in position aa, the second in position bb. Positions are numbered from 11 to nn from left to right.

Since they are rivals, you want to maximize the distance between them. If students are in positions pp and ss respectively, then distance between them is |ps||p−s|.

You can do the following operation at most xx times: choose two adjacent (neighbouring) students and swap them.

Calculate the maximum distance between two rivalling students after at most xx swaps.

Input

The first line contains one integer tt (1t1001≤t≤100) — the number of test cases.

The only line of each test case contains four integers nn, xx, aa and bb (2n1002≤n≤100, 0x1000≤x≤100, 1a,bn1≤a,b≤n, aba≠b) — the number of students in the row, the number of swaps which you can do, and positions of first and second rivaling students respectively.

Output

For each test case print one integer — the maximum distance between two rivaling students which you can obtain.

Example input Copy
3
5 1 3 2
100 33 100 1
6 0 2 3
output Copy
2
99
1
Note

In the first test case you can swap students in positions 33 and 44. And then the distance between the rivals is equal to |42|=2|4−2|=2.

In the second test case you don't have to swap students.

In the third test case you can't swap students.

 思路:情況1:兩個人的距離加上可移動的次數都小於等於最遠距離的話,直接輸出。

情況2:兩個人的距離加上可移動距離大於最遠距離,則說明可移動次數x足夠用了。再來判斷,要使兩個人達到最遠距離,與最遠距離還差多少,如果可移動次數x大於差值,則兩人的距離可達最大,否則兩個人的最遠距離為原先的距離加上可移動距離x,即為答案

AC代碼

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int juli,n,x,a,b;
        cin >> n >> x >> a >> b;
        juli = abs(a - b);
        if(juli + x <= n - 1)//移動後的距離 小於等於 最遠距離 
        {
            cout << x + juli << endl;//直接輸出 
            continue;
        }
        if(n - juli <= x)//n-juli為 離最遠距離差多少  
        {    
            cout << n - 1 << endl;
            continue;
        }
        else
        {
            cout << juli + x << endl;
            continue;
        }
    }
    return 0;
}
//100 25 70 10

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1、Content Type 的值類型: 1.1 application/json:消息主體是序列化後的 JSON 字元串 1.2 application/x www form urlencoded:數據被編碼為名稱/值對。這是標準的編碼格式 1.3 multipart/form data: 需要在 ...
  • 一、視頻列表中控制只允許一個視頻播放 註: call() :調用一個對象的一個方法,用另一個對象替換當前對象,例如: arrayA.call(A,args1,args2) ,即 A 對象調用 arrayA 對象的方法。 二、視頻列表播放時滑動頁面抖動 註 : app 預設最小高度: min heig ...
  • 二哥,我今年大二,看你分享的《阿裡巴巴 Java 開發手冊》上有一段內容說:“迴圈體內,拼接字元串最好使用 StringBuilder 的 append 方法,而不是 + 號操作符。”到底為什麼啊,我平常一直就用的‘+’號操作符啊!二哥有空的時候能否寫一篇文章分析一下呢? 就在昨天,一位叫小菜的讀者 ...
  • 例4 水仙花數 題目描述 一個三位整數(100~999),若各位數的立方和等於該數自身,則稱其為“水仙花數”(如:153=13+53+33),找出所有的這種數。 輸入格式 沒有輸入 輸出格式 若幹行,每行1個數字。 輸入樣例 無 輸出樣例 153 * * * ... * * * (輸出被和諧了) ( ...
  • 例3 Cantor表 題目描述 現代數學的著名證明之一是Georg Cantor證明瞭有理數是可枚舉的。他是用下麵這一張表來證明這一命題的: 1/1 1/2 1/3 1/4 …… 2/1 2/2 2/3 …… 3/1 3/2 …… 4/1 …… …… 現以z字型方法給上表的每項編號。方法為:第一項是 ...
  • from flask import Flask, url_for from werkzeug.routing import BaseConverter app = Flask(__name__) # 實現一個需求: # 一個url中,含有手機號碼的變數,必須限定這個變數的字元串格式滿足手機號碼的格式 ...
  • ### url_for的基本使用: "url_for"的第一個參數應該是視圖函數的名字的字元串,後面的參數就是傳遞給"url"的。 如果傳遞的參數之前在url中已經定義了,那麼這個參數就會被當成"path"傳遞給"url"; 如果傳遞的參數之前在url中沒有定義,那麼將會被當成查詢字元串的形式放在" ...
  • 併發與並行 併發:指兩個或多個事件在同一個時間段內發生。 並行:指兩個或多個事件在同一時刻發生(同時發生) 在操作系統中,安裝了多個程式,併發指的是在一段時間內巨集觀上有多個程式同時運行,這在單CPU系統中,每一時刻只能有一道程式執行,即微觀上這些程式是分時的交替運行,只不過是給人的感覺是同時運行,那 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...