Educational Codeforces Round 178 div2(題解ABCDE)

A. Three Decks

#1.由于最后三個數會相等,提前算出來和,%3判斷,再判前兩個數是否大于

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e4 + 10;
void solve()
{int a,b,c;cin>>a>>b>>c;if((a+b+c)%3==0){int tmp=(a+b+c)/3;if((a<=tmp)&&(b<=tmp))cout<<"YES"<<endl;else cout<<"NO"<<endl;}else cout<<"NO"<<endl;
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t = 1;cin>>t;while (t--){solve();}return 0;
}

B. Move to the End

我們每次要從數組末尾拿1,2,3...一直到n?個數,對于每次取,我都可以拿一個數到數組末尾。

#1.為此我們可以取一個前綴max數組,討論從后向前的k個元素的前綴max是否大于這個元素

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e4 + 10;
void solve()
{int n;cin>>n;vector<ll>a(n+1);vector<ll>pre(n+1,0);for(int i=1;i<=n;i++){cin>>a[i];pre[i]=max(pre[i-1],a[i]);}ll sum=0;for(int i=n;i>=1;i--){sum+=a[i];if(pre[i-1]>a[i])cout<<sum-a[i]+pre[i-1]<<" ";else cout<<sum<<" ";}cout<<endl;
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t = 1;cin>>t;while (t--){solve();}return 0;
}

C. Card Game

有n張卡,編號大的克制編號小的,特別的1克制n,每回合Alice先出,Bob后手,如Alice克制Bob則得Alice得這兩張牌,反之Bob

#1.注意到由于Alice先手,只有無論Alice出任何牌Bob都能克制她時,Bob勝,其余情況Alice勝

#2.可以用vector存Alice的牌,set存Bob的牌,二分+特判

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e4 + 10;
void solve()
{int n;cin>>n;string s;cin>>s;vector<int>a;s="#"+s;set<int>st;bool tag=true;for(int i=1;i<=n;i++){if(s[i]=='A')a.push_back(i);else st.insert(i);}int l=a.size();for(int i=0;i<l;i++){if(a[i]==n){if(!(st.count(1)))tag=false;}else{auto it=st.upper_bound(a[i]);if(a[i]==1){if(*it==n)tag=false;}else{if(*it<a[i])tag=false;}}}if(tag)cout<<"Bob"<<endl;else cout<<"Alice"<<endl;
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t = 1;cin>>t;while (t--){solve();}return 0;
}

D. Array and GCD

給一個長為n的數組a,可以讓數組中的任一元素減1,另一元素加1,也可只減不加,最后問最少刪幾個元素能讓數組任意兩個元素之間互質,(刪元素要在操作之前),并且要保證操作后的數組中任意元素都是>=2的

#1. 要讓任意兩個元素之間互素,當數組中都是素數即可

#2.再來考慮操作,我能讓數組中任意元素變化,但數組的總和只能是不變或變小的,假設剩了x個元素,它最小應該是前x個素數相加。

#3.到這只需用歐拉篩篩到1e7(大概6e5個素數),在對素數做前綴和,即為保留i個元素,i個元素的總和至少為多少

#4.保持貪心性質,刪數只刪最小的

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e7 + 10;
const int M=1e6+4;
bool vis[N];
vector<int>primes;
ll pre[M];
void init(int x)
{vis[0]=vis[1]=true;for(int i=2;i<=x;i++){if(!vis[i])primes.push_back(i);int l=primes.size();for(int j=0;j<l&&primes[j]*i<=x;j++){vis[i*primes[j]]=true;if(i%primes[j]==0)break;}}
}
void solve()
{int n;cin>>n;vector<int>a(n+1);ll sum=0;for(int i=1;i<=n;i++)cin>>a[i],sum+=a[i];sort(a.begin()+1,a.end(),greater<int>());if(n<2){cout<<0<<endl;return;}for(int i=n;i>=2;i--){if(sum>=pre[i]){cout<<n-i<<endl;return;}sum-=a[i];}cout<<n-1<<endl;
}
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int t = 1;cin>>t;init(1e7);int l=primes.size();//cout<<l<<endl;for(int i=0;i<l;i++){pre[i+1]=pre[i]+primes[i];}while (t--){solve();}return 0;
}

E. Unpleasant Strings

給一個長為n的字符串s,其中只能出現26個字母前k個字母,q次詢問,每次詢問給一個字符串,對于每次詢問給出至少添加幾個字母能使它不為s的子序列。

#1.對于本就不是它的子序列的字符串,添加0個。那就需要判斷以一個字符串是否為另一個字符串的子序列。k很小,可以將每種字符用vector存起來,在判斷時,只需要遍歷要判斷的字符串,二分對于這個字符出現序列中第一個大于上一個位置的位置

#2.通過上述方法可以找到這個字符串作為子序列第一個末尾,對于后續元素至少要添加的元素數量,我們可以采用后綴和提前預處理出答案,后綴和是從后向前遍歷,將k個元素都出現的一段視作1,再做后綴和

