ACM题目造数据

In:

#include <bits/stdc++.h>
using namespace std;

int random(int l,int r){
    
    
	return (long long)rand()*rand()%(r-l+1)+l;
}

int main()
{
    
    
	
  srand(int(time(0)));//加上这个才能真正产生随机数 
  for(int i = 1; i <= 10; i ++){
    
    
  string fileName = "";
  string c = to_string(i);
  fileName += c;
  fileName += ".in";
  freopen(fileName.c_str(), "w", stdout);
  int l= random(1,2e6);
  int m= random(1,2e6);
  cout<<l<<" "<<m<<endl;
  for(int i=1;i<=m;i++){
    
    
  	int s=random(0,l);
  	int e=random(s,l);
  	printf("%d %d\n",s,e);
  }
  fclose(stdout);
  }
  return 0;
}

Out:

#include <bits/stdc++.h>
using namespace std;
const int N = 2e6+9;
int tr[N];
int d[N];

void solve(){
    
    
	memset(tr,0,sizeof(tr));
	memset(d,0,sizeof(d));
	int l,m;
    scanf("%d%d",&l,&m);
    for(int i=1;i<=l+1;i++) tr[i] = 1;
    d[1] = 1;
    while(m--)
    {
    
    
    	int s,e;
    	scanf("%d%d",&s,&e);
    	s++;
    	e++;
        d[s]--;
    	if(e+1<=l+1) d[e+1]++;
	}
	int ans = 0;
	for(int i=1;i<=l+1;i++)
	{
    
    
		d[i] = d[i] + d[i-1];
	//	cout<<d[i]<<" ";
		if(d[i]>0) ans++;
	}
	//cout<<endl;
	printf("%d\n",ans);
}

int main(void)
{
    
    
    for(int i = 1; i <= 10; i ++)
    {
    
    
      string fileName = "";
      string c = to_string(i);//确定对应的标号 
      fileName += c;
      fileName += ".in";
      freopen(fileName.c_str(), "r", stdin);
      string fileNameout = "";
      string s = to_string(i);
      fileNameout += s;
      fileNameout += ".out";
      freopen(fileNameout.c_str(), "w", stdout);
      solve();
    }
	fclose(stdin);
	fclose(stdout);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_45769627/article/details/109602778