
已全部拿下,后天考试,做一套找找感觉,ioi赛制就是爽
RC-u1 热 热 热
n数据范围很小,模拟一下就可以
#include <bits/stdc++.h>
#define LL long long
using namespace std;
typedef pair<int,int> PII;
void solve(){
int n,w;
cin>>n>>w;
w--;
int ans1=0,ans2=0;
for(int i=1;i<=n;i++){
int x;
cin>>x;
if(x>=35){
if(w==3){
ans2++;
}else{
ans1++;
}
}
w=(w+1)%7;
}
cout<<ans1<<' '<<ans2<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
while(T--) solve();
}
谁进线下了?
暴力判断,也不需要排序
#include <bits/stdc++.h>
#define LL long long
using namespace std;
typedef pair<int,int> PII;
int s[10]={0,12,9,7,5,4,3,2,1,0};
void solve(){
int n;
cin>>n;
vector<int> ans(21);
for(int i=1;i<=n;i++){
for(int j=1;j<=20;j++){
int p,k;cin>>p>>k;
if(p==1) ans[j]+=12;
if(p==2) ans[j]+=9;
if(p==3) ans[j]+=7;
if(p==4) ans[j]+=5;
if(p==5) ans[j]+=4;
if(p>=6 && p<=7) ans[j]+=3;
if(p>=8 && p<=10) ans[j]+=2;
if(p>=11 && p<=15) ans[j]+=1;
ans[j]+=k;
}
}
for(int i=1;i<=20;i++){
cout<<i<<' '<<ans[i]<<'\n';
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
while(T--) solve();
}
暖炉与水豚
当一个水豚是暖的但是周围33方格都没有暖炉,那么它的周围33方格为’.'的都是有可能是暖炉
要注意如果这个位置是暖炉,那么它的周围3*3就不能有冷的水豚,这点需要判断
#include<bits/stdc++.h>
#define LL long long
using namespace std;
typedef pair<int,int> PII;
void solve() {
int n,m;
cin>>n>>m;
vector<vector<char>> a(n+1,vector<char>(m+1));
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
cin>>a[i][j];
}
}
auto check=[&](int x,int y)->bool{
for(int i=max(x-1,1); i<=min(x+1,n); i++) {
for(int j=max(y-1,1); j<=min(y+1,m); j++) {
if(a[i][j]=='m') return false;
}
}
return true;
};
auto check2=[&](int x,int y)->bool{
for(int i=max(x-1,1); i<=min(x+1,n); i++) {
for(int j=max(y-1,1); j<=min(y+1,m); j++) {
if(a[i][j]=='c') return false;
}
}
return true;
};
set<PII> ans;
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
if(a[i][j]=='w') {
if(check(i,j)) {
for(int p=max(i-1,1); p<=min(i+1,n); p++) {
for(int q=max(j-1,1); q<=min(j+1,m); q++) {
if(a[p][q]=='.' && check2(p,q)) ans.insert({p,q});
}
}
}
}
}
}
if(ans.empty()){
cout<<"Too cold!"<<'\n';
return ;
}
for(auto [x,y]:ans) {
cout<<x<<' '<<y<<'\n';
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
// cin>>T;
while(T--) {
solve();
}
return 0;
}
章鱼图的判断
并查集判断环,bfs求两点最短距离
#include<bits/stdc++.h>
#define LL long long
using namespace std;
typedef pair<int,int> PII;
const int N=1e5+10;
int n,m;
vector<int> g[N];
int ans,vis[N],p[N],cnt[N],dis[N];
int l,r;
int find(int x){
if(x!=p[x]) p[x]=find(p[x]);
return p[x];
}
int bfs(int x,int y){
queue<int> q;
q.push(x);
vis[x]=1;
while(!q.empty()){
auto u=q.front();
q.pop();
if(u==y) break;
for(auto v:g[u]){
if(u==x && v==y) continue;
if(!vis[v]){
vis[v]=1;
q.push(v);
dis[v]=dis[u]+1;
}
}
}
return dis[y]+1;
}
void solve(){
cin>>n>>m;
ans=0;
for(int i=1;i<=n;i++){
vis[i]=cnt[i]=dis[i]=0;
g[i].clear();
p[i]=i;
}
l=r=-1;
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
g[x].push_back(y);
g[y].push_back(x);
int px=find(x);
int py=find(y);
if(px==py){
cnt[py]++;
l=x,r=y;
}else{
p[px]=py;
cnt[py]+=cnt[px];
}
}
for(int i=1;i<=n;i++){
if(find(i)==i && cnt[i]==1) ans++;
}
if(ans==1){
cout<<"Yes"<<' '<<bfs(l,r)<<'\n';
}else{
cout<<"No"<<' '<<ans<<'\n';
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
工作安排
01背包优化
#include<bits/stdc++.h>
#define LL long long
using namespace std;
typedef pair<int,int> PII;
const int N=5010;
int dp[N],n;
struct node{
int t,d,p;
bool operator<(const node&it)const{
return d<it.d;
}
}a[N];
void solve(){
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i].t>>a[i].d>>a[i].p;
sort(a+1,a+n+1);
for(int i=0;i<=5000;i++) dp[i]=0;
for(int i=1;i<=n;i++){
auto [t,d,p]=a[i];
for(int j=d;j>=0;j--){
if(j>=t) dp[j]=max(dp[j],dp[j-t]+p);
}
}
int ans=0;
for(int j=0;j<=5000;j++) ans=max(ans,dp[j]);
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}