Greeting Card

本文探讨了一项趣味挑战:使用高精度绘图仪绘制新年贺卡,通过精确坐标定位,连接距离为2018单位长度的点对,形成图案。文章详细介绍了算法思路与实现代码,展示了如何利用数学和编程解决这一问题。

题目描述

Quido plans to send a New Year greeting to his friend Hugo. He has recently acquired access to an advanced high-precision plotter and he is planning to print the greeting card on the plotter.
Here’s how the plotter operates. In step one, the plotter plots an intricate pattern of n dots on the paper. In step two, the picture in the greeting emerges when the plotter connects by a straight segment each pair of dots that are exactly 2 018 length units apart. 
The plotter uses a special holographic ink, which has a limited supply.Quido wants to know the number of all plotted segments in the picture to be sure that there is enough ink to complete the job.

 

输入

The first line of input contains a positive integer n specifying the number of plotted points. The following n lines each contain a pair of space-separated integer coordinates indicating one plotted point. Each coordinate is non-negative and less than 231. There are at most 105 points, all of them are distinct.
In this problem, all coordinates and distances are expressed in plotter length units, the length of the unit in the x-direction and in the y-direction is the same.

 

输出

The output contains a single integer equal to the number of pairs of points which are exactly 2018 length units apart.

 

样例输入

 

4
20180000 20180000
20180000 20182018
20182018 20180000
20182018 20182018

样例输出

4

题意:

题意很好理解,就是给你一些点,问你有多少对距离是2018的

思路其实很好想,看到给的点是整数,当时就想打表看看,有多少个 x^2 + y^2 = 2018*2018(x,y是两点的水平差和垂直差),结果一看就两个,加上垂直水平四个方向,一共有十二个点是可以和当前给出的点满足相距2018的。数组不好存,就用map+pair,每给出一个点就在关于他的这十二个点上加一,后面输入的点如果被标记过,那么它对应的map值就是有多少个点可以和他相距2018,最后把它们都加起来,就是结果了。

AC代码

#include<iostream>
#include<cstdio>     //EOF,NULL
#include<cstring>    //memset
#include<cstdlib>    //rand,srand,system,itoa(int),atoi(char[]),atof(),malloc
#include<cmath>           //ceil,floor,exp,log(e),log10(10),hypot(sqrt(x^2+y^2)),cbrt(sqrt(x^2+y^2+z^2))
#include<algorithm>  //fill,reverse,next_permutation,__gcd,
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<utility>
#include<iterator>
#include<iomanip>             //setw(set_min_width),setfill(char),setprecision(n),fixed,
#include<functional>
#include<map>
#include<set>
#include<limits.h>     //INT_MAX
#include<cmath> // bitset<?> n
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
const int INF =0x3f3f3f3f;
const int inf =0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn = 10010;

map<P,ll> m;
ll dir[12][2] = {2018,0,0,2018,-2018,0,0,-2018,1118,1680,-1118,1680,1118,-1680,-1118,-1680,1680,1118,1680,-1118,-1680,1118,-1680,-1118};

int main()
{
    
  // rep(i,1,2019)
  // {
  //   rep(j,1,2019)
  //   {
  //     if(i*i + j*j == 2018 * 2018)
  //     {
  //       printf("%d %d\n",i,j);
  //     }
  //   }
  // }
  int n;
  int t;
  sca(t);
  ll x,y;
  ll sum = 0;
  while(t--)
  {
    scanf("%lld%lld",&x,&y);
    sum += m[{x,y}];
    //printf("%d\n",m[{x,y}]);
    rep(i,0,12)
    {
      m[{x+dir[i][0],y+dir[i][1]}]++;
    }
  }
  printf("%lld\n",sum);
  
  return 0;
}

 