#include<iostream>
#include<vector>
#include<stdio.h>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#include<cstring>
#include<stack>
#include<array>
#include<cmath>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<iomanip>
using namespace std;
using ll = long long;
using llu = unsigned long long;
const ll inf = 0x3f3f3f3f3f3f3f3fll;
const ll MIN = -9187201950435737472ll;
ll mod = 1e9 + 7;
ll base = 131;
const int N = 1e4 + 10;
int main()
{ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);int l,q,k;cin>>l>>k;string s;cin>>s;string str;vector<vector<int>>dp(k+1,vector<int>());vector<ll>suf(l+3,0);s="#"+s;for(int i=1;i<=l;i++){dp[s[i]-'a'+1].push_back(i);}suf[l]=0;int cnt=0;vector<bool>vis(k+1,false);for(int i=l-1;i>=0;i--){if(!vis[s[i+1]-'a'+1])cnt++,vis[s[i+1]-'a'+1]=true;suf[i]=suf[i+1]+(cnt==k);if(cnt==k){fill(vis.begin(),vis.end(),false);cnt=0;}}cin>>q;while(q--){cin>>str;int len=str.length();int pos=-1;bool tag=true;for(int i=0;i<len;i++){int x=str[i]-'a'+1;auto tmp=upper_bound(dp[x].begin(),dp[x].end(),pos);//cout<<tmp<<endl;if(tmp==dp[x].end()){tag=false;break;}pos=*tmp;//cout<<pos<<endl;}if(!tag){cout<<0<<endl;continue;}//cout<<pos<<endl;cout<<suf[pos]+1<<endl;}return 0;
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/81028.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/81028.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/81028.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何創建一個導入模板?全流程圖文解析

先去找到系統內可以上傳東西的按鈕 把你的模板上傳上去,找到對應的fileName 圖里的文字寫錯了,是復制粘貼"filePath"到URL才能下載

通信原理第七版與第六版區別附pdf

介紹 我用夸克網盤分享了「通信原理 第7版》樊昌信」&#xff0c;鏈接&#xff1a;https://pan.quark.cn/s/be7c5af4cdce 《通信原理&#xff08;第7版&#xff09;》是在第6版的基礎上&#xff0c;為了適應當前通信技術發展和教學需求&#xff0c;并吸取了數十所院校教師的反…

Mysql唯一性約束

唯一性約束&#xff08;Unique Constraint&#xff09;是數據庫設計中用于保證表中某一列或多列組合的值具有唯一性的一種規則。它可以防止在指定列中插入重復的數據&#xff0c;有助于維護數據的完整性和準確性。下面從幾個方面為你詳細解釋 作用 確保數據準確性&#xff1a…

測試基礎筆記第十六天

提示&#xff1a;文章寫完后&#xff0c;目錄可以自動生成&#xff0c;如何生成可參考右邊的幫助文檔 文章目錄 一、UI自動化介紹1.認識UI自動化測試2.實施UI自動化測試前置條件3.UI自動化測試執行時機4.UI自動化測試核心作用和劣勢 二、認識Web自動化測試工具-Selenium021.Sel…

PaddleX的安裝

參考&#xff1a;安裝PaddlePaddle - PaddleX 文檔 1、安裝PaddlePaddle 查看 docker 版本 docker --version 若您通過 Docker 安裝&#xff0c;請參考下述命令&#xff0c;使用飛槳框架官方 Docker 鏡像&#xff0c;創建一個名為 paddlex 的容器&#xff0c;并將當前工作目…

長效住宅IP是什么?如何獲取長效住宅IP?

在當今的互聯網世界里&#xff0c;IP地址作為連接用戶與網站之間的橋梁&#xff0c;其重要性不言而喻。對于跨境電商、社交媒體運營以及數據采集等領域的專業人士而言&#xff0c;普通的IP地址已無法滿足日益復雜的需求。他們更需要一種穩定、安全且持久的長效住宅IP來完成各類…

02 業務流程架構

業務流程架構提供了自上而下的組織鳥瞰圖&#xff0c;是業務流程的全景圖。根據所采用的方法不同&#xff0c;有時被稱為流程全景圖或高層級流程圖&#xff0c;提供了業務運營中所有業務流程的整體視圖。 這樣有助于理解企業內部各個業務流程之間的相互關系以及它們如何共同工…

jenkins slave節點打包報錯Failed to create a temp file on

jenkins slave節點打包報錯 一、報錯信息 FATAL: Unable to produce a script file Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to slave-83at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1784)at hudson.remoting.UserRequest$…

什么是 Swagger 以及如何在 Spring Boot 中實現 Swagger:配置與實踐指南

在現代 RESTful API 開發中&#xff0c;Swagger 是一種廣泛使用的工具&#xff0c;用于生成、描述和可視化 API 文檔。它極大地簡化了 API 的開發、測試和維護過程。結合 Spring Boot&#xff0c;Swagger 可以快速集成到項目中&#xff0c;生成交互式 API 文檔&#xff0c;方便…

Xilinx FPGA支持的FLASH型號匯總

以博主這些年的FPGA開發使用經驗來看&#xff0c;FPGA開發的主流還是以Xilinx FPGA為主&#xff0c;貿易戰關稅戰打了這么多年&#xff0c;我們做研發的也不可避免的要涉及一些國產替代的工作&#xff1b;這里把Xilinx FPGA官方支持的各類&#xff08;國產和非國產&#xff09;…

第3講:ggplot2完美入門與美化細節打磨——從基礎繪制到專業級潤色

目錄 1. 為什么選擇ggplot2? 2. 快速了解ggplot2繪圖核心邏輯 3. 基礎繪圖示范:柱狀圖、折線圖、散點圖 (1)簡單柱狀圖 (2)折線圖示范 (3)高級散點圖 + 擬合線 4. 精細美化:細節打磨決定專業感 5. 推薦的美化小插件(可選進階) 6. 小練習:快速上手一幅美化…

Vue3 上傳后的文件智能預覽(實戰體會)

目錄 前言1. Demo12. Demo2 前言 &#x1f91f; 找工作&#xff0c;來萬碼優才&#xff1a;&#x1f449; #小程序://萬碼優才/r6rqmzDaXpYkJZF 爬蟲神器&#xff0c;無代碼爬取&#xff0c;就來&#xff1a;bright.cn 此處的基本知識涉及較少&#xff0c;主要以Demo的形式供大…

transformer-實現單層Decoder 層

Decoder Layer 論文地址 https://arxiv.org/pdf/1706.03762 解碼器層結構 Transformer解碼器層由三種核心組件構成&#xff1a; Masked多頭自注意力&#xff1a;關注解碼器序列當前位置之前的上下文&#xff08;因果掩碼&#xff09; Encoder-Decoder多頭注意力&#xff1a;關…

設計模式每日硬核訓練 Day 16:責任鏈模式(Chain of Responsibility Pattern)完整講解與實戰應用

&#x1f504; 回顧 Day 15&#xff1a;享元模式小結 在 Day 15 中&#xff0c;我們學習了享元模式&#xff08;Flyweight Pattern&#xff09;&#xff1a; 通過共享對象&#xff0c;分離內部狀態與外部狀態&#xff0c;大量減少內存開銷。適用于字符渲染、游戲場景、圖標緩…

大數據開發環境的安裝,配置(Hadoop)

1. 三臺linux服務器的安裝 1. 安裝VMware VMware虛擬機軟件是一個“虛擬PC”軟件&#xff0c;它使你可以在一臺機器上同時運行二個或更多Windows、DOS、LINUX系統。與“多啟動”系統相比&#xff0c;VMWare采用了完全不同的概念。 我們可以通過VMware來安裝我們的linux虛擬機…

多模態大語言模型arxiv論文略讀(四十九)

When Do We Not Need Larger Vision Models? ?? 論文標題&#xff1a;When Do We Not Need Larger Vision Models? ?? 論文作者&#xff1a;Baifeng Shi, Ziyang Wu, Maolin Mao, Xin Wang, Trevor Darrell ?? 研究機構: UC Berkeley、Microsoft Research ?? 問題背…

【深度學習與大模型基礎】第14章-分類任務與經典分類算法

Part 1&#xff1a;什么是分類任務&#xff1f; 1.1 分類就是“貼標簽” 想象你有一堆水果&#xff0c;有蘋果&#x1f34e;、橘子&#x1f34a;、香蕉&#x1f34c;&#xff0c;你的任務是讓機器學會自動判斷一個新水果屬于哪一類——這就是分類&#xff08;Classification&…

LeetCode 2906 統計最大元素出現至少K次的子數組(滑動窗口)

給出一個示例&#xff1a; 輸入&#xff1a;nums [1,3,2,3,3], k 2 輸出&#xff1a;6 解釋&#xff1a;包含元素 3 至少 2 次的子數組為&#xff1a;[1,3,2,3]、[1,3,2,3,3]、[3,2,3]、[3,2,3,3]、[2,3,3] 和 [3,3] 。該題也是一個比較簡單的滑動窗口的題目&#xff0c;但是…

使用 Spring Boot 進行開發

? 使用 Spring Boot 進行開發 ? &#x1f4cc; 本節將深入介紹如何高效使用 Spring Boot&#xff0c;涵蓋以下核心主題&#xff1a; 1?? &#x1f527; 構建系統 深入了解 Spring Boot 的項目結構和依賴管理 2?? ?? 自動配置 探索 Spring Boot 的自動化配置機制和原…

Qt的WindowFlags窗口怎么選?

Qt.Dialog: 指示窗口是一個對話框&#xff0c;這通常會改變窗口的默認按鈕布局&#xff0c;并可能影響窗口框架的樣式。Qt.Popup: 指示窗口是一個彈出式窗口&#xff08;例如菜單或提示&#xff09;&#xff0c;它通常是臨時的且沒有任務欄按鈕。Qt.Tool: 標識窗口作為一個工具…