第一题(100)
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
int n,k,a[5020 ],b[5020 ],ans= INT_MAX,ans1,ans2,c[5020 ],z;
int main (){
// double string a.length() unsigned long long
// freopen("?.in","r",stdin);scanf("%d",&a);
// freopen("?.out","w",stdout);printf("%d",a);ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>> n;
for (int i= 1 ;i<= n;i++ ){
char f;
cin>> f;
if (f== 'F' ){
a[i]= 1 ;
b[i]= 1 ;
}
}
for (int i= 1 ;i<= n;i++ ){
ans2= 0 ;
z= 0 ;
int f= 1 ;
for (int j= 1 ;j<= n- i+ 1 ;j++ ){
z-= c[j];
a[j]= (a[j]+ z)% 2 ;
if (a[j]== 0 ){
ans2++ ;
if (ans2>= ans){
f= 0 ;
break ;
}
z++ ;
a[j]= 1 ;
c[j+ i]= 1 ;
}
}
if (f== 1 ){
for (int j= n- i+ 2 ;j<= n;j++ ){
z-= c[j];
a[j]= (a[j]+ z)% 2 ;
if (a[j]== 0 ){
f= 0 ;
break ;
}
}
}
for (int j= 1 ;j<= n;j++ ){
a[j]= b[j];
c[j]= 0 ;
}
if (f== 1 ){
if (ans> ans2){
ans= ans2;
ans1= i;
}
}
}
cout<< ans1<< ' ' << ans;
return 0 ;
}
//�I
第二题(0)
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
int x1,x2,x3,x4,a[50 ],ans;
int main (){
// double string a.length() unsigned long long
// freopen("?.in","r",stdin);scanf("%d",&a);
// freopen("?.out","w",stdout);printf("%d",a);
ios ::sync_with_stdio (0 ), cin.tie (0 ), cout.tie (0 );
cin>> x1>> x2>> x3>> x4;
for (int i= 1 ;i<= x1;i++ ){
cin>> a[i];
}
sort (a+ 1 ,a+ x1+ 1 );
for (int i= x1;i>= 1 ;){
int z= a[i];
int j= i- 1 ;
while (j>= 1 ){
if (z> a[j]){
z-= a[j];
ans+= a[j];
j-- ;
}else {
a[j]-= z;
ans+= z;
break ;
}
}
i= j;
if (j<= 0 ){
ans+= z;
}
}
for (int i= 1 ;i<= x2;i++ ){
cin>> a[i];
}
sort (a+ 1 ,a+ x2+ 1 );
for (int i= x2;i>= 1 ;){
int z= a[i];
int j= i- 1 ;
while (j>= 1 ){
if (z> a[j]){
z-= a[j];
ans+= a[j];
j-- ;
}else {
a[j]-= z;
ans+= z;
break ;
}
}
i= j;
if (j<= 0 ){
ans+= z;
}
}
for (int i= 1 ;i<= x3;i++ ){
cin>> a[i];
}
sort (a+ 1 ,a+ x3+ 1 );
for (int i= x3;i>= 1 ;){
int z= a[i];
int j= i- 1 ;
while (j>= 1 ){
if (z> a[j]){
z-= a[j];
ans+= a[j];
j-- ;
}else {
a[j]-= z;
ans+= z;
break ;
}
}
i= j;
if (j<= 0 ){
ans+= z;
}
}
for (int i= 1 ;i<= x4;i++ ){
cin>> a[i];
}
sort (a+ 1 ,a+ x4+ 1 );
for (int i= x4;i>= 1 ;){
int z= a[i];
int j= i- 1 ;
while (j>= 1 ){
if (z> a[j]){
z-= a[j];
ans+= a[j];
j-- ;
}else {
a[j]-= z;
ans+= z;
break ;
}
}
i= j;
if (j<= 0 ){
ans+= z;
}
}
cout<< ans;
return 0 ;
}
//�I
改正
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
int x1,x2,x3,x4,a[10020 ],s,n,ans;
void dfs (int q ,int x ,int y ){
if (max (x,y)>= s) return ;
if (q> n){
s= min (s,max (x,y));
return ;
}
dfs (q+ 1 ,x+ a[q],y);
dfs (q+ 1 ,x,y+ a[q]);
}
int main (){
cin>> x1>> x2>> x3>> x4;
for (int i= 1 ;i<= x1;i++ ){
cin>> a[i];
}
n= x1,s= INT_MAX;
dfs (1 ,0 ,0 );
ans+= s;
for (int i= 1 ;i<= x2;i++ ){
cin>> a[i];
}
n= x2,s= INT_MAX;
dfs (1 ,0 ,0 );
ans+= s;
for (int i= 1 ;i<= x3;i++ ){
cin>> a[i];
}
n= x3,s= INT_MAX;
dfs (1 ,0 ,0 );
ans+= s;
for (int i= 1 ;i<= x4;i++ ){
cin>> a[i];
}
n= x4,s= INT_MAX;
dfs (1 ,0 ,0 );
ans+= s;
cout<< ans;
return 0 ;
}
//㊣
第三题(0)
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
int n,m,b[500020 ];
struct str {
int d,id;
queue<long long> c;
}a[500020 ];
int px1 (str x ,str y ){
return x.d< y.d;
}
int px2 (str x ,str y ){
return x.id< y.id;
}
int main (){
// double string a.length() unsigned long long
// freopen("?.in","r",stdin);scanf("%d",&a);
// freopen("?.out","w",stdout);printf("%d",a);
ios ::sync_with_stdio (0 ), cin.tie (0 ), cout.tie (0 );
cin>> n>> m;
for (int i= 1 ;i<= m;i++ ){
cin>> b[i];
}
if (n>= m){
for (int i= 1 ;i<= m;i++ ){
cout<< i<< ' \n ' ;
}
for (int i= m+ 1 ;i<= n;i++ ){
cout<< 0 << ' \n ' ;
}
return 0 ;
}else {
for (int i= 1 ;i<= n;i++ ){
a[i].id= i;
a[i].d+= b[i];
a[i].c.push (i);
}
for (int i= n+ 1 ;i<= m;i++ ){
sort (a+ 1 ,a+ n+ 1 ,px1);
a[1 ].d+= b[i];
a[1 ].c.push (i);
}
}
sort (a+ 1 ,a+ n+ 1 ,px2);
for (int i= 1 ;i<= n;i++ ){
while (a[i].c.size ()){
cout<< a[i].c.front ()<< ' ' ;
a[i].c.pop ();
}
cout<< endl;
}
return 0 ;
}
//�I
改正
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
typedef long long ll;
ll t;
ll n,m,k,p,l,r;
pair< ll,ll> u;
priority_queue< pair< ll,ll> ,vector< pair< ll,ll> > ,greater< pair< ll,ll> > > q;
vector< ll> ans[500120 ];
int main (){
// double string a.length() unsigned long long
// freopen("?.in","r",stdin);scanf("%d",&a);
// freopen("?.out","w",stdout);prllf("%d",a);
ios ::sync_with_stdio (0 ), cin.tie (0 ), cout.tie (0 );
cin>> n>> m;
for (ll i= 1 ;i<= n;i++ ){
q.push ({0 ,i});
}
for (ll i= 1 ;i<= m;i++ ){
cin>> t;
u= q.top ();
q.pop ();
ans[u.second].push_back (i);
q.push ({u.first+ t,u.second});
}
for (ll i= 1 ;i<= n;i++ ){
if (ans[i].empty ()) cout<< "0 \n " ;
else {
for (ll j= 0 ;j< ans[i].size ();j++ ){
if (j) cout<< ' ' ;
cout<< ans[i][j];
}
cout<< ' \n ' ;
}
}
return 0 ;
}
//㊣
第四题(0)
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
stack<char> a[10020 ];
stack<char> b[10020 ];
int t,f= 0 ,f1= 0 ;
string c;
double ans;
int main (){
// double string a.length() unsigned long long
// freopen("?.in","r",stdin);scanf("%d",&a);
// freopen("?.out","w",stdout);printf("%d",a);ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
while (1 ){
getline (cin,c);
if (c== "EOF" ){
break ;
}
int l= c.size ();
f++ ;
for (int i= 0 ;i< l;i++ ){
if (c[i]!= '<' ){
a[f].push (c[i]);
}
else {
if (a[f].size ()){
a[f].pop ();
}
}
}
}
while (1 ){
getline (cin,c);
if (c== "EOF" ){
break ;
}
f1++ ;
int l= c.size ();
for (int i= 0 ;i< l;i++ ){
if (c[i]!= '<' ){
b[f1].push (c[i]);
}
else {
if (b[f1].size ()){
b[f1].pop ();
}
}
}
}
cin>> t;
for (int i= 1 ;i<= f;i++ ){
while (a[i].size ()){
if (a[i].top ()== b[i].top ()){
ans++ ;
}
a[i].pop ();
b[i].pop ();
}
}
cout<<int (ans* 1.0 / t* 60 );
return 0 ;
}
//?I
改正
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
string a[100020 ],b[100020 ],f1,f2;
int k,x,y;
int main (){
// doublx string a.lxngth() unsignxd long long
// frxopxn("?.in","r",stdin);scanf("%d",&a);
// frxopxn("?.out","w",stdout);printf("%d",a);
ios ::sync_with_stdio (0 ),cin.tie (0 ),cout.tie (0 );
while (1 ){
getline (cin,f1);
if (f1== "EOF" ){
break ;
}
int l= f1.size ();
x++ ;
stack<char> q;
for (int i= 0 ;i< l;i++ ){
if (f1[i]!= '<' ){
q.push (f1[i]);
}else {
if (q.size ()){
q.pop ();
}
}
}
f2= "" ;
while (q.size ()){
f2+= q.top ();
q.pop ();
}
reverse (f2.begin (),f2.end ());
a[x]= f2;
}
while (1 ){
getline (cin,f1);
if (f1== "EOF" ){
break ;
}
int l= f1.size ();
y++ ;
stack<char> q;
for (int i= 0 ;i< l;i++ ){
if (f1[i]!= '<' ){
q.push (f1[i]);
}else {
if (q.size ()){
q.pop ();
}
}
}
f2= "" ;
while (q.size ()){
f2+= q.top ();
q.pop ();
}
reverse (f2.begin (),f2.end ());
b[y]= f2;
}
cin>> k;
int ans;
ans= 0 ;
for (int i= 1 ;i<= min (x,y);i++ ){
for (int j= 0 ;j< min (a[i].size (),b[i].size ());j++ ){
if (a[i][j]== b[i][j]){
ans++ ;
}
}
}
cout<< (long long )(ans* 60 / k);
return 0 ;
}
//㊣
第五题
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
int n,m,qx,qy,zx,zy,b[1020 ][1020 ],c[1020 ][1020 ];
char a[1020 ][1020 ];
struct str {
int x,y,s;
};
int d[4 ][2 ]{
{1 ,0 },{0 ,1 },{- 1 ,0 },{0 ,- 1 }
};
int bfs (){
queue< str> q;
for (int i= 1 ;i<= n;i++ ){
for (int j= 1 ;j<= m;j++ ){
b[i][j]= 0 ;
}
}
b[qx][qy]= 1 ;
q.push ({qx,qy,0 });
while (q.size ()){
str f= q.front ();
q.pop ();
if (c[f.x][f.y]){
cout<< f.s<< " \n " ;
return 0 ;
}
for (int i= 0 ;i< 4 ;i++ ){
int xx= f.x+ d[i][0 ],yy= f.y+ d[i][1 ];
if (xx<= 0 || yy<= 0 || xx> n|| yy> m) continue ;
if (a[xx][yy]== 'X' || b[xx][yy]) continue ;
b[xx][yy]= 1 ;
q.push ({xx,yy,f.s+ 1 });
}
}
cout<< "Poor Harry \n " ;
return 0 ;
}
int main (){
// double string a.length() unsigned long long
// freopen("?.in","r",stdin);scanf("%d",&a);
// freopen("?.out","w",stdout);printf("%d",a);ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>> n>> m;
for (int i= 1 ;i<= n;i++ ){
for (int j= 1 ;j<= m;j++ ){
cin>> a[i][j];
}
}
while (cin>> qx>> qy>> zx>> zy){
if (qx== 0 ){
return 0 ;
}
for (int i= 1 ;i<= n;i++ ){
for (int j= 1 ;j<= m;j++ ){
c[i][j]= 0 ;
}
}
for (int i= zx;i<= n&& a[i][zy]!= 'X' ;i++ ){
c[i][zy]= 1 ;
}
for (int i= zx;i>= 1 && a[i][zy]!= 'X' ;i-- ){
c[i][zy]= 1 ;
}
for (int i= 0 ;i+ zx<= n&& i+ zy<= m&& a[zx+ i][zy+ i]!= 'X' ;i++ ){
c[i+ zx][i+ zy]= 1 ;
}
for (int i= 1 ;zx- i>= 1 && zy- i>= 1 && a[zx- i][zy- i]!= 'X' ;i++ ){
c[zx- i][zy- i]= 1 ;
}
for (int i= zy;i<= m&& a[zx][i]!= 'X' ;i++ ){
c[zx][i]= 1 ;
}
for (int i= zy;i>= 1 && a[zx][i]!= 'X' ;i-- ){
c[zx][i]= 1 ;
}
for (int i= 1 ;zx+ i<= n&& zy- i>= 1 && a[i+ zx][zy- i]!= 'X' ;i++ ){
c[i+ zx][zy- i]= 1 ;
}
for (int i= 1 ;zx- i>= 1 && zy+ i<= n&& a[i- zx][i+ zy]!= 'X' ;i++ ){
c[i- zx][zy+ i]= 1 ;
}
bfs ();
}
return 0 ;
}
//�I
第六题
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
long long n,m,f[1000020 ],d[1000020 ],re[1000020 ],r[1000020 ],l[1000020 ],d1[1000020 ];
long long rf (long long x ){
memset (f,0 ,sizeof (f));
for (long long i= 1 ;i<= x;i++ ){
f[l[i]]+= d1[i];
f[r[i]+ 1 ]-= d1[i];
}
for (long long i= 1 ;i<= n;i++ ){
d[i]= d[i- 1 ]+ f[i];
if (d[i]> re[i])return 0 ;
}
return 1 ;
}
int main (){
cin>> n>> m;
for (long long i= 1 ;i<= n;i++ ){
cin>> re[i];
}for (long long i= 1 ;i<= m;i++ ){
cin>> d1[i]>> l[i]>> r[i];
}
long long ll= 1 ,rr= m,mid;
if (rf (m)){
cout<< "0" ;
return 0 ;
}
while (ll< rr){
mid= (ll+ rr)/ 2 ;
if (rf (mid)){
ll= mid+ 1 ;
}else {
rr= mid;
}
}
cout<< "-1" << endl<< ll;
}
//㊣
C++ 复制 #include <bits/stdc++.h>
using namespace std ;
int n,m,cd,ks,js[1000020 ],b[10020 ],s[10020 ],L[10020 ],R[10020 ],f1,f2,f3;
int a[1000020 ];
int kkk (){
cd= sqrt (n);
ks= n/ cd;
for (int i= 1 ;i<= n;i++ ){
js[i]= (i- 1 )/ cd+ 1 ;
s[js[i]]= min (s[js[i]],a[i]);
}
for (int i= 1 ;i<= ks;i++ ){
L[i]= R[i- 1 ]+ 1 ;
R[i]= cd* i;
}
if (cd* cd!= n){
ks++ ;
L[ks]= R[ks- 1 ]+ 1 ;
R[ks]= n;
}
return 0 ;
}
int cyx (){
int e= js[f2],w= js[f3];
if (e== w){
for (int i= f2;i<= f3;i++ ){
a[i]-= f1;
s[e]= min (s[e],a[i]- b[e]);
}
}
else {
for (int i= f2;i<= R[e];i++ ){
a[i]-= f1;
s[e]= min (s[e],a[i]- b[e]);
}
for (int i= L[w];i<= f3;i++ ){
a[i]-= f1;
s[w]= min (s[w],a[i]- b[w]);
}
for (int i= e+ 1 ;i< w;i++ ){
b[i]+= f1;
s[i]-= f1;
}
}
for (int i= 1 ;i<= ks;i++ ){
if (s[i]< 0 ) return 0 ;
}
return 1 ;
}
int main (){
// double string a.length() unsigned long long
// freopen("?.in","r",stdin);scanf("%d",&a);
// freopen("?.out","w",stdout);printf("%d",a);ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>> n>> m;
for (int i= 1 ;i<= n;i++ ){
cin>> a[i];
}
for (int i= 1 ;i<= 10000 ;i++ ){
s[i]= INT_MAX;
}
kkk ();
int h= 0 ;
while (m-- ){
h++ ;
cin>> f1>> f2>> f3;
if (cyx ()== 0 ){
cout<<- 1 ;
cout<< " \n " << h;
return 0 ;
}
}
cout<< 0 ;
return 0 ;
}