A.Archmage(思维)
1.题目大意:法师初始有n点蓝且为满蓝状态,每秒先放一个消耗x点蓝的技能,接着恢复y点蓝,问m秒后能放几次技能
2.首先不难发现如果 y ≥ x y \geq x y≥x那么每秒都能放一次技能;否则,尽管蓝量不能超过n,但是我们依旧可以先累积 m − 1 m-1 m−1秒恢复的蓝量(第 m m m秒累积的蓝没用),再除以 x x x看看能放多少次技能,注意到答案不能超过 m m m
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <bitset>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ins insert
#define lowbit(x) (x&(-x))
#define mkp(x,y) make_pair(x,y)
#define mem(a,x) memset(a,x,sizeof a);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int t;
ll n,m,x,y;
cin>>t;
while(t--){
cin>>n>>m>>x>>y;
if(y>=x){
cout<<m<<"\n";
}else{
ll ans=(n+(m-1)*y)/x;
cout<<min(ans,m)<<"\n";
}
}
return 0;
}
B. Bamboo Leaf Rhapsody(签到)
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <bitset>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ins insert
#define lowbit(x) (x&(-x))
#define mkp(x,y) make_pair(x,y)
#define mem(a,x) memset(a,x,sizeof a);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;
ll x,y,z;
scanf("%d",&n);
ll ans=INF;
while(n--){
scanf("%lld%lld%lld",&x,&y,&z);
ans=min(x*x+y*y+z*z,ans);
}
double d=sqrt(ans);
printf("%.3lf",d);
return 0;
}
C. Cheat Sheet(贪心)
使用map处理一下字符串,最后排序贪心取即可
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <bitset>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ins insert
#define lowbit(x) (x&(-x))
#define mkp(x,y) make_pair(x,y)
#define mem(a,x) memset(a,x,sizeof a);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=1e9+7;
const int maxn=2e5+10;
int a[maxn];
map<string,int> mp;
string s;
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,m;
int cnt=0;
cin>>n>>m;
for(int i=1;i<=m;i++){
cin>>s;
if(!mp.count(s)){
//cout<<mp[s]<<endl;
int x=s.size();
a[cnt++]=x;
mp[s]=1;
}
}
sort(a,a+cnt);
int ans=0;
for(int i=0;i<cnt;i++){
if(i>0) a[i]++;
if(n>=a[i]){
n-=a[i];
ans++;
}
}
cout<<ans<<endl;
return 0;
}
D. Disaster Recovery
G. Gentle Jena(单调栈)
留坑
H. Hay Mower
一开始写了 O ( n ∗ k ) O(n*k) O(n∗k)的做法,发现wa了
后来发现实际上每一格的贡献就是最后更新的时间,那么记录下该时间最后计算每一格即可
比赛时因为小细节卡了很久,就是乘法取模时这样写是不对的:
( x % M o d ∗ y % M o d ) % M o d {(x\%Mod*y\%Mod)\%Mod} (x%Mod∗y%Mod)%Mod
因为乘法运算和取模运算是同一优先级,因此 y y y会先乘进去后取模,那么必须加括号:
( x % M o d ∗ ( y % M o d ) ) % M o d {(x\%Mod*(y\%Mod))\%Mod} (x%Mod∗(y%Mod))%Mod
还有坑就是时间要比较大小不能先取模
吃一堑长一智
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <math.h>
#include <cstdio>
#include <string>
#include <bitset>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ins insert
#define lowbit(x) (x&(-x))
#define mkp(x,y) make_pair(x,y)
#define mem(a,x) memset(a,x,sizeof a);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> P;
const double eps=1e-8;
const double pi=acos(-1.0);
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int Mod=998244353;
const int maxn=1e6+10;
struct node{
int id,flag;
ll t;
}a[maxn];
ll r[505],c[505];
ll g[505][505];
bool cmp(node &p,node &q){
return p.t<q.t;
}
int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,m,k;
char dir;
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>g[i][j];
}
for(int i=0;i<k;i++){
cin>>dir;
cin>>a[i].id>>a[i].t;
if(dir=='r') a[i].flag=1;
else a[i].flag=0;
}
sort(a,a+k,cmp); //不排序也行
for(int i=0;i<k;i++){
if(a[i].flag){
int cur=a[i].id;
r[cur]=max(r[cur],a[i].t);
}else{
int cur=a[i].id;
c[cur]=max(c[cur],a[i].t);
}
}
ll ans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
ll d=max(r[i],c[j])%Mod;
ans+=(d*(g[i][j]%Mod))%Mod;
ans%=Mod;
}
cout<<ans<<"\n";
return 0;
}