d3486
思路:每次把ai加到总等待时间最短的t1上,输出tm
有人会问为啥。我来说,tm用的时间最长,在tm接的时候t1,t2…tm-1一起接。因为tm接的时间最慢tm接完了,所有的也接完了。
给我走开,我要代码
好好好,给你代码
#include<bits/stdc++.h>
using namespace std;
int t[105],a[10005];
int main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sort(t+1,t+1+m);
t[1]+=a[i];
}
sort(t+1,t+1+m);
cout<<t[m];
return 0;
}d46746
看了题目后直接出结论string!!!
上代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
cin>>s;
int t;
cin>>t;
while(t--)
{
int op;
cin>>op;
if(op==1)
{
reverse(s.begin(),s.end());
}
else
{
int op1;
char a;
cin>>op1>>a;
if(op1==1)
{
s=a+s;
}
else
{
s=s+a;
}
}
}
cout<<s;
return 0;
}咋只有54分
好好好,正常一点。
其实这道题要用deque,因为deque首尾添加很方便,但直接反转好像有点超了。
所以这道题要做标记操作+反转。
不废话上代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
deque<char>q;
string s;
cin>>s;
int t,f=0;
cin>>t;
for(int i=0;i<s.size();i++) q.push_back(s[i]);
while(t--)
{
int op;
cin>>op;
if(op==1)
{
if(f==0) f=1;
else f=0;
}
else
{
int op1;
cin>>op1;
char a;
cin>>a;
if(op1==1&&f==0)
{
q.push_front(a);
}
else if(op1==1&&f==1)
{
q.push_back(a);
}
else if(op1==2&&f==0)
{
q.push_back(a);
}
else if(op1==2&&f==1)
{
q.push_front(a);
}
}
}
if(f==1) reverse(q.begin(),q.end());
for(int i=0;i<q.size();i++) cout<<q[i];
return 0;
}