fibmod and points for test

#include <stdio.h>
#include <math.h>
long long n, b, k;

struct state {
	long long s[2][2];
	state(long long a = 0, long long b = 0, long long  c = 0, long long d = 0) {
		s[0][0] = a, s[0][1] = b, s[1][0] = c, s[1][1] = d;
	}
}tmp(1, 0, 0, 1), c(1, 1, 1, 0);

state count(const state& p, const state& q) {
	state f;
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < 2; j++)
			f.s[i][j] = (p.s[i][0] * q.s[0][j] + p.s[i][1] * q.s[1][j]) % b;
	return f;
}

state solve(long long k) {
	if (k == 0) return tmp;
	else if (k == 1) return c;

	state a = solve(k / 2);

	a = count(a, a);
	if (k % 2) a = count(a, c);
	return a;
}

int main () {
	int m;
	while (scanf("%lld%d", &n, &m) == 2) {
		b = m;
		if (n) {
			state ans = solve(n - 1);
			k = ans.s[0][0];
		} else
			k = 0;
		printf("%lld\n", k);
	}
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
//#include <cstring>
#include <cmath>
using namespace std;


struct POINT
{
	int x,y;
}point[110];

int n;
double getArea()
{
	double sum = 0;
	for (int i = 0; i < n; ++ i)
	{
		sum += (point[i].x   * point[(i + 1) % n].y   - point[i].y  * point[(i + 1) % n].x );
	}
	return fabs(sum/2.0);
}

int Gcd(int a, int b)
{
	if (0 == b)
	{
		return a;
	}
	else
		return Gcd(b, a % b);
}
int getSegmentPoint(POINT p1, POINT p2)
{
	int a = abs(p2.y - p1.y);
	int b = abs(p2.x - p1.x);

	if (a == 0 && b == 0)
	{
		return 0;
	}
	if (a == 0)
	{
		return b - 1;
	}
	if (b == 0)
	{
		return a - 1;
	}
	return Gcd(b, a) - 1;
}
int getPoint()
{
	int ans = n;
	for (int i = 0; i < n; ++ i)
	{
		ans += getSegmentPoint(point[i], point[(i + 1) % n]);
	}
	return ans;
}
int main()
{
	int cas, j = 1;
	int temp1=0,temp2=0,temp3=0,temp4=0,begin1=0,begin2 = 0;
	scanf("%d", &cas);
	while (cas --)
	{
		scanf("%d", &n);
		point[0].x = point[0].y = 0;
		//temp1 = 0;temp2 = 0;temp3 = 0;temp4 = 0;
		for (int i = 1; i <= n; ++ i)
		{
			scanf("%d %d", &point[i].x, &point[i].y);
			//point[i].x = temp3-temp1;
			//point[i].y = temp4-temp2;
			//temp1 =temp3;
			//temp2 =temp4;
			//point[i].x += point[i - 1].x;
			//point[i].y += point[i - 1].y;
			//cin >> point[i].x >> point[i].y;
		}
		for (int i = 1; i <= n; ++ i){
            point[i].x=point[i].x-point[n].x;
            point[i].y=point[i].y-point[n].y;
		}

		printf("Scenario #%d:\n", j ++);
		double Area = getArea();
		int res;
		int PointNum = getPoint();
		res = (int)Area - PointNum / 2 + 1;
		printf("%d %d %.1lf\n\n", res, PointNum, Area);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值