C. Adding Powers
题目大意:
你有一个一开始全是0的数组v,给你一个长度为n的数组a。
然后你可以进行操作第i次操作(i从0开始)
你可以跳过这一步,或者给v数组中任意一个位置加上。
问你能不能最终让这个v数组变成a数组
题目做法:
每个只能用一次,所以肯定是每个贪心地拿,如果不贪心地每次先拿最大,就必须要有多个次小的被重复拿。
AC代码:
#include<bits/stdc++.h>
#define pb(element) push_back(element)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
//#define ll long long
//Cara's templet version 1.20
//2024/3/7 13:54 UTC+8
//Kids' with no fire in their eyes
//Whose life ended when flame faded away
//And u mf plz hear my admonish
//Don't be that kind of kid
//Plz keep ur unique flame
//I wanna see ur blaze
using namespace std;
const int maxn=1e9+7;
void solve()
{
int n,k,maxn=-1,i;
cin>>n>>k;
int a[n];
map<int,bool> mp;
vector<int> seq;
for(i=0;i<n;i++)
{
cin>>a[i];
maxn=max(maxn,a[i]);
}
for(i=1;i<maxn;i*=k) seq.pb(i);
seq.pb(i);
for(i=0;i<n;i++)
{
while(a[i]!=0)
{
int ps=upper_bound(seq.begin(),seq.end(),a[i])-seq.begin();
a[i]-=seq[ps-1];
if(mp[seq[ps-1]]==1)
{
cout<<"NO"<<'\n';
return ;
}
mp[seq[ps-1]]=1;
}
}
cout<<"YES"<<'\n';
}
signed main()
{
fast int casen=1;
cin>>casen;
while(casen--) solve();
}
A. Is it rated - 2
原题链接:Problem - 1505A - Codeforces
题目大意:
交互题,输出NO
题目做法:
如果你看到有人做这样的的题目的题解,你也许就能非常轻易的得出一个结论就是
要么他已经疯了
要么他闲得没事干
AC代码:
#include<bits/stdc++.h>
#define pb(element) push_back(element)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
//#define ll long long
//Cara's templet version 1.20
//2024/3/7 13:54 UTC+8
//Kids' with no fire in their eyes
//Whose life ended when flame faded away
//And u mf plz hear my admonish
//Don't be that kind of kid
//Plz keep ur unique flame
//I wanna see ur blaze
using namespace std;
const int maxn=1e9+7;
void solve()
{
string str;
while(cin>>str)
{
cout<<"NO"<<'\n';
cout.flush();
}
}
signed main()
{
fast int casen=1;
//cin>>casen;
while(casen--) solve();
}
C. Rooks Defenders
题目大意:
给你一个n*n的棋盘,进行q次询问
有三种询问方式
第一种在(x,y)上放一个rook
第二种移除(x,y)上的rook
第三章询问(x1,y1)- (x2,y2)的区域内会不会被rook攻击全覆盖到,rook的攻击方式是同排或者同列。
题目做法:
浅打一个树状数组,很平实的思路,WA了好几发3,没注意到同行同列的增加其实不一定影响树状数组里的值,终于用俩mp解决了这个问题,好像这个思路和题解的也不太一样。回头看看能不能理解一下再打一种写法。
AC代码:
#include<bits/stdc++.h>
#define pb(element) push_back(element)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
using namespace std;
const int maxn = 1e5+100;
int c[2][maxn], n, q;
map<int,int> mpx,mpy;
int lowerbit(int i){
return i&(-1*i);
}
int sumup(int i, int num){
int res = 0;
while(i > 0){
res += c[num][i];
i -= lowerbit(i);
}
return res;
}
void modify(int i, int k, int num){
while(i <= n + 10){
c[num][i] += k;
i += lowerbit(i);
}
}
void solve()
{
cin >> n >> q;
while(q--){
int t;
cin >> t;
if(t == 1){
int x, y;
cin >> x >> y;
mpx[x]++;
mpy[y]++;
if(mpx[x] == 1) modify(x, 1, 0);
if(mpy[y] == 1) modify(y, 1, 1);
}
if(t == 2){
int x, y;
cin >> x >> y;
mpx[x]--;
mpy[y]--;
if(mpx[x] == 0) modify(x, -1, 0);
if(mpy[y] == 0) modify(y, -1, 1);
}
if(t == 3){
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (sumup(x2, 0) - sumup(x1 - 1, 0) == x2 - x1 + 1 || sumup(y2, 1) - sumup(y1 - 1, 1) == y2 - y1 + 1){
cout << "Yes" << '\n';
}
else{
cout << "No" << '\n';
}
}
}
}
signed main()
{
fast int casen = 1;
//cin>>casen;
while(casen--) solve();
}
B. Interesting drink
原题链接:Problem - 706B - Codeforces
题目大意:
先给一个n代表n个商店
然后给一个长度为n的数组,数组元素代表商店里商品的价格
然后有q次询问,每次给一个钱数目,问最多能买几个商店里的商品,也即多少个商店里商品的价格小于等于钱的数目。
题目做法:
排序,二分,秒了。(不要再刷水题了行不行。。。。。)
AC代码:
#include<bits/stdc++.h>
#define pb(element) push_back(element)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
//#define ll long long
//Cara's templet version 1.20
//2024/3/7 13:54 UTC+8
//Kids' with no fire in their eyes
//Whose life ended when flame faded away
//And u mf plz hear my admonish
//Don't be that kind of kid
//Plz keep ur unique flame
//I wanna see ur blaze
using namespace std;
const int maxn=1e9+7;
void solve()
{
int n,q;
cin>>n;
int a[n+1];
for(int i=0;i<n;i++) cin>>a[i];
a[n]=1e18;
sort(a,a+n+1);
cin>>q;
for(int i=0;i<q;i++)
{
int sm;
cin>>sm;
cout<<upper_bound(a,a+n+1,sm)-a<<'\n';
}
}
signed main()
{
fast int casen=1;
//cin>>casen;
while(casen--) solve();
}
B. Petr and Permutations
原题链接:Problem - 706B - Codeforces
题目大意:
有两个人,一个喜欢将一个全排列中任选一对位置交换3*n次,一个喜欢交换7*n-1次,给你一个交换完的排序,问你是哪个人交换出来的。
题目做法:
原本是想来练树状数组的,但是发现一个圈里的交换次数是圈中元素-1,其余的话就是只能换两次让位置不变,不然换不成最后的模样,这样就根本用不到树状数组了。
回头看题解却看不明白树状数组的解法了,回头再尝试理解一下,再写一个树状数组的解法吧。
AC代码:
#include<bits/stdc++.h>
#define pb(element) push_back(element)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define int long long
//#define ll long long
//Cara's templet version 1.20
//2024/3/7 13:54 UTC+8
//Kids' with no fire in their eyes
//Whose life ended when flame faded away
//And u mf plz hear my admonish
//Don't be that kind of kid
//Plz keep ur unique flame
//I wanna see ur blaze
using namespace std;
const int maxn=1e6+10;
int ar[maxn];
bool vis[maxn];
int much=0;
void dfs(int now)
{
//cout<<now<<"?";
if(vis[ar[now]]!=1)
{
much++;
vis[ar[now]]=1;
dfs(ar[now]);
}
}
void solve()
{
int n,i,res=0;
cin>>n;
for(i=1;i<=n;i++) cin>>ar[i];
for(i=1;i<=n;i++)
{
if(vis[i]==0)
{
much=0;
dfs(i);
// cout<<much<<'\n';
// cout<<'\n';
res+=much-1;
}
}
if((3*n-res)%2==0) cout<<"Petr"<<'\n';
else cout<<"Um_nik"<<'\n';
}
signed main()
{
fast int casen=1;
//cin>>casen;
while(casen--) solve();
}