King's Phone HDU - 5641(模拟)

本文介绍了一个手机图案解锁的有效性验证算法。该算法基于特定规则判断输入的图案密码是否有效,包括密码长度、不可重复经过同一节点及路径上的中间点不能被跳过等约束条件。

King's Phone

HDU - 5641
In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen.

The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as 1,2,3, the three points in the second line are labeled as 4,5,6, and the three points in the last line are labeled as 7,8,9。The password itself is a sequence, representing the points in chronological sequence, but you should follow the following rules:

- The password contains at least four points.


- Once a point has been passed through. It can't be passed through again.

- The middle point on the path can't be skipped, unless it has been passed through( 3427 is valid, but 3724 is invalid).

His password has a length for a positive integer k(1k9), the password sequence is s1,s2...sk(0si<INT_MAX)
, he wants to know whether the password is valid. Then the King throws the problem to you.
Input The first line contains a number&nbsp; T(0<T100000), the number of the testcases.

For each test case, there are only one line. the first first number&nbsp; k,represent the length of the password, then k numbers, separated by a space, representing the password sequence s1,s2...sk. Output Output exactly T lines. For each test case, print `valid` if the password is valid, otherwise print `invalid` Sample Input
3
4 1 3 6 2
4 6 2 1 3
4 8 1 6 7
Sample Output
invalid
valid
valid

hint:
For test case #1:The path $1\rightarrow 3$ skipped the middle point $2$, so it's invalid.

For test case #2:The path $1\rightarrow 3$ doesn't skipped the middle point $2$, because the point 2 has been through, so it's valid.

For test case #2:The path $8\rightarrow 1 \rightarrow 6 \rightarrow 7$ doesn't have any the middle point $2$, so it's valid.

主要是是搞懂题目意思

手机按键1 2 3

              4 5 6

              7 8 9

三个条件

1. 密码至少经过四个点。 2. 不能重复经过同一个点。 3. 路径上的中间点不能跳过,除非已经被经过

这里条件3的路径是指按键路径,比如一行123,这个路径如果有13,跳过了中间2,而2之前没出现过就算无效密码

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int vis[15];
int judge(int a,int b){
//    1 2 3
//    4 5 6
//    7 8 9
    if(a > b) swap(a,b);
    int c = b - a;//计算两个数的差
    if(c == 2 && (a == 1 || a == 4 || a == 7) && !vis[(a+b)/2]) return 0;//如果是每行,中间跳过了返回0
    if(c == 4 && a == 3 && !vis[(a+b)/2]) return 0;//如果是副对角线,中间跳过了返回0
    if((c == 6 || c == 8) && !vis[(a+b)/2]) return 0;//如果是每列,或者主对角线,中间跳过了,返回0
    return 1;
}
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        int k,i,j;
        int valid = 1;
        int password[15];
        memset(vis,0,sizeof(vis));
        scanf("%d",&k);
        for(i = 0; i < k; i++){
            scanf("%d",&password[i]);
            if(password[i] < 1 || password[i] > 9) valid = 0;
        }
        if(k < 4 || k > 9 || !valid){
            printf("invalid\n");
            continue;
        }
        vis[password[0]] = 1;
        for(i = 1; i < k; i++){
            vis[password[i]]++;
            if(!judge(password[i-1],password[i]) || vis[password[i]] > 1) valid = 0;
        }
        if(valid) printf("valid\n");
        else printf("invalid\n");
    }
    return 0;
}

跟网型逆变器小干扰稳定性分析与控制策略优化研究(Simulink仿真实现)内容概要:本文围绕跟网型逆变器的小干扰稳定性展开分析,重点研究其在电力系统中的动态响应特性及控制策略优化问题。通过构建基于Simulink的仿真模型,对逆变器在不同工况下的小信号稳定性进行建模与分析,识别系统可能存在的振荡风险,并提出相应的控制优化方法以提升系统稳定性和动态性能。研究内容涵盖数学建模、稳定性判据分析、控制器设计与参数优化,并结合仿真验证所提策略的有效性,为新能源并网系统的稳定运行提供理论支持和技术参考。; 适合人群:具备电力电子、自动控制或电力系统相关背景,熟悉Matlab/Simulink仿真工具,从事新能源并网、微电网或电力系统稳定性研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 分析跟网型逆变器在弱电网条件下的小干扰稳定性问题;② 设计并优化逆变器外环与内环控制器以提升系统阻尼特性;③ 利用Simulink搭建仿真模型验证理论分析与控制策略的有效性;④ 支持科研论文撰写、课题研究或工程项目中的稳定性评估与改进。; 阅读建议:建议读者结合文中提供的Simulink仿真模型,深入理解状态空间建模、特征值分析及控制器设计过程,重点关注控制参数变化对系统极点分布的影响,并通过动手仿真加深对小干扰稳定性机理的认识。
### 关于HDU - 6609 的题目解析 由于当前未提供具体关于 HDU - 6609 题目的详细描述,以下是基于一般算法竞赛题型可能涉及的内容进行推测和解答。 #### 可能的题目背景 假设该题目属于动态规划类问题(类似于多重背包问题),其核心在于优化资源分配或路径选择。此类问题通常会给出一组物品及其属性(如重量、价值等)以及约束条件(如容量限制)。目标是最优地选取某些物品使得满足特定的目标函数[^2]。 #### 动态转移方程设计 如果此题确实是一个变种的背包问题,则可以采用如下状态定义方法: 设 `dp[i][j]` 表示前 i 种物品,在某种条件下达到 j 值时的最大收益或者最小代价。对于每一种新加入考虑范围内的物体 k ,更新规则可能是这样的形式: ```python for i in range(n): for s in range(V, w[k]-1, -1): dp[s] = max(dp[s], dp[s-w[k]] + v[k]) ``` 这里需要注意边界情况处理以及初始化设置合理值来保证计算准确性。 另外还有一种可能性就是它涉及到组合数学方面知识或者是图论最短路等相关知识点。如果是后者的话那么就需要构建相应的邻接表表示图形结构并通过Dijkstra/Bellman-Ford/Floyd-Warshall等经典算法求解两点间距离等问题了[^4]。 最后按照输出格式要求打印结果字符串"Case #X: Y"[^3]。 #### 示例代码片段 下面展示了一个简单的伪代码框架用于解决上述提到类型的DP问题: ```python def solve(): t=int(input()) res=[] cas=1 while(t>0): n,k=list(map(int,input().split())) # Initialize your data structures here ans=find_min_unhappiness() # Implement function find_min_unhappiness() res.append(f'Case #{cas}: {round(ans)}') cas+=1 t-=1 print("\n".join(res)) solve() ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值