能读取到信息,但是只显示当天的,切换另一天打卡界面不显示,请修改 class HomeInterface(QWidget): def __init__(self, employee_id, name, department): super().__init__() self.setObjectName('homeInterface') self.employee_id = employee_id self.name = name self.department = department self.initUI() def initUI(self): # 主布局 - 网格布局 main_layout = QGridLayout(self) main_layout.setSpacing(20) main_layout.setContentsMargins(40, 30, 40, 30) # 1. 员工问候语区域 (顶部) greeting_card = self.create_greeting_card() main_layout.addWidget(greeting_card, 0, 0, 1, 4) # 占据第一行4列 # 2. 统计看板 (4个卡片) stats_cards = self.create_stats_cards() for i, card in enumerate(stats_cards): main_layout.addWidget(card, 1, i) # 第二行,每列一个卡片 # 3. 日历和打卡区域 (左右分栏) today = QDate.currentDate() calendar_card = self.create_calendar_card(today.year(),today.month()) attendance_card = self.create_attendance_card(today) # 创建左右分栏容器 bottom_container = QWidget() bottom_layout = QHBoxLayout(bottom_container) bottom_layout.setSpacing(20) bottom_layout.addWidget(calendar_card, 2) bottom_layout.addWidget(attendance_card, 1) # 打卡区域占2/3宽度 main_layout.addWidget(bottom_container, 2, 0, 1, 4) # 第三行,占据4列 self.setLayout(main_layout) def create_greeting_card(self) -> CardWidget: """创建问候语卡片""" card = CardWidget(self) card.setMinimumHeight(100) layout = QHBoxLayout(card) layout.setContentsMargins(30, 20, 30, 20) # 问候语文本 greeting_text = BodyLabel(f"早上好,{self.name}!祝您有愉快的一天!") greeting_text.setFont(QFont("Microsoft YaHei", 18, QFont.Bold)) # 打卡按钮 checkin_btn = PrimaryPushButton(text="返回登录界面") checkin_btn.clicked.connect(self.return_to_login) checkin_btn.setFixedSize(150, 40) layout.addWidget(greeting_text, 1) layout.addWidget(checkin_btn) return card def return_to_login(self): from ui_login import LoginWindow # 新增导入 self.login_window = LoginWindow() self.login_window.show() self.close() def create_stats_cards(self) -> List[widgets.CardWidget]: """创建4个统计看板卡片""" stats_data = [ {"title": "本月出勤", "value": f"{22}天"}, {"title": "考勤异常", "value": f"{5}次"}, {"title": "实际工时", "value": f"{3}小时"}, {"title": "期望工时", "value": f"{75}小时"} ] cards = [] for data in stats_data: card = CardWidget(self) card.setFixedHeight(120) layout = QVBoxLayout(card) layout.setContentsMargins(20, 15, 20, 15) # 标题 title = CaptionLabel(data["title"]) title.setStyleSheet("color: #666666;") # 主数值 value = BodyLabel(data["value"]) value.setFont(QFont("Microsoft YaHei", 20, QFont.Bold)) value.setStyleSheet("color: #28afe9; margin: 5px 0;") layout.addWidget(title) layout.addWidget(value) cards.append(card) return cards def create_calendar_card(self,year,month) -> CardWidget: """创建日历卡片""" card = CardWidget(self) card.setMinimumHeight(400) layout = QVBoxLayout(card) layout.setContentsMargins(20, 20, 20, 20) # 标题 title = BodyLabel("工作日历") title.setFont(QFont("Microsoft YaHei", 12, QFont.Bold)) calendar = HeatmapCalendar() calendar.setGridVisible(True) calendar.setMinimumDate(QDate.currentDate().addMonths(-3)) calendar.setMaximumDate(QDate.currentDate().addMonths(1)) calendar.setCurrentPage(QDate.currentDate().year(), QDate.currentDate().month()) calendar.clicked[QDate].connect(self.create_attendance_card) calendar.setStyleSheet(''' QCalendarWidget QWidget#qt_calendar_navigationbar { background-color: #E8E8E8; color: white; font-size: 20px; font-weight: bold; } QToolButton { color: balck; font-size: 18px; border: none; } QToolButton:hover { background-color: #81C784; } ''') # 标记今日日期 today_format = calendar.weekdayTextFormat(Qt.Saturday) today_format.setBackground(Qt.yellow) calendar.setDateTextFormat(QDate.currentDate(), today_format) month_str = f"{year}-{month:02d}" conn = sqlite3.connect('badge_records.db') cursor = conn.cursor() cursor.execute(''' SELECT date(datetime(timestamp, 'unixepoch', '+8 hours')), SUM(actual_work_hours), SUM(expected_work_hours) FROM records WHERE badge_id=? AND strftime('%Y-%m', datetime(timestamp, 'unixepoch', '+8 hours'))=? GROUP BY date(datetime(timestamp, 'unixepoch', '+8 hours')) ORDER BY date(datetime(timestamp, 'unixepoch', '+8 hours')) ''', (self.employee_id, month_str)) records = cursor.fetchall() conn.close() # 构建热力图数据 heatmap_data = {} for row, record in enumerate(records): date, actual, expected = record # 存入热力图数据 heatmap_data[date] = actual calendar.set_heat_data(heatmap_data) layout.addWidget(title) layout.addWidget(calendar) return card def create_attendance_card(self,date:QDate) -> CardWidget: """创建打卡记录卡片""" card = CardWidget(self) card.setMinimumHeight(400) date_str = date.toString("yyyy-MM-dd") print(f"查询日期{date_str}") layout = QVBoxLayout(card) layout.setContentsMargins(20, 20, 20, 20) # 标题栏 title = BodyLabel("今日打卡记录") title.setFont(QFont("Microsoft YaHei", 12, QFont.Bold)) # 打卡记录 records_container = QWidget() records_layout = QVBoxLayout(records_container) records_layout.setSpacing(10) # 添加记录 conn = sqlite3.connect('badge_records.db') cursor = conn.cursor() # 获取当日打卡记录 cursor.execute(''' SELECT strftime('%H:%M', datetime(timestamp, 'unixepoch', '+8 hours')), check_in_type, status, actual_work_hours FROM records WHERE badge_id=? AND date(datetime(timestamp, 'unixepoch', '+8 hours'))=? ORDER BY datetime(timestamp, 'unixepoch', '+8 hours') ''', (self.employee_id, date_str)) records = cursor.fetchall() conn.close() print(f"查询结果: {records}") # for row, record in enumerate(records): # time, check_in_type, status, hours=record # # 状态(翻译为中文) # status_map = { # "normal": "正常", # "late": "迟到", # "leave_early": "早退", # "no_morning_check": "未上班打卡" # } # status_text = status_map.get(record[2], record[2]) # # self.daily_table.setItem(row, 2, QTableWidgetItem(status_text)) # # 设置不同状态的颜色 # color = QColor(0, 0, 0) # 默认黑色 # if status_text == '迟到' or status_text == '早退': # color = QColor(255, 165, 0) # 橙色 # elif status_text == '缺勤': # color = QColor(255, 0, 0) # 红色 # record_widget = self.create_record_item(time, check_in_type, status_text,color) # records_layout.addWidget(record_widget) # layout.addWidget(title) # layout.addWidget(records_container) return self.create_attendance_card_content(date_str, records) def create_attendance_card_content(self, date_str, records): """创建打卡记录卡片内容""" card = CardWidget(self) layout = QVBoxLayout(card) # 标题 title = BodyLabel(f"{date_str} 打卡记录") layout.addWidget(title) # 无记录时的处理 if not records: no_data = BodyLabel("当日无打卡记录") layout.addWidget(no_data) return card # 有记录时的处理 records_container = QWidget() records_layout = QVBoxLayout(records_container) for record in records: time, check_in_type, status, hours = record record_widget = self.create_record_item(time, check_in_type, status) records_layout.addWidget(record_widget) layout.addWidget(records_container) return card def create_record_item(self, time: str, action: str, location: str) -> QWidget: """创建单个打卡记录项""" item = QWidget() layout = QHBoxLayout(item) layout.setContentsMargins(10, 8, 10, 8) # 时间标签 time_label = BodyLabel(time) time_label.setFixedWidth(60) time_label.setStyleSheet("font-weight: bold;") # 动作标签 action_label = BodyLabel(action) action_label.setStyleSheet("color: #333333;") # 位置标签 location_label = CaptionLabel(location) location_label.setStyleSheet("color: #666666;") layout.addWidget(time_label) layout.addWidget(action_label) layout.addStretch(1) layout.addWidget(location_label) # 添加样式 item.setStyleSheet(""" QWidget { background-color: #F5F5F5; border-radius: 6px; } """) return item
08-25
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>2025-2026跨年倒计时</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { background-color: #000; display: flex; justify-content: center; align-items: center; height: 100vh; overflow: hidden; } .countdown-container { width: 100vw; height: 100vw; /* 1:1 比例 */ max-width: 600px; max-height: 600px; position: relative; } .flip-clock { display: flex; justify-content: center; align-items: center; gap: 10px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2; } .flip-card { width: 80px; height: 120px; perspective: 1000px; } .flip-card-inner { position: relative; width: 100%; height: 100%; text-align: center; transition: transform 0.5s; transform-style: preserve-3d; } .flip-card-front, .flip-card-back { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; justify-content: center; align-items: center; font-size: 48px; font-weight: bold; color: #fff; background-color: #333; border-radius: 8px; } .flip-card-back { transform: rotateX(180deg); } .fireworks { position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 1; opacity: 0; transition: opacity 1s; } .greeting { position: absolute; top: 70%; left: 50%; transform: translate(-50%, -50%); z-index: 3; font-size: 32px; font-weight: bold; color: #fff; opacity: 0; transition: opacity 1s; } </style> </head> <body> <div class="countdown-container"> <div class="flip-clock" id="flipClock"> <div class="flip-card" id="cardHourTens"> <div class="flip-card-inner"> <div class="flip-card-front">2</div> <div class="flip-card-back">2</div> </div> </div> <div class="flip-card" id="cardHourOnes"> <div class="flip-card-inner"> <div class="flip-card-front">3</div> <div class="flip-card-back">3</div> </div> </div> <div class="flip-card" id="cardMinuteTens"> <div class="flip-card-inner"> <div class="flip-card-front">5</div> <div class="flip-card-back">5</div> </div> </div> <div class="flip-card" id="cardMinuteOnes"> <div class="flip-card-inner"> <div class="flip-card-front">9</div> <div class="flip-card-back">9</div> </div> </div> <div class="flip-card" id="cardSecondTens"> <div class="flip-card-inner"> <div class="flip-card-front">5</div> <div class="flip-card-back">5</div> </div> </div> <div class="flip-card" id="cardSecondOnes"> <div class="flip-card-inner"> <div class="flip-card-front">5</div> <div class="flip-card-back">5</div> </div> </div> </div> <div class="fireworks" id="fireworks"></div> <div class="greeting" id="greeting">Happy New Year</div> </div> <script> // 初始化时间:2025-12-31 23:59:55 let hours = 23; let minutes = 59; let seconds = 55; let isNewYear = false; // 获取翻页卡片元素 const cardHourTens = document.getElementById('cardHourTens').querySelector('.flip-card-inner'); const cardHourOnes = document.getElementById('cardHourOnes').querySelector('.flip-card-inner'); const cardMinuteTens = document.getElementById('cardMinuteTens').querySelector('.flip-card-inner'); const cardMinuteOnes = document.getElementById('cardMinuteOnes').querySelector('.flip-card-inner'); const cardSecondTens = document.getElementById('cardSecondTens').querySelector('.flip-card-inner'); const cardSecondOnes = document.getElementById('cardSecondOnes').querySelector('.flip-card-inner'); const fireworks = document.getElementById('fireworks'); const greeting = document.getElementById('greeting'); // 更新翻页卡片 function updateCard(card, digit) { const front = card.querySelector('.flip-card-front'); const back = card.querySelector('.flip-card-back'); if (front.textContent !== digit) { back.textContent = digit; card.style.transform = 'rotateX(180deg)'; setTimeout(() => { front.textContent = digit; card.style.transform = 'rotateX(0deg)'; }, 500); } } // 更新时间显示 function updateTime() { seconds++; if (seconds >= 60) { seconds = 0; minutes++; if (minutes >= 60) { minutes = 0; hours++; if (hours >= 24) { hours = 0; } } } // 处理跨年逻辑 if (hours === 0 && minutes === 0 && seconds === 0) { isNewYear = true; fireworks.style.opacity = 1; greeting.style.opacity = 1; // 初始化烟花效果(这里用简单的动画模拟,如需更逼真可引入烟花库) initFireworks(); } if (!isNewYear) { const hourTens = Math.floor(hours / 10); const hourOnes = hours % 10; const minuteTens = Math.floor(minutes / 10); const minuteOnes = minutes % 10; const secondTens = Math.floor(seconds / 10); const secondOnes = seconds % 10; updateCard(cardHourTens, hourTens); updateCard(cardHourOnes, hourOnes); updateCard(cardMinuteTens, minuteTens); updateCard(cardMinuteOnes, minuteOnes); updateCard(cardSecondTens, secondTens); updateCard(cardSecondOnes, secondOnes); } } // 初始化烟花效果(简单模拟) function initFireworks() { for (let i = 0; i < 20; i++) { createFirework(); } } function createFirework() { const firework = document.createElement('div'); firework.style.position = 'absolute'; firework.style.width = '5px'; firework.style.height = '5px'; firework.style.backgroundColor = `rgb(${Math.random() * 255}, ${Math.random() * 255}, ${Math.random() * 255})`; firework.style.borderRadius = '50%'; firework.style.left = `${Math.random() * 100}%`; firework.style.top = `${Math.random() * 100}%`; firework.style.animation = `firework ${Math.random() * 2 + 1}s linear forwards`; fireworks.appendChild(firework); setTimeout(() => { fireworks.removeChild(firework); if (isNewYear) { createFirework(); } }, (Math.random() * 2 + 1) * 1000); } // 定义烟花动画(通过样式插入) const style = document.createElement('style'); style.textContent = ` @keyframes firework { 0% { transform: scale(0); opacity: 1; } 100% { transform: scale(5); opacity: 0; } } `; document.head.appendChild(style); // 启动倒计时 setInterval(updateTime, 1000); </script> </body> </html>
01-01
内容概要:本文详细介绍了一种基于Simulink的表贴式永磁同步电机(SPMSM)有限控制集模型预测电流控制(FCS-MPCC)仿真系统。通过构建PMSM数学模型、坐标变换、MPC控制器、SVPWM调制等模块,实现了对电机定子电流的高精度跟踪控制,具备快速动态响应和低稳态误差的特点。文中提供了完整的仿真建模步骤、关键参数设置、核心MATLAB函数代码及仿真结果分析,涵盖转速、电流、转矩和三相电流波形,验证了MPC控制策略在动态性能、稳态精度和抗负载扰动方面的优越性,并提出了参数自整定、加权代价函数、模型预测转矩控制和弱磁扩速等优化方向。; 适合人群:自动化、电气工程及其相关专业本科生、研究生,以及从事电机控制算法研究与仿真的工程技术人员;具备一定的电机原理、自动控制理论和Simulink仿真基础者更佳; 使用场景及目标:①用于永磁同步电机模型预测控制的教学演示、课程设计或毕业设计项目;②作为电机先进控制算法(如MPC、MPTC)的仿真验证平台;③支撑科研中对控制性能优化(如动态响应、抗干扰能力)的研究需求; 阅读建议:建议读者结合Simulink环境动手搭建模型,深入理解各模块间的信号流向与控制逻辑,重点掌握预测模型构建、代价函数设计与开关状态选择机制,并可通过修改电机参数或控制策略进行拓展实验,以增强实践与创新能力。
根据原作 https://pan.quark.cn/s/23d6270309e5 的源码改编 湖北省黄石市2021年中考数学试卷所包含的知识点广泛涉及了中学数学的基础领域,涵盖了实数、科学记数法、分式方程、几何体的三视图、立体几何、概率统计以及代数方程等多个方面。 接下来将对每道试题所关联的知识点进行深入剖析:1. 实数与倒数的定义:该题目旨在检验学生对倒数概念的掌握程度,即一个数a的倒数表达为1/a,因此-7的倒数可表示为-1/7。 2. 科学记数法的运用:科学记数法是一种表示极大或极小数字的方法,其形式为a×10^n,其中1≤|a|<10,n为整数。 此题要求学生运用科学记数法表示一个天文单位的距离,将1.4960亿千米转换为1.4960×10^8千米。 3. 分式方程的求解方法:考察学生解决包含分母的方程的能力,题目要求找出满足方程3/(2x-1)=1的x值,需通过消除分母的方式转化为整式方程进行解答。 4. 三视图的辨认:该题目测试学生对于几何体三视图(主视图、左视图、俯视图)的认识,需要识别出具有两个相同视图而另一个不同的几何体。 5. 立体几何与表面积的计算:题目要求学生计算由直角三角形旋转形成的圆锥的表面积,要求学生对圆锥的底面积和侧面积公式有所了解并加以运用。 6. 统计学的基础概念:题目涉及众数、平均数、极差和中位数的定义,要求学生根据提供的数据信息选择恰当的统计量。 7. 方程的整数解求解:考察学生在实际问题中进行数学建模的能力,通过建立方程来计算在特定条件下帐篷的搭建方案数量。 8. 三角学的实际应用:题目通过在直角三角形中运用三角函数来求解特定线段的长度。 利用正弦定理求解AD的长度是解答该问题的关键。 9. 几何变换的应用:题目要求学生运用三角板的旋转来求解特定点的...
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值