Greeting Card

本文探讨了一个复杂的绘图挑战,旨在通过精确计算点之间的距离来确定能够形成特定长度段的点对数量。利用整数坐标的特性,文章提出了一种高效的算法解决方案,避免了超时问题,确保了足够的墨水供应以完成新年贺卡的打印任务。

题目描述

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.

题意:

给出一组点,求其中两点之间距离为2018的数量。

题解:

刚开始用暴力写 但数据太大死在了超时上,因为点的坐标都为整数打表可以找到规律。只存在两种情况1.在同一直线上相距2018,二、分别相差1118和1680。用其中一个点根据关系遍历看该点在集合中是否存在,即可以找到所有满足的点。

#include<iostream>
#include<cstdio>
#include<set>
#include<utility>
typedef long long ll;

using namespace std;
const int maxn = 100000+2;
int n;
ll x,y;
ll ans;
int dx[]={2018,0,-2018,0,1118,1680,1680,-1118,-1680,1118,-1118,-1680};
int dy[]={0,2018,0,-2018,1680,1118,-1118,1680,1118,-1680,-1680,-1118};
ll X[maxn],Y[maxn];
int main()
{

    cin>>n;
    pair<ll,ll> p;
    set<pair<ll,ll> >st;
    for(int i = 0;i<n;i++){
        cin>>X[i]>>Y[i];
        p.first = X[i];
        p.second = Y[i];
        st.insert(p);
    }
    ans = 0;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<12;j++){
            p.first = X[i]+dx[j];
            p.second = Y[i]+dy[j];
            if(st.count(p))
                ans++;
        }
    }
    cout<<ans/2<<endl;
    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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值