算法加项目

1.仅加号

很简单,找到每次添加后最小的即可,这里不做演示。

2.采药

dp,for1数目,for2时间,简单的dp模板题目。

#include<bits/stdc++.h>
using namespace std;
int n,m;
const int N=105,M=105;
long long a[M],b[M],dp[N][1005];
int main() {
    cin>>m>>n;
    for(int i=1; i<=n; i++)
        cin>>a[i]>>b[i];
    for(int i=1; i<=n; i++) {
        for(int j=m; j>=0; j--) {
            if(j>=a[i])
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i]]+b[i]);
                else
                dp[i][j]=dp[i-1][j];
        }
    }
    printf("%lld",dp[n][m]);
    return 0;
}

3.奶牛晒衣服

二分,二分对象为时间,从最多的时间开始一直折半,直到while条件不成立,则可以得出结果!

#include<bits/stdc++.h>
using namespace std;
long long s[500005];
long long n,a,b;
long long l=0,r=0;
int pd(int x){
	int k=0;
	for(int i=1;i<=n;i++){
		if(s[i]-a*x<=0)continue;
		int e=s[i]-a*x;
		if(e%b!=0)
		k+=e/b+1;
		else
		k+=e/b;
	}
	if(k<=x) return 1;
    else return 0;
}
int main() {
	cin>>n>>a>>b;
	for(int i=1; i<=n; i++) {
		cin>>s[i];
		r=max(r,s[i]/a+1);
	}
	long long mid=r;
	while(l<r) {
		mid=(l+r)/2;  //时间
		if(pd(mid))
		r=mid;
		else
		l=mid+1;
	}
	cout<<r;

	return 0;
}

4.进击的奶牛

稍微比普通的二分模板题目难一点,将他们的距离进行二分,然后进行判断,如果pd函数成立,则继续查找比x更大的距离。

#include<bits/stdc++.h>
using namespace std;
long long s[500005];
long long n,a,b,m;
long long l=1,r=0;
int pd(int x){
	int k=1,y=s[1];
	for(int i=2;i<=n;i++){
         if(s[i]-y>=x)
         y=s[i],k++;
         else
         continue;
	}
//	cout<<k<<endl;
	if(k<m) return 0;
    else return 1;
}
int main() {
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		cin>>s[i];
	}
	sort(s+1,s+1+n);
	r=s[n];
	long long mid;
	while(l+1<r) {
		mid=(l+r)/2;  //距离
		if(pd(mid))
			l=mid;
		else
			r=mid;

	//	cout<<l<<" "<<r<<" "<<mid<<endl;
	}
	cout<<l;

	return 0;
}

5.木材加工

也是模板二分,不用绕弯子。

6.最小餮食

找到数组A,满足条件的最小个数,在找到数组B,满足条件的最小个数,他们之间最小的必然同时满足两个条件。注意:x,y,t这里要用long long 因为为14次方,int满足不了。

#include<bits/stdc++.h>
using namespace std;
long long t,x,y;
int ans,n;
const int N=2e5+7;
int a[N],b[N];
bool cmp(int a, int b) {
	return a > b;
}
int main() {
	cin>>n>>x>>y;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(int i=1; i<=n; i++)
		cin>>b[i];
	sort(a+1,a+n+1,cmp);
	sort(b+1,b+n+1,cmp);
	ans=n;
	for(int i=1; i<=n; i++) {
		t+=a[i];
		if(t>x) {
			ans=i;
			break;
		}
	}
	t=0;
//	cout<<ans<<" "<<a[1]<<endl;
	for(int i=1; i<=n; i++) {
		t+=b[i];
		if(t>y) {
			ans=min(i,ans);
			break;
		}
		//cout<<ans<<" "<<t<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

7.成功实现信息显示在List上

但是还没有实现将数据保存在数据库中,预计下次总结实现数据库存储及其他功能。

创建类ChatBubble,用来显示头像,气泡之类的,这里创建改类的对象,调用类中的方法,实现如下操作。

气泡设置及添加节点到对象中:

 //聊天气泡,本人为深绿色,非本人为浅绿色
      //  Rectangle bubble = new Rectangle(40.0, 20.0, (double) this.totalLength * 1.2, 30.0);xxx
        //矩形的宽度,矩形的高度,矩形四个角的弧度宽度,矩形四个角的弧度高度
        Rectangle bubble = new Rectangle(40.0, 20.0, (double) this.totalLength * 1, 30);
        bubble.setArcWidth(10.0);
        bubble.setArcHeight(10.0);
        bubble.setFill(isSentByMe ? Color.LIGHTGREEN : Color.LIGHTGRAY);//颜色
        //设置消息内容的文本布局
        TextFlow messageFlow = new TextFlow();
        messageFlow.setLayoutX(40.0);
        messageFlow.setLayoutY(28.0);
        messageFlow.setPrefWidth(100.0);
        messageFlow.setLineSpacing(5.0);
        this.processMessage(message, messageFlow, bubble);//2
        //将当前节点添加到对象中
        this.getChildren().addAll(new Node[]{head, label, label1, bubble, messageFlow});

效果如下:

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
电子邮件解密算法可以使用公钥密和私钥解密的方式实现。下面是一个使用RSA算法进行解密的C++示例项目: 1. 首先,生成一对公私钥。这里使用openssl库生成: ``` openssl genpkey -algorithm RSA -out private_key.pem -aes256 openssl rsa -in private_key.pem -outform PEM -pubout -out public_key.pem ``` 2. 在C++代码中使用openssl库进行解密。需要使用openssl中的RSA库和EVP库。 ```c++ #include <openssl/rsa.h> #include <openssl/pem.h> #include <openssl/evp.h> // 密函数 std::string encrypt(const std::string& plaintext, const std::string& public_key_file) { // 读取公钥 FILE* key_file = fopen(public_key_file.c_str(), "r"); RSA* rsa = PEM_read_RSA_PUBKEY(key_file, NULL, NULL, NULL); fclose(key_file); // 获取公钥长度 int key_len = RSA_size(rsa); // 分配内存 unsigned char* ciphertext = new unsigned char[key_len]; // 密 int len = RSA_public_encrypt(plaintext.size(), (const unsigned char*)plaintext.c_str(), ciphertext, rsa, RSA_PKCS1_PADDING); // 转换为字符串 std::string result((const char*)ciphertext, len); // 清理内存 delete[] ciphertext; RSA_free(rsa); return result; } // 解密函数 std::string decrypt(const std::string& ciphertext, const std::string& private_key_file) { // 读取私钥 FILE* key_file = fopen(private_key_file.c_str(), "r"); RSA* rsa = PEM_read_RSAPrivateKey(key_file, NULL, NULL, NULL); fclose(key_file); // 获取私钥长度 int key_len = RSA_size(rsa); // 分配内存 unsigned char* plaintext = new unsigned char[key_len]; // 解密 int len = RSA_private_decrypt(ciphertext.size(), (const unsigned char*)ciphertext.c_str(), plaintext, rsa, RSA_PKCS1_PADDING); // 转换为字符串 std::string result((const char*)plaintext, len); // 清理内存 delete[] plaintext; RSA_free(rsa); return result; } ``` 3. 通过调用encrypt和decrypt函数,可以实现电子邮件解密: ```c++ // 密 std::string ciphertext = encrypt("Hello, world!", "public_key.pem"); // 解密 std::string plaintext = decrypt(ciphertext, "private_key.pem"); ``` 注意:在实际应用中,需要考虑安全性和性能等因素,例如密钥管理、防止重放攻击等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值