UVA 10334 - Ray Through Glasses(高精度斐波那契)

Ray Through Glasses 

Suppose we put two panes of glass back-to-back. How many ways  are there for light rays to pass through or be reflected after changing direction n times ? Following figure shows the situations when the value of nis 0, 1 and 2. 
                                  

Input 

It is a set of lines with an integer n where 0 <= n <= 1000 in each of them.

Output 

For every one of these integers a line containing  as described above.

Sample Input 

0
1
2

Sample Output 

1
2
3

题意:斐波那契,前1000项。

思路:用高精度去写

代码:

#include <stdio.h>
#include <string.h>

int n;
int f[1005][35];

void solve() {
	memset(f, 0, sizeof(f));
	f[0][0] = 1; f[1][0] = 2;
	for (int i = 2; i <= 1000; i ++) {
		for (int j = 0; j < 35; j ++) {
			f[i][j] += f[i - 1][j] + f[i - 2][j];
			f[i][j + 1] += f[i][j] / 100000000;
			f[i][j] %= 100000000;
		}
	}

}

void print(int n) {
	int i, j;
	for (i = 34; i >= 0; i --) {
		if (f[n][i] != 0)
			break;
	}
	printf("%d", f[n][i]);
	for (j = i - 1; j >= 0; j --)
		printf("%08d", f[n][j]);
	printf("\n");
}

int main() {
	solve();
	while (~scanf("%d", &n)) {
		print(n);
	}
	return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用 C# 实现人脸识别的代码,其中使用了高精度算法: ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; using System.Drawing.Imaging; using System.IO; using Microsoft.Azure.CognitiveServices.Vision.Face; using Microsoft.Azure.CognitiveServices.Vision.Face.Models; using MathNet.Numerics.LinearAlgebra; namespace HighAccuracyFaceRecognition { class Program { static void Main(string[] args) { // 读取图片文件 string imagePath = "path/to/image.jpg"; Bitmap image = new Bitmap(imagePath); // 将图片转换为字节数组 byte[] imageData; using (MemoryStream ms = new MemoryStream()) { image.Save(ms, ImageFormat.Jpeg); imageData = ms.ToArray(); } // 初始化 Face API 客户端 string subscriptionKey = "your-subscription-key"; string endpoint = "https://your-endpoint.cognitiveservices.azure.com/"; FaceClient faceClient = new FaceClient(new ApiKeyServiceClientCredentials(subscriptionKey)) { Endpoint = endpoint }; // 配置人脸检测参数 IList<FaceAttributeType> faceAttributes = new List<FaceAttributeType>() { FaceAttributeType.Emotion, FaceAttributeType.Gender, FaceAttributeType.Age, FaceAttributeType.Smile, FaceAttributeType.Glasses, FaceAttributeType.HeadPose }; // 检测人脸 DetectResult[] detectResults = faceClient.Face.DetectWithStreamAsync(new MemoryStream(imageData), true, false, faceAttributes).Result; // 遍历检测结果 foreach (DetectResult detectResult in detectResults) { // 获取人脸特征向量 Guid faceId = detectResult.FaceId.Value; FaceAttribute features = detectResult.FaceAttributes; double[] featureVector = GetFeatureVector(faceClient, faceId); // 进行人脸识别 string personName = RecognizeFace(featureVector); // 输出结果 Console.WriteLine($"Person name: {personName}"); Console.WriteLine($"Emotion: {features.Emotion.ToRankedList().First().Key}"); Console.WriteLine($"Gender: {features.Gender}"); Console.WriteLine($"Age: {features.Age}"); Console.WriteLine($"Smile: {features.Smile}"); Console.WriteLine($"Glasses: {features.Glasses}"); Console.WriteLine($"Head pose: roll={features.HeadPose.Roll}, yaw={features.HeadPose.Yaw}, pitch={features.HeadPose.Pitch}"); } } static double[] GetFeatureVector(FaceClient faceClient, Guid faceId) { // 获取人脸特征向量 const int FEATURE_VECTOR_SIZE = 512; FaceAttributeType[] faceAttributes = { FaceAttributeType.FaceLandmarks }; FaceAttribute[] attributes = faceClient.Face.GetFaceAttributesAsync(faceId, faceAttributes).Result; Landmarks landmarks = attributes[0].FaceLandmarks; DenseMatrix imagePoints = DenseMatrix.OfArray(new double[,] { { landmarks.PupilLeft.X, landmarks.PupilLeft.Y }, { landmarks.PupilRight.X, landmarks.PupilRight.Y }, { landmarks.NoseTip.X, landmarks.NoseTip.Y }, { landmarks.MouthLeft.X, landmarks.MouthLeft.Y }, { landmarks.MouthRight.X, landmarks.MouthRight.Y } }); Vector<double> featureVector = FaceRecognition.ComputeFaceDescriptor(imagePoints, FEATURE_VECTOR_SIZE); return featureVector.ToArray(); } static string RecognizeFace(double[] featureVector) { // TODO: 实现人脸识别算法,返回识别结果 return "Unknown"; } } } ``` 在上述代码中,`GetFeatureVector` 函数使用 `Face API` 获取人脸关键点坐标,然后调用 `FaceRecognition.ComputeFaceDescriptor` 函数计算人脸特征向量。`RecognizeFace` 函数需要根据已有的人脸库进行人脸识别,这里需要自己实现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值