模拟专题填题记

tonyfang posted @ 2015年8月31日 15:28 in 随笔 with tags c++ OI , 467 阅读

…现在需要多填些题…

现在已经做了

5

开始填题啦~

1025 & 1560 NOIP2005表达式求值

有点麻烦的要用栈来搞来搞去~测试数据还有BUG,括号不配对。。

 

# include <stdio.h>
# include <iostream>
# include <stack>
# include <string.h>
using namespace std;
# define ll long long
const int Mod=100000007;
int n;
struct options {
	char a[10010];
} s;
const int gi[]={0,-1, 0, 1, 2, 3, 83, 89, 97, 233, 1001},gn=10;

inline int isdigit(char x) {
	return (x>='0'&&x<='9');
}
inline int isalpha(char x) {
	return (x>='a'&&x<='z');
}

stack <ll> number;
stack <char> opt;

inline ll qp(ll r,ll s) {
	ll ss=1;
	for(int i=1;i<=s;++i)ss*=r,ss%=Mod;
	return ss;
}

inline int xxx(char opt) {
	if(opt=='(')return 0;
	if(opt=='+'||opt=='-')return 1;
	if(opt=='*')return 2;
	if(opt=='^')return 3;
}

inline ll js() {
	ll r,s,t;
	char op=opt.top();
	opt.pop();
	s=number.top();number.pop();
	r=number.top();number.pop();
	if(op=='+') t=s+r;
	if(op=='-') t=r-s;
	if(op=='*') t=s*r;
	if(op=='^') t=qp(r,s);
	t=(t%Mod+Mod)%Mod;
	number.push(t);
}

inline ll g(options x,int value) {
	int sizes=strlen(x.a);
	for (int i=0;i<sizes;++i) {
		if(x.a[i]==' ')continue;
		if (isdigit(x.a[i])) {
			ll y=x.a[i]-'0';
			while(isdigit(x.a[i+1])) y=(y<<1)+(y<<3)+x.a[++i]-'0',y%=Mod;
			number.push(y);
		} else if (isalpha(x.a[i])) number.push(value);
		else if(x.a[i]=='(') opt.push(x.a[i]);
		else if(x.a[i]==')') {
			while(!opt.empty()&& opt.top()!='(') js();
			if(!opt.empty())opt.pop();
		} else {
			while(!opt.empty() && xxx(opt.top())>=xxx(x.a[i])) js();
			opt.push(x.a[i]);
		}
	}
	while(!opt.empty()) js();
	return number.top();
}
ll sample[gn+1000];
main() {
	gets(s.a);
	for(int i=1;i<=gn;++i)sample[i]=g(s,gi[i]);
	cin>>n;getchar();
	for (int j=0,i;j<n;++j) {
		gets(s.a);
		for (i=1;i<=gn;++i) if(g(s,gi[i])!=sample[i]) break;
		if(i==gn+1) putchar('A'+j);
	}return 0;
}

1081 hopscotch:随便乱搞,$O(n^{2}m^{2})$,因为$n,m \leq 50$。缩进有点~~不好看,别介意~

 

#include<stdio.h>
#include<math.h>
using namespace std;
int n,m;
int map[51][51];
char t;
inline void g(int x,int y) {
	for(int ii=1;ii<=n;++ii)for(int jj=1;jj<=m;++jj){
		double xx=sqrt((ii-x)*(ii-x)+(jj-y)*(jj-y));int yy=xx;
		if(xx==yy) map[ii][jj]=!map[ii][jj];
	}
}
main(){
	scanf("%d%d\n",&n,&m);
	for(int i=1;i<=n;++i) {
		for (int j=1;j<=m;++j) {
			scanf("%c",&t);
			map[i][j]=t=='B'?1:0;
		}
		if(i!=n) scanf("\n");
	}
	//for (int i=1;i<=n;printf("\n"),++i)for(int j=1;j<=m;++j) printf("%d ",map[i][j]);
	for(int i=1;i<=n;++i)for(int j=1,t;j<=m;++j){
		scanf("%d",&t);
		if(t&1)g(i,j);
	}
	for (int i=1;i<=n;printf("\n"),++i)for(int j=1;j<=m;++j) printf("%c",map[i][j]?'B':'W');
}

1114:简单题不贴代码了。

2074:记$f(n)$为正整数$n$的因数个数,求$M=\sum_{i=1}^Nf(i)$

随便推了推

#include<stdio.h>
int r,n;long long a;main() {scanf("%d",&n);for(int i=1;i<=n;i=r+1)r=n/(n/i),a+=(r-i+1)*(n/i);printf("%lld",a);}

 

 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter