刷题计划(problem.cpp/problem.in/problem.out)
题面:王队在做题,他想把最新的前20道提交了没有$AC$过的题目列出来。如果没有20道,就只输出全部。输入会有如下几个操作:
10000 12
2 1
3
2 9999
3
1 1
3
2 1
3
2 10000
3
2 9999
3
1
9999 1
9999
9999
10000 9999
9999 10000
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct node{
int Time,Name;
bool AC;
}Q[10005];
int n,m,type,Task,cnt,time;
int Test[10005],Testcnt;
int AC[10005],ACcnt;
inline void Clear(){
for (int i=1;i<=ACcnt;i++)
for (int j=1;j<=cnt;j++)
if (AC[i]==Q[j].Name)
Q[j].AC=true;
return;
}
bool cmp(node a,node b){
return a.Time>b.Time;
}
int main(){
freopen("problem.in","r",stdin);
freopen("problem.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++){
scanf("%d",&type);
if (type==1){
scanf("%d",&AC[++ACcnt]);
continue;
}
if (type==2){
scanf("%d",&Task);
cnt++;
Q[cnt].Name=Task;
Q[cnt].Time=++time;
Q[cnt].AC=false;
continue;
}
if (type==3){
int ans=0;
sort (Q+1,Q+cnt+1,cmp);
Clear();
Testcnt=0;
for (int j=1;j<=cnt;j++){
if (!Q[j].AC){
bool flag=false;
for (int k=1;k<=Testcnt;k++)
if (Test[k]==Q[j].Name){
flag=true;
break;
}
if (flag) continue;
printf ("%d ",Q[j].Name);
Test[++Testcnt]=Q[j].Name;
ans++;
if (ans>=20) break;
}
}
printf("\n");
}
}
fclose(stdin);
fclose(stdout);
return 0;
}
最优交换(swap.cpp/swap.in/swap.out)
2
1432 2
4321 2
4312
4321
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int T,k,len;
string str,Maxstr;
string Max(string a,string b){
if (a>b) return a;
return b;
}
void dfs(string str,int deep){
if (deep>k){
Maxstr=Max(Maxstr,str);
return;
}
for (int i=0;i<len-1;i++){
swap(str[i],str[i+1]);
dfs(str,deep+1);
swap(str[i],str[i+1]);
}
return;
}
int main(){
freopen("swap.in","r",stdin);
freopen("swap.out","w",stdout);
scanf("%d",&T);
while (T--){
cin >>str;
scanf("%d",&k);
len=str.length();
dfs(str,1);
cout <<Maxstr<<endl;
}
fclose(stdin);
fclose(stdout);
return 0;
}
3 4 5
1 2 1 1
2 3 1 2
3 2 2 2
2 3 4 2
1 4 5 1
10 1 2 1
14
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int n,m,S,ans;
struct node{
int v,w;
}G[405][405];
int dp[405][405][405];
int main(){
freopen("matrix.in","r",stdin);
freopen("matrix.out","w",stdout);
scanf("%d%d%d",&n,&m,&S);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
scanf("%d",&G[i][j].v);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
scanf("%d",&G[i][j].w);
for (int s=0;s<=S;s++){
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
if (G[i][j].v<=s)
dp[i][j][s]=max(max(dp[i-1][j][s-G[i][j].v],dp[i][j-1][s-G[i][j].v])+G[i][j].w,max(dp[i][j-1][s],dp[i-1][j][s]));
else dp[i][j][s]=max(dp[i][j-1][s],dp[i-1][j][s]);
}
}
}
printf ("%d\n",dp[n][m][S]);
fclose(stdin);
fclose(stdout);
return 0;
}
格点统计(count.cpp/count.in/count.out)
输入样例:
3
4
输出样例:
5
8
分析:数论找规律吧....反正我推出这么一个东西:
for (unsigned long long i=1;i<=Sqrt;i++){
ans+=k-2*i+1;
if (ans>Mod) ans=ans%Mod;
}
ans++;
ans*=2;
ans-=Psum;//x=y的个数
ans=ans%Mod;
不过测出来证明是错的$QAQ$
产品排序(product.cpp/product.in/product.out)
4
1 4
3 2
5 2
2 1
40
电话线铺设(telephone.cpp/telephone.in/telephone.out)
本文作者:Snowflake_Pink
本文链接:https://snowflake.pink/archives/24/
最后修改时间:2020-04-13 11:15:29
本站未注明转载的文章均为原创,并采用 CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!