[Simulation] [summary] exercises

uvalive3059

Ideas: a very simple simulation, where it set an initial value b [0] can unify all processes.

#include <iostream>
#include <cstdio>
using namespace std;
int a[100],b[100];
int t;
int sum;
int main()
{
	//freopen("input.txt","r",stdin);
	while(cin>>t&&t!=-1)
	{
		sum=0;
		a[0]=b[0]=0;
		for(int i=1;i<=t;++i)
			cin>>a[i]>>b[i];
		for(int i=1;i<=t;++i)
			sum+=a[i]*(b[i]-b[i-1]);
		printf("%d miles\n",sum);
	}
	return 0;
}

uva640

Understand what sieve method simulation

Ideas: a little confused by the meaning of the questions, in fact, each number only counted once is enough. But still I do not know why the wa.

#include <iostream>
#include <string.h>
using namespace std;
const int maxn=100000+10;
int a[maxn];
int main()
{
	memset(a,0,sizeof(a));
	for(int i=1;i<=100000;++i)
	{
		int n=i;
		int b=i;
		while(b)
		{
			n+=(b%10);
			b/=10;
		}
		a[n]=1;

	}
	for(int i=1;i<=100000;++i)
	{
		if(!a[i])cout<<i<<endl;
	}
	return 0;
}

uva11000 

Ideas: This title is write a few years to find the law, after the assignment is very interesting. Garlic from the meter off.

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	
	int n;
	while(cin>>n&&n!=-1)
	{
		long long a=1,b=0,c,d;
		while(n--)
		{
			c=b+1;
			d=a+b;
			a=c;
			b=d;
		}
		cout<<b<<" "<<a+b<<endl;
	}
	return 0;
}

poj2260

Thinking: this simulation is very clever, but also used the bitwise & operator.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int a[110][110];//存储矩阵
int col[110],row[110];//统计各行各列数字
int n;
int cr,cc;// 计算奇数列(行)的总数,都为0则ok,都为1则更改,else就是corrupt的
int pr,pc;// 记录需要更改的列和行
int main()
{
	//freopen("in.txt","r",stdin);
	while(cin>>n&&n)
	{
		cr=0;cc=0;
		memset(a,0,sizeof(a));
		memset(col,0,sizeof(col));
		memset(row,0,sizeof(row));
		for(int i=0;i<n;++i)
			for(int j=0;j<n;++j)
			{
				cin>>a[i][j];
				if(a[i][j]==1)
				{
					row[i]++;
					col[j]++;
				}
			}
		for(int i=0;i<n;++i)
		{
			if(row[i]&1==1){cr++;pr=i;}
			if(col[i]&1==1){cc++;pc=i;}
		}
		if(cr==0&&cc==0)cout<<"OK\n";
		else if(cr==1&&cc==1)printf("Change bit (%d,%d)\n",pr+1,pc+1);
		else cout<<"Corrupt\n";
	}
	return 0;
}

 

Published 22 original articles · won praise 3 · Views 1839

Guess you like

Origin blog.csdn.net/qq_42825058/article/details/86743389