每日打卡 2017.03.07 POJ题目分类 水题

与PKU那么有缘,所以从今天起到复试结束,每天刷1-2道POJ


题目来源:http://blog.csdn.net/a1dark/article/details/11714009/


题目地址,在owner中搜yeyangulu即可:https://vjudge.net/contest/


POJ 3299


Tip1:%.1lf是会自动进行四舍五入的

Tip2:<iomanip>下cout<<setprecision(k)保留k位小数并四舍五入,cout<<fixed保证输出浮点数而不是科学计数法

Tip3:仔细看英文原题!!!

Tip4:floor返回不超过其的最大整数,exp是以e为底数的指数,log是以e为底的对数,log10是以10为底的对数

Tip5:printf里没有%lf,用%f通杀float和double,在scanf里才有区分


#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main()
{
	freopen("input.txt", "r", stdin);

	string k;
	double t, d, h;
	int z;
	while(true)
	{
		z = 0;
		cin >> k;
		if(k == "E") break;
		if(k == "T")
		{
			z += 1;
			cin >> t;
		}
		if(k == "D")
		{
			z += 2;
			cin >> d;
		}
		if(k == "H")
		{
			z += 4;
			cin >> h;
		}
		cin >> k;
		if(k == "T")
		{
			z += 1;
			cin >> t;
		}
		if(k == "D")
		{
			z += 2;
			cin >> d;
		}
		if(k == "H")
		{
			z += 4;
			cin >> h;
		}
		if(z == 3)
		{
			h = 6.11 * exp(5417.7530 * ((1/273.16) - (1/(d+273.16))));
			h = (0.5555)* (h - 10.0) + t;
		}
		if(z == 5)
		{
			d = h - t;
			d = d/0.5555 + 10;
			d = log(d /6.11)/log(exp(1));
			d /= 5417.7530;
			d = (1/273.16) - d;
			d = 1/d;
			d -= 273.16;
		}
		if(z == 6)
		{
			t = 6.11 * exp(5417.7530 * ((1/273.16) - (1/(d+273.16))));
			t = (0.5555)* (t - 10.0);
			t = h - t;
		}
		//printf("T %.1lf D %.1lf H %.1lf\n", t, d, h);
		printf("T %.1f D %.1f H %.1f\n", t, d, h);
		//cout<<setprecision(1)<<fixed<<"T "<<t<<" D "<<d<<" H "<<h<<endl;
	}

	return 0;
}


POJ 2159


Tip1:奇数odd 偶数even 大写capital 小写lower-case

Tip2:题目可能会非常坑,务必细度关键英文!

#include<iostream>
#include<algorithm>
using namespace std;

string s1, s2;
int z1[26], z2[26];

int main()
{
	freopen("input.txt", "r", stdin);
	cin >> s1 >> s2;
	for(int i = 0; i < s1.length(); i++)
	{
		z1[s1[i]-'A']++;
		z2[s2[i]-'A']++;
	}
	sort(z1, z1 + 26);
	sort(z2, z2 + 26);
	bool ok = true;
	for(int i = 0; i < 26; i++)
	{
		if(z1[i] != z2[i])
		{
			ok = false;
			break;
		}
	}
	cout << (ok?"YES":"NO") << endl;
	return 0;
}

POJ 2739


Tip1:consecutive 连续的



#include<iostream>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int n;
int prime[10001];
int pos[10001];
int a[10001];
int tot;

int main()
{
	freopen("input.txt", "r", stdin);
	
	for(int i = 2; i <= 10000; i++)
	{
		int ok = 1, p = (int)(sqrt(i) + 0.5);
		for(int j = 2; j <= p; j++)
		{
			if(i % j == 0)
			{
				ok = 0;
				break;
			}
		}
		prime[i] = ok;
	}
	for(int i = 2; i <= 10000; i++)
	{
		if(prime[i])
		{
			pos[i] = tot;
			a[tot++] = i;
		}
	}
	for(int i = tot - 1; i >= 0; i--)
	{
		int sum = a[i], p = i - 1;
		while(sum < 10001 && p >= 0)
		{
			sum += a[p];
			p--;
			prime[sum]++;
		}
	}
	
	while(scanf("%d", &n) && n != 0)
	{
		printf("%d\n", prime[n]);
	} 

	return 0;
}

POJ 1083


#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#define sf(a) scanf("%d", &a)
#define sf2(a,b) scanf("%d%d", &a, &b)
using namespace std;

const int MAXN = 200 + 1;
int T, N;

int a[MAXN];

int main()
{
	freopen("input.txt", "r", stdin);
	sf(T);
	int t1, t2;
	while(T--)
	{
		sf(N);
		memset(a, 0, sizeof(a));
		for(int i = 0; i < N; i++)
		{
			sf2(t1, t2);
			t1 = (t1 - 1) / 2;
			t2 = (t2 - 1) / 2; 
			if(t1 > t2) swap(t1, t2);
			for(int j = t1; j <= t2; j++) a[j]++;
		}
		sort(a, a + 200);
		cout << a[199] * 10 << endl;
	}
	return 0;
}

POJ 2262


Tip1:素数筛法

vis[0] = 1;

vis[1] = 1;


for(int i = 2; i <= n; i++)
    for(int j = i*2; j <= n; j+=i)vis[j] = 1;

更高效(效率提升1.2倍)

int m = sqrt(n+0.5);
for(int i = 2; i <= m; i++)
   if(!vis[i]) for(int j = i*i; i <= n; j+=i)vis[j] = 1;
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#define sf(a) scanf("%d", &a)
#define sf2(a,b) scanf("%d%d", &a, &b)
using namespace std;

const int MAXN = 1000000 + 5;
int T, N;

bool vis[MAXN];
int pos[MAXN];

int main()
{
	freopen("input.txt", "r", stdin);
	int m = sqrt(MAXN + 0.5);
	for(int i = 2; i <= m; i++)
	{
		if(!vis[i])
		for(int j = i*i; j <= MAXN; j += i)
			vis[j] = true;
	}
	int tot = 0;
	pos[tot++] = 2;
	for(int i = 3; i < MAXN; i+=2)
	{
		if(!vis[i]) pos[tot++] = i;
	}
	while(sf(N)  && N != 0)
	{
		bool ok = false;
		for(int i = 0; i < tot; i++)
		{
			if(!vis[N-pos[i]])
			{
				printf("%d = %d + %d\n", N, pos[i], N - pos[i]);
				ok = true;
				break;
			}
		}
		if(!ok)
		{
			printf("Goldbach's conjecture is wrong.\n");
		}
	}
	return 0;
}

POJ 1503

#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#define sf(a) scanf("%d", &a)
#define sfs(a) scanf("%s", a)
#define sf2(a,b) scanf("%d%d", &a, &b)
using namespace std;

const int MAXN = 102;
int tot = 0;
int a[MAXN][MAXN];
char str[MAXN];
int ans[MAXN];

int main()
{
	freopen("input.txt", "r", stdin);
	while(sfs(str) != EOF)
	{
		int len = strlen(str);
		for(int i = 0; i < len; i++)
			a[tot][MAXN - 1 - i] = str[len - 1 - i] - '0';
		tot++;
	}
	int p = 0;
	for(int i = MAXN - 1; i >= 0; i--)
	{
		int sum = p;
		for(int j = 0; j < tot; j++)
		{
			sum += a[j][i];
		}
		ans[i] = sum % 10;
		p = sum / 10;
	}
	bool ok = false;
	for(int i = 0; i < MAXN; i++)
	{
		if(ans[i] != 0) ok = true;
		if(ok)cout << ans[i];
	}
	cout << endl;
	return 0;
}

POJ 3006

#include<iostream>
#include<cmath>
using namespace std;

const int MAXN = 1000000 + 5;
bool vis[MAXN];

int main()
{
	//freopen("input.txt", "r", stdin);
	vis[0] = 1;
	vis[1] = 1;
	int m = sqrt(MAXN + 0.5);
	for(int i = 2; i <= m; i++)
	{
		if(!vis[i])
		{
			for(int j = i*i; j < MAXN; j+=i)
			{
				vis[j] = true;
			}
		}
	}
	int a, d, n;
	while(cin >> a >> d >> n)
	{
		if(n == 0)break;
		while(true)
		{
			if(!vis[a])
			{
				if(n == 1)
				{
					cout << a << endl;
					break;
				}
				else
				{
					n--;
				}
			}
			a += d;
		}
	}
	return 0;
}

POJ 2255


#include<iostream>
#include<cmath>
using namespace std;

const int MAXN = 26;
string preord, inord;

struct Node
{
	Node *lchild, *rchild;
	char value;
	Node(int value = 0):value(value), lchild(NULL), rchild(NULL) {}
};

Node* build(int inl, int inr, int prel, int prer)
{
	if(inl >= inr) return NULL;
	Node *ret = new Node(preord[prel]);
	int p = -1;
	for(int i = inl; i < inr; i++)
	{
		if(preord[prel] == inord[i])
		{
			p = i;
			break;
		}
	}
	int delta = p - inl;
	ret->lchild = build(inl, p, prel + 1, prel + delta + 1);
	ret->rchild = build(p + 1, inr, prel + delta + 1, prer);
	return ret;
}

void postord(Node *root)
{
	if(root == NULL)return;
	postord(root->lchild);
	postord(root->rchild);
	cout << root->value;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	while(cin >> preord >> inord)
	{
		int len = preord.length();
		Node *root = build(0, len, 0, len);
		postord(root);
		cout << endl;
	}
	return 0;
}

POJ 3094

#include<iostream>
#include<cmath>
using namespace std;

const int MAXN = 26;

string str;

int main()
{
	//freopen("input.txt", "r", stdin);
	while(getline(cin, str))
	{
		if(str == "#")break;
		int sum = 0;
		for(int i = 0; i < str.size(); i++)
		{
			if(str[i] == ' ')continue;
			sum += (str[i] - 'A' + 1) * (i + 1);
		}
		cout << sum << endl;
	}
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值