Giter Club home page Giter Club logo

response3's People

Contributors

qiaobaaa avatar

Watchers

 avatar

response3's Issues

intsant

#include
#include
#include
using namespace std;

string dbStr[1007];
int value[1007];
int len;
int idx;
int total;

int calculate(string str, int start, int end) {
int ans = 0;
int sign = 1;

for (register int i = start; i < end; i++)
{
    int tem = 0;
    if (str[i]=='+')
        sign = 1;
    if (str[i] == '-')
        sign = -1;
    if (str[i] >= '0' && str[i] <= '9')
    {
        tem = str[i] - '0';
        if (i + 1 < end && str[i + 1] >= '0' && str[i + 1] <= '9')
        {
            tem = tem * 10 + (str[i + 1] - '0');
            i++;
        }
    }
    if (i + 1 < end && str[i + 1] == '*')
    {
        int x = 0;
        i += 2;
        x = str[i] - '0';
        if (i + 1 < end && str[i + 1] >= '0' && str[i + 1] <= '9')
        {
            x = x * 10 + (str[i + 1] - '0');
            i++;
        }
        tem = tem * x;
    }
    ans += tem * sign;
}

return ans;

}

void init(int mLen, char mSubexp[])
{
len = mLen + 1;
idx = 0;
total = 0;
dbStr[idx] = mSubexp;
dbStr[idx] = '+' + dbStr[idx];
value[idx] = calculate(dbStr[idx], 0, len);
total += value[idx];
idx++;
}

int append(char mLink, char mSubexp[])
{
dbStr[idx] = mSubexp;
dbStr[idx] = mLink + dbStr[idx];
value[idx] = calculate(dbStr[idx], 0, len);
total += value[idx];
idx++;
return total;
}

int erase(int mFrom)
{
int r = mFrom / len;
int c = mFrom % len;

total -= value[r];
if (c != 0) {
    total -= value[r + 1];
    for (int i = c; i < len; i++) {
        dbStr[r][i] = dbStr[r + 1][i];
    }
    value[r] = calculate(dbStr[r], 0, len);
    total += value[r];
    r++;
}
for (int i = r; i < idx; i++) {
    dbStr[i] = dbStr[i + 1];
    value[i] = value[i + 1];
}
idx--;
return total;

}

int select(int mFrom, int mTo)
{
int ans = 0;
int sr = mFrom / len;
int sc = mFrom % len;
int er = mTo / len;
int ec = mTo % (len);

if (sr == er) {
    ans = calculate(dbStr[sr], sc, ec + 1);
    return ans;
}
ans += calculate(dbStr[sr], sc, len);
ans += calculate(dbStr[er], 0, ec + 1);
for (int x = sr + 1; x < er; x++) {
    ans += value[x];
}
return ans;

}

1225

//author: Liu Heng

#include <U8g2lib.h>
#include <Arduino_GFX_Library.h>
#include <Arduino.h>
#include <WiFi.h>
#include <stdio.h>
#include <FS.h>
#include <SD.h>
#include <SD_MMC.h>

#include "material.h"
#include "map.h"
#include "mota_bin.h"
#include "warrior.h"
#include "monster.h"

#define GFX_BL 48 // default backlight pin, you may replace DF_GFX_BL to actual backlight pin
const int yyy = 13;

Arduino_DataBus bus = new Arduino_ESP32SPI(41 / DC /, 10 / CS /, 12 / SCK /, 11 / MOSI /, GFX_NOT_DEFINED / MISO */);
Arduino_ST7789 gfx = new Arduino_ST7789(bus, 42 / RST /, 0 / rotation /, true / IPS */, 240, 320, 0, 0);
int rc;

/*
#define SDMMC_D2 33 // SDMMC Data2
#define SDMMC_D3 4 //34 // SDMMC Data3 / SPI CS
#define SDMMC_CMD 5 // SDMMC CMD / SPI MOSI
#define SDMMC_CLK 6 // SDMMC CLK / SPI SCK
#define SDMMC_D0 7 // SDMMC Data0 / SPI MISO
#define SDMMC_D1 38 // SDMMC Data1
*/

#define SDMMC_D2 16 // SDMMC Data2
#define SDMMC_D3 4 //34 // SDMMC Data3 / SPI CS
#define SDMMC_CMD 5 // SDMMC CMD / SPI MOSI
#define SDMMC_CLK 6 // SDMMC CLK / SPI SCK
#define SDMMC_D0 7 // SDMMC Data0 / SPI MISO
#define SDMMC_D1 15 // SDMMC Data1

int16_t h, xOffset, yOffset;

//所有游戏图片的像素指针

//商店
uint16_t *shop_m;
uint16_t *shop_l;
uint16_t *shop_r;

//@@@@@@@@@@ 敌人
//1
//初级卫兵
uint16_t *gate_keeper_c;
//绿史莱姆
uint16_t *green_slime;
//红史莱姆
uint16_t *red_slime;
//蝙蝠
uint16_t *bat;
//法师
uint16_t *priest;
//骷髅队长
uint16_t *skeleton_a;
//骷髅士兵
uint16_t *skeleton_b;
//骷髅人
uint16_t *skeleton_c;

//2
//大史莱姆
uint16_t *big_slime;
//大蝙蝠
uint16_t *big_bat;
//石头人
uint16_t *rock;
//高级法师
uint16_t *super_priest;
//吸血鬼
uint16_t *vampire;
//兽人武士
uint16_t *zombine_knight;
//兽人
uint16_t *zombine;

//3
//中级卫兵
uint16_t *gate_keeper_b;
//鬼战士
uint16_t *ghost_solider;
//骑士队长
uint16_t *gold_knight;
//骑士
uint16_t *knight;
//幽灵
uint16_t *slime_man;
//战士
uint16_t *solider;
//双手剑士
uint16_t *swords_man;

//5
//黑暗骑士
uint16_t *dark_knight;
//高级卫兵
uint16_t *gate_keeper_a;
//高级巫师
uint16_t *magician_a;
//初级巫师
uint16_t *magician_b;
//魔法警卫
uint16_t *magic_sergeant;
//史莱姆王
uint16_t *slime_lord;
//吸血蝙蝠
uint16_t *vampire_bat;

//dragon 龙
uint16_t *dragon_wn;
uint16_t *dragon_n;
uint16_t *dragon_en;

uint16_t *dragon_w;
uint16_t *dragon_m;
uint16_t *dragon_e;

uint16_t *dragon_ws;
uint16_t *dragon_s;
uint16_t *dragon_es;

//octopus 章鱼
uint16_t *octopus_wn;
uint16_t *octopus_n;
uint16_t *octopus_en;

uint16_t *octopus_w;
uint16_t *octopus_m;
uint16_t *octopus_e;

uint16_t *octopus_ws;
uint16_t *octopus_s;
uint16_t *octopus_es;

//大魔导师
uint16_t *great_magic_master;
//魔王
uint16_t *boss;

//.............. 特殊物品
//冰冻水晶
uint16_t *snow_crystal;
//幸运金币
uint16_t *lucky_gold;
//十字架
uint16_t *cross;
//传送道具
uint16_t *orbof_flying;
//屠龙匕首
uint16_t *dragon_slayer;
//向上飞行器
uint16_t *wings_to_flyup;
//向下飞行器
uint16_t *wings_to_flydown;
//中心对称飞行器
uint16_t *warp_staff;
//破墙镐
uint16_t *mattock;
//魔法钥匙
uint16_t *magic_key;
//炸药
uint16_t *bomb;

//............. npc
//公主
uint16_t *princess;
//指引者
uint16_t *oldman;
//小偷
uint16_t *thief;
//商人
uint16_t *merchant;

//.......... 剑的分类
//铁剑
uint16_t *iron_sword;
//神圣剑
uint16_t *sacred_sword;
//圣剑
uint16_t *holy_sword;
//骑士剑
uint16_t *knight_sword;
//银剑
uint16_t *silver_sword;

//......... 盾的分类
uint16_t *iron_shield;
uint16_t *sacred_shield;
uint16_t *holy_shield;
uint16_t *knight_shield;
uint16_t *silver_shield;

//............ 背景
//铁门 or 笼子
uint16_t *iron_gate;
//钢门 or 花门
uint16_t *steel_gate;
//熔岩
uint16_t *lava;
//星空
uint16_t *star;

uint16_t *road;
uint16_t *wall;

uint16_t *upstair;
uint16_t *downstair;

uint16_t *yellow_door;
uint16_t *red_door;
uint16_t *blue_door;

uint16_t *yellow_key;
uint16_t *red_key;
uint16_t *blue_key;

uint16_t *yellow_keyy;
uint16_t *red_keyy;
uint16_t *blue_keyy;

uint16_t *attack;
uint16_t *defend;
uint16_t *life;
uint16_t *gold;

//物品
uint16_t *red_crystal;
uint16_t *blue_crystal;
uint16_t *red_elixir;
uint16_t *blue_elixir;

//人物CRYSTAL
uint16_t *people_up;
uint16_t *people_down;
uint16_t *people_right;
uint16_t *people_left;

//enemy

uint16_t *background;
uint16_t *backgroundd;
//uint16_t * MOTA "/motaa.jpg"
//uint16_t * ZHUANGBEI "/zhuangbeii.jpg"
//uint16_t * III "/iii.jpg"

GFXfont *f = NULL;

Warrior w;

void logMemoryy() {
log_d("Used PSRAM: %d", ESP.getPsramSize());
}
void logMemory() {
log_d("Used PSRAM: %d", ESP.getPsramSize() - ESP.getFreePsram());
}

//void initpsarm(char *file, uint16_t *buffer);

void display_picture(int h, int w, uint16_t *data) {
for (int i = 0; i < 20; i++) {
gfx->draw16bitRGBBitmap(w, i + h, data + (i * 20), 20, 1);
}
}

void display_picture2(int h, int w, uint16_t *data) {
for (int i = 0; i < 20; i++) {
gfx->draw16bitRGBBitmap(w, i + h, data + (i * 10), 10, 1);
}
}

void findrole(int& prow, int& pcol)
{
for (prow = 1; prow <= NUM; prow++)
{
for (pcol = 1; pcol <= NUM; pcol++)
{
switch (mappp[w.getLevel()][prow][pcol])
{
case 16:
case 17:
case 18:
case 19: return;
}
}
}
}

void setup() {
Serial.begin(115200);
// Serial.setDebugOutput(true);
// while(!Serial);
Serial.println("PNG Image Viewer");

#ifdef GFX_EXTRA_PRE_INIT
GFX_EXTRA_PRE_INIT();
#endif

// Init Display
gfx->begin();

gfx->fillScreen(BLACK);
gfx->setUTF8Print(true);

#ifdef GFX_BL
pinMode(GFX_BL, OUTPUT);
//digitalWrite(GFX_BL, HIGH);
analogWrite(GFX_BL, 180);
#endif

// pinMode(SDMMC_D3 /* CS /, OUTPUT);
// digitalWrite(SDMMC_D3 /
CS */, HIGH);
//#if defined(SOC_SDMMC_USE_GPIO_MATRIX)
// SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0);
//#endif

#if defined(SOC_SDMMC_USE_GPIO_MATRIX)
SD_MMC.setPins(SDMMC_CLK, SDMMC_CMD, SDMMC_D0, SDMMC_D1, SDMMC_D2, SDMMC_D3);
#endif
if (!SD_MMC.begin("/root", true)) {
//if(!FFat.begin(true)){
Serial.println("FFat Mount Failed");
return;
} else {
if (psramInit()) {
Serial.printf("Total PSRAM: %d", ESP.getPsramSize());
Serial.println("\nPSRAM is correctly initialized");
}
}
//rc = png.open(PNG_FILENAME, myOpen, myClose, myRead, mySeek, PNGDraw);
}

void loop() {
logMemoryy();
//给所有的图片素材申请空间
shop_m = (uint16_t *)ps_malloc(800);
shop_l = (uint16_t *)ps_malloc(800);
shop_r = (uint16_t *)ps_malloc(800);
//@@@@@@@@@@@ 敌人
//1
gate_keeper_c = (uint16_t *)ps_malloc(800);
green_slime = (uint16_t *)ps_malloc(800);
red_slime = (uint16_t *)ps_malloc(800);
bat = (uint16_t *)ps_malloc(800);
priest = (uint16_t *)ps_malloc(800);
skeleton_a = (uint16_t *)ps_malloc(800);
skeleton_b = (uint16_t *)ps_malloc(800);
skeleton_c = (uint16_t *)ps_malloc(800);

//2
big_slime = (uint16_t *)ps_malloc(800);
big_bat = (uint16_t *)ps_malloc(800);
rock = (uint16_t *)ps_malloc(800);
super_priest = (uint16_t *)ps_malloc(800);
vampire = (uint16_t *)ps_malloc(800);
zombine_knight = (uint16_t *)ps_malloc(800);
zombine = (uint16_t *)ps_malloc(800);

//3
gate_keeper_b = (uint16_t *)ps_malloc(800);
ghost_solider = (uint16_t *)ps_malloc(800);
gold_knight = (uint16_t *)ps_malloc(800);
knight = (uint16_t *)ps_malloc(800);
slime_man = (uint16_t *)ps_malloc(800);
solider = (uint16_t *)ps_malloc(800);
swords_man = (uint16_t *)ps_malloc(800);

//5
dark_knight = (uint16_t *)ps_malloc(800);
gate_keeper_a = (uint16_t *)ps_malloc(800);
magician_a = (uint16_t *)ps_malloc(800);
magician_b = (uint16_t *)ps_malloc(800);
magic_sergeant = (uint16_t *)ps_malloc(800);
slime_lord = (uint16_t *)ps_malloc(800);
vampire_bat = (uint16_t *)ps_malloc(800);

//dragon 龙
dragon_wn = (uint16_t *)ps_malloc(800);
dragon_n = (uint16_t *)ps_malloc(800);
dragon_en = (uint16_t *)ps_malloc(800);

dragon_w = (uint16_t *)ps_malloc(800);
dragon_m = (uint16_t *)ps_malloc(800);
dragon_e = (uint16_t *)ps_malloc(800);

dragon_ws = (uint16_t *)ps_malloc(800);
dragon_s = (uint16_t *)ps_malloc(800);
dragon_es = (uint16_t *)ps_malloc(800);

//octopus 章鱼
octopus_wn = (uint16_t *)ps_malloc(800);
octopus_n = (uint16_t *)ps_malloc(800);
octopus_en = (uint16_t *)ps_malloc(800);

octopus_w = (uint16_t *)ps_malloc(800);
octopus_m = (uint16_t *)ps_malloc(800);
octopus_e = (uint16_t *)ps_malloc(800);

octopus_ws = (uint16_t *)ps_malloc(800);
octopus_s = (uint16_t *)ps_malloc(800);
octopus_es = (uint16_t *)ps_malloc(800);

//大魔导师
great_magic_master = (uint16_t *)ps_malloc(800);
//魔王
boss = (uint16_t *)ps_malloc(800);

//.............. 特殊物品
snow_crystal = (uint16_t *)ps_malloc(800);
//幸运金币
lucky_gold = (uint16_t *)ps_malloc(800);
//十字架
cross = (uint16_t *)ps_malloc(800);
//传送道具
orbof_flying = (uint16_t *)ps_malloc(800);
dragon_slayer = (uint16_t *)ps_malloc(800);
wings_to_flyup = (uint16_t *)ps_malloc(800);
wings_to_flydown = (uint16_t *)ps_malloc(800);
warp_staff = (uint16_t *)ps_malloc(800);
//破墙镐
mattock = (uint16_t *)ps_malloc(800);
magic_key = (uint16_t *)ps_malloc(800);
bomb = (uint16_t *)ps_malloc(800);

//............. npc
princess = (uint16_t *)ps_malloc(800);
oldman = (uint16_t *)ps_malloc(800);
thief = (uint16_t *)ps_malloc(800);
merchant = (uint16_t *)ps_malloc(800);

//.......... 剑的分类
iron_sword = (uint16_t *)ps_malloc(800);
//神圣剑
sacred_sword = (uint16_t *)ps_malloc(800);
//圣剑
holy_sword = (uint16_t *)ps_malloc(800);
knight_sword = (uint16_t *)ps_malloc(800);
silver_sword = (uint16_t *)ps_malloc(800);

//......... 盾的分类
iron_shield = (uint16_t *)ps_malloc(800);
sacred_shield = (uint16_t *)ps_malloc(800);
holy_shield = (uint16_t *)ps_malloc(800);
knight_shield = (uint16_t *)ps_malloc(800);
silver_shield = (uint16_t *)ps_malloc(800);

//............ 背景
//铁门 or 笼子
iron_gate = (uint16_t *)ps_malloc(800);
//钢门 or 花门
steel_gate = (uint16_t *)ps_malloc(800);
//熔岩
lava = (uint16_t *)ps_malloc(800);
star = (uint16_t *)ps_malloc(800);

road = (uint16_t *)ps_malloc(800);
wall = (uint16_t *)ps_malloc(800);

upstair = (uint16_t *)ps_malloc(800);
downstair = (uint16_t *)ps_malloc(800);

yellow_door = (uint16_t *)ps_malloc(800);
red_door = (uint16_t *)ps_malloc(800);
blue_door = (uint16_t *)ps_malloc(800);

yellow_key = (uint16_t *)ps_malloc(800);
red_key = (uint16_t *)ps_malloc(800);
blue_key = (uint16_t *)ps_malloc(800);

yellow_keyy = (uint16_t *)ps_malloc(800);
red_keyy = (uint16_t *)ps_malloc(800);
blue_keyy = (uint16_t *)ps_malloc(800);

attack = (uint16_t *)ps_malloc(800);
defend = (uint16_t *)ps_malloc(800);
life = (uint16_t *)ps_malloc(800);
gold = (uint16_t *)ps_malloc(800);

//物品
red_crystal = (uint16_t *)ps_malloc(800);
blue_crystal = (uint16_t *)ps_malloc(800);
red_elixir = (uint16_t *)ps_malloc(800);
blue_elixir = (uint16_t *)ps_malloc(800);

//人物
people_up = (uint16_t *)ps_malloc(800);
people_down = (uint16_t *)ps_malloc(800);
people_right = (uint16_t *)ps_malloc(800);
people_left = (uint16_t )ps_malloc(800);
//20
20
background = (uint16_t )ps_malloc(800);
//10
20
backgroundd = (uint16_t *)ps_malloc(800);

//buffer = (uint16_t *)heap_caps_malloc(80000, MALLOC_CAP_SPIRAM);
//Serial.printf("@@@@@@ %d %f\n", sizeof(uint16_t), sizeof(byte));
//big_bat = (uint16_t *)ps_malloc(400);
logMemory();

// loadpsarm(SHOP_M, shop_m);
//loadpsarm(SHOP_L,shop_l);
//loadpsarm(SHOP_R,shop_r);

/*
//@@@@@@@@@@ 敌人
//1
loadpsarm(gate_keeper_a,gate_keeper_c;
//绿史莱姆
uint16_t *green_slime;
//红史莱姆
uint16_t *red_slime;
//蝙蝠
uint16_t *bat;
//法师
uint16_t *priest;
//骷髅队长
uint16_t *skeleton_a;
//骷髅士兵
uint16_t *skeleton_b;
//骷髅人
uint16_t *skeleton_c;
*/
loadpsarm(SHOP_M, shop_m);
loadpsarm(SHOP_L, shop_l);
loadpsarm(SHOP_R, shop_r);

//1
loadpsarm(GATE_KEEPER_C, gate_keeper_c);
loadpsarm(GREEN_SLIME, green_slime);
loadpsarm(RED_SLIME, red_slime);
loadpsarm(BAT, bat);
loadpsarm(PRIEST, priest);
loadpsarm(SKELETON_A, skeleton_a);
loadpsarm(SKELETON_B, skeleton_b);
loadpsarm(SKELETON_C, skeleton_c);

//2
loadpsarm(BIG_SLIME, big_slime);
loadpsarm(BIG_BAT, big_bat);
loadpsarm(ROCK, rock);
loadpsarm(SUPER_PRIEST, super_priest);
loadpsarm(VAMPIRE, vampire);
loadpsarm(ZOMBINE, zombine);
loadpsarm(ZOMBINE_KNIGHT, zombine_knight);

//3
loadpsarm(GATE_KEEPER_B, gate_keeper_b);
loadpsarm(GHOST_SOLIDER, ghost_solider);
loadpsarm(GOLD_KNIGHT, gold_knight);
loadpsarm(KNIGHT, knight);
loadpsarm(SLIME_MAN, slime_man);
loadpsarm(SOLIDER, solider);
loadpsarm(SWORDS_MAN, swords_man);

//5
loadpsarm(DARK_KNIGHT, dark_knight);
loadpsarm(GATE_KEEPER_A, gate_keeper_a);

loadpsarm(MAGICIAN_A, magician_a);
loadpsarm(MAGICIAN_B, magician_b);

loadpsarm(MAGIC_SERGEANT, magic_sergeant);
loadpsarm(SLIME_LORD, slime_lord);
loadpsarm(VAMPIRE_BAT, vampire_bat);

//dragon

loadpsarm(DRAGON_WN, dragon_wn);
loadpsarm(DRAGON_N, dragon_n);
loadpsarm(DRAGON_EN, dragon_en);

loadpsarm(DRAGON_W, dragon_w);
loadpsarm(DRAGON_M, dragon_m);
loadpsarm(DRAGON_E, dragon_e);

loadpsarm(DRAGON_WS, dragon_ws);
loadpsarm(DRAGON_S, dragon_s);
loadpsarm(DRAGON_ES, dragon_es);

//octopus
loadpsarm(OCTOPUS_WN, octopus_wn);
loadpsarm(OCTOPUS_N, octopus_n);
loadpsarm(OCTOPUS_EN, octopus_en);

loadpsarm(OCTOPUS_W, octopus_w);
loadpsarm(OCTOPUS_M, octopus_m);
loadpsarm(OCTOPUS_E, octopus_e);

loadpsarm(OCTOPUS_WS, octopus_ws);
loadpsarm(OCTOPUS_S, octopus_s);
loadpsarm(OCTOPUS_ES, octopus_es);

//
loadpsarm(GREAT_MAGIC_MASTER, great_magic_master);
loadpsarm(BOSS, boss);

//.............. 特殊物品
//冰冻水晶
loadpsarm(SNOW_CRYSTAL, snow_crystal);
loadpsarm(LUCKY_GOLD, lucky_gold);
loadpsarm(CROSS, cross);
loadpsarm(ORBOFFLY, orbof_flying);
//屠龙匕首
loadpsarm(DRAGON_SLAYER, dragon_slayer);
//向上飞行器
loadpsarm(WINGS_TO_FLYUP, wings_to_flyup);
//向下飞行器
loadpsarm(WINGS_TO_FLYDOWN, wings_to_flydown);
//中心对称飞行器
loadpsarm(WARP_STAFF, warp_staff);
//破墙镐
loadpsarm(MATTOCK, mattock);
//魔法钥匙
loadpsarm(MAGIC_KEY, magic_key);
//炸药
loadpsarm(BOMB, bomb);

//............. npc
//公主
loadpsarm(PRINCESS, princess);
loadpsarm(OLDMAN, oldman);
loadpsarm(THIEF, thief);
loadpsarm(MERCHANT, merchant);

loadpsarm(IRON_SWORD, iron_sword);
loadpsarm(SACRED_SWORD, sacred_sword);
loadpsarm(HOLY_SWORD, holy_sword);
loadpsarm(KNIGHT_SWORD, knight_sword);
loadpsarm(SILVER_SWORD, silver_sword);

loadpsarm(IRON_SHIELD, iron_shield);
loadpsarm(SACRED_SHIELD, sacred_shield);
loadpsarm(HOLY_SHIELD, holy_shield);
loadpsarm(KNIGHT_SHIELD, knight_shield);
loadpsarm(SILVER_SHIELDD, silver_shield);

loadpsarm(IRONGATE, iron_gate);
loadpsarm(STEEL_GATE, steel_gate);
loadpsarm(LAVA, lava);
loadpsarm(STAR, star);

//
loadpsarm(ROAD, road);
loadpsarm(WALL, wall);

loadpsarm(UPSTAIR, upstair);
loadpsarm(DOWNSTAIR, downstair);

loadpsarm(YELLOWDOOR, yellow_door);
loadpsarm(REDDOOR, red_door);
loadpsarm(BLUEDOOR, blue_door);

loadpsarm(YELLOWKEY, yellow_key);
loadpsarm(REDKEY, red_key);
loadpsarm(BLUEKEY, blue_key);

loadpsarm(YELLOWKEYY, yellow_keyy);
loadpsarm(REDKEYY, red_keyy);
loadpsarm(BLUEKEYY, blue_keyy);

loadpsarm(ATTACK, attack);
loadpsarm(DEFEND, defend);
loadpsarm(LIFE, life);
loadpsarm(GOLD, gold);

//物品
loadpsarm(REDCRYSTAL, red_crystal);
loadpsarm(BLUECRYSTAL, blue_crystal);
loadpsarm(REDELIXIR, red_elixir);
loadpsarm(BLUEELIXIR, blue_elixir);

loadpsarm(PEOPLEUP, people_up);
loadpsarm(PEOPLEDOWN, people_down);
loadpsarm(PEOPLERIGHT, people_right);
loadpsarm(PEOPLELEFT, people_left);

loadpsarm(BACKGROUND, background);
loadpsarm(BACKGROUNDD, backgroundd);

//gfx->fillScreen(BLACK);
unsigned long start = millis();
//gfx->fillScreen(RED);
initfirstfloor();
information();
Serial.printf(" time used: %lu\n", millis() - start);
/*
gfx->fillScreen(BLACK);
for (int x = 0; x < 11; x += 20) {
for (int y = 0; y < 1; y += 20) {
display_picture(x, y, wall);
}
}
//for (int i=0;i<30;i++) {
// gfx->draw16bitRGBBitmap(30, i, buffer+(i*30), 30, 1);
// }
Serial.printf(" time used: %lu\n", millis() - start);
*/
delay(100000000);
}

void loadpsarm(char *file, uint16_t *buffer) {
File bmpFile = SD_MMC.open(file, "r");
if (!bmpFile || bmpFile.isDirectory()) {
Serial.println("ERROR: Failed to open file for reading");
} else {
byte lo, hi;
uint16_t tem;
if (strcmp(BACKGROUNDD, file) == 0) {
for (int y = 0; y < 20; y++) {
bmpFile.seek(4 + (y * 20)); //seek at start of line
for (int x = 0; x < 10; x++) {
lo = bmpFile.read();
hi = bmpFile.read();
tem = lo;
tem = tem << 8;
tem = tem | hi;
//Serial.printf(" %d %d %x %x %x\n", y, x, lo, hi, tem);
buffer[y * 10 + x] = tem;
}
}
} else {
for (int y = 0; y < 20; y++) {
bmpFile.seek(4 + (y * 40)); //seek at start of line
for (int x = 0; x < 20; x++) {
lo = bmpFile.read();
hi = bmpFile.read();
tem = lo;
tem = tem << 8;
tem = tem | hi;
//Serial.printf(" %d %d %x %x %x\n", y, x, lo, hi, tem);
buffer[y * 20 + x] = tem;
}
}
}
}
bmpFile.close();
}

void drawmap(int floor)
{
for (int x = 1; x < 12; x++) {
for (int y = 0; y < 13; y++) {
int tem = mappp[floor][x][y];
switch (tem) {
case 0:
if (y == 0) {
display_picture2((x - 1) * 20, y * 20, backgroundd);
}
else if (y == 12) {
display_picture2((x - 1) * 20, (y * 20) - 10, backgroundd);
}
else {
display_picture((x - 1) * 20, (y * 20) - 10, wall);
}
break;
case 1:
display_picture((x - 1) * 20, (y * 20) - 10, road);
break;
//暗墙
case 2:
display_picture((x - 1) * 20, (y * 20) - 10, wall);
break;
//隐形墙
case 3:
display_picture((x - 1) * 20, (y * 20) - 10, road);
break;
//岩浆
case 4:
display_picture((x - 1) * 20, (y * 20) - 10, lava);
break;
//虚空
case 5:
display_picture((x - 1) * 20, (y * 20) - 10, star);
break;
case 6:
display_picture((x - 1) * 20, (y * 20) - 10, yellow_door);
break;
case 7:
display_picture((x - 1) * 20, (y * 20) - 10, blue_door);
break;
case 8:
display_picture((x - 1) * 20, (y * 20) - 10, red_door);
break;
case 9:
display_picture((x - 1) * 20, (y * 20) - 10, iron_gate);
break;
case 10:
display_picture((x - 1) * 20, (y * 20) - 10, steel_gate);
break;
case 11:
display_picture((x - 1) * 20, (y * 20) - 10, upstair);
break;
case 12:
display_picture((x - 1) * 20, (y * 20) - 10, downstair);
break;

    case 16:
      display_picture((x - 1) * 20, (y * 20) - 10, people_up);
      break;
    case 17:
      display_picture((x - 1) * 20, (y * 20) - 10, people_down);
      break;
    case 18:
      display_picture((x - 1) * 20, (y * 20) - 10, people_left);
      break;
    case 19:
      display_picture((x - 1) * 20, (y * 20) - 10, people_right);
      break;

    case 21:
      display_picture((x - 1) * 20, (y * 20) - 10, yellow_key);
      break;
    case 22:
      display_picture((x - 1) * 20, (y * 20) - 10, blue_key);
    case 23:
      display_picture((x - 1) * 20, (y * 20) - 10, red_key);
      break;

    case 24:
      display_picture((x - 1) * 20, (y * 20) - 10, red_crystal);
      break;
    case 25:
      display_picture((x - 1) * 20, (y * 20) - 10, blue_crystal);
      break;
    case 26:
      display_picture((x - 1) * 20, (y * 20) - 10, red_elixir);
      break;
    case 27:
      display_picture((x - 1) * 20, (y * 20) - 10, blue_elixir);
      break;

    case 31:
      display_picture((x - 1) * 20, (y * 20) - 10, iron_sword);
      break;
    case 32:
      display_picture((x - 1) * 20, (y * 20) - 10, iron_shield);
      break;
    case 33:
      display_picture((x - 1) * 20, (y * 20) - 10, silver_sword);
      break;
    case 34:
      display_picture((x - 1) * 20, (y * 20) - 10, silver_shield);
      break;
    case 35:
      display_picture((x - 1) * 20, (y * 20) - 10, knight_sword);
      break;
    case 36:
      display_picture((x - 1) * 20, (y * 20) - 10, knight_shield);
      break;
    case 37:
      display_picture((x - 1) * 20, (y * 20) - 10, sacred_sword);
      break;
    case 38:
      display_picture((x - 1) * 20, (y * 20) - 10, sacred_shield);
      break;
    case 39:
      display_picture((x - 1) * 20, (y * 20) - 10, holy_sword);
      break;
    case 40:
      display_picture((x - 1) * 20, (y * 20) - 10, holy_shield);
      break;

    case 41:
      display_picture((x - 1) * 20, (y * 20) - 10, orbof_flying);
      break;
    //notebook
    case 42:
      display_picture((x - 1) * 20, (y * 20) - 10, orbof_flying);
      break;
    case 43:
      display_picture((x - 1) * 20, (y * 20) - 10, cross);
      break;
    case 44:
      display_picture((x - 1) * 20, (y * 20) - 10, mattock);
      break;
    case 45:
      display_picture((x - 1) * 20, (y * 20) - 10, bomb);
      break;
    case 46:
      display_picture((x - 1) * 20, (y * 20) - 10, warp_staff);
      break;
    case 47:
      display_picture((x - 1) * 20, (y * 20) - 10, lucky_gold);
      break;
    case 48:
      display_picture((x - 1) * 20, (y * 20) - 10, snow_crystal);
      break;
    case 49:
      display_picture((x - 1) * 20, (y * 20) - 10, wings_to_flydown);
      break;
    case 50:
      display_picture((x - 1) * 20, (y * 20) - 10, wings_to_flyup);
      break;
    case 51:
      display_picture((x - 1) * 20, (y * 20) - 10, magic_key);
      break;
    case 52:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_slayer);
      break;

    case 92:
    case 93:
    case 94:
    case 95:
    case 96:
    case 97:
    case 98:
    case 99:
    case 100:
      display_picture((x - 1) * 20, (y * 20) - 10, thief);
      break;

    case 101:
    case 102:
    case 103:
    case 104:
    case 105:
    case 106:
    case 107:
    case 108:
    case 109:
    case 110:
    case 111:
    case 112:
    case 113:
    case 114:
    case 115:
    case 116:
    case 117:
    case 118:
    case 119:
    case 120:
      display_picture((x - 1) * 20, (y * 20) - 10, oldman);
      break;

    case 131:
    case 132:
    case 133:
    case 134:
    case 135:
    case 136:
    case 137:
    case 138:
    case 139:
    case 140:
    case 141:
    case 142:
      display_picture((x - 1) * 20, (y * 20) - 10, merchant);
      break;

    case 160:
      display_picture((x - 1) * 20, (y * 20) - 10, shop_l);
      break;
    case 161:
      display_picture((x - 1) * 20, (y * 20) - 10, shop_m);
      break;
    case 162:
      display_picture((x - 1) * 20, (y * 20) - 10, shop_r);
      break;
    case 163:
    case 164:
      display_picture((x - 1) * 20, (y * 20) - 10, princess);
      break;

    case 251:
      display_picture((x - 1) * 20, (y * 20) - 10, green_slime);
      break;
    case 252:
      display_picture((x - 1) * 20, (y * 20) - 10, red_slime);
      break;
    case 253:
      display_picture((x - 1) * 20, (y * 20) - 10, bat);
      break;
    case 254:
      display_picture((x - 1) * 20, (y * 20) - 10, priest);
      break;
    case 255:
      display_picture((x - 1) * 20, (y * 20) - 10, skeleton_c);
      break;
    case 256:
      display_picture((x - 1) * 20, (y * 20) - 10, skeleton_b);
      break;
    case 257:
      display_picture((x - 1) * 20, (y * 20) - 10, gate_keeper_c);
      break;
    case 258:
      display_picture((x - 1) * 20, (y * 20) - 10, skeleton_a);
      break;
    case 259:
      display_picture((x - 1) * 20, (y * 20) - 10, big_slime);
      break;
    case 260:
      display_picture((x - 1) * 20, (y * 20) - 10, big_bat);
      break;
    case 261:
      display_picture((x - 1) * 20, (y * 20) - 10, super_priest);
      break;
    case 262:
      display_picture((x - 1) * 20, (y * 20) - 10, zombine);
      break;
    case 263:
      display_picture((x - 1) * 20, (y * 20) - 10, zombine_knight);
      break;
    case 264:
      display_picture((x - 1) * 20, (y * 20) - 10, rock);
      break;
    case 265:
      display_picture((x - 1) * 20, (y * 20) - 10, vampire);
      break;
    case 266:
      display_picture((x - 1) * 20, (y * 20) - 10, ghost_solider);
      break;
    case 267:
      display_picture((x - 1) * 20, (y * 20) - 10, solider);
      break;
    case 268:
      display_picture((x - 1) * 20, (y * 20) - 10, slime_man);
      break;
    case 269:
      display_picture((x - 1) * 20, (y * 20) - 10, gate_keeper_b);
      break;
    case 270:
      display_picture((x - 1) * 20, (y * 20) - 10, swords_man);
      break;
    case 271:
      display_picture((x - 1) * 20, (y * 20) - 10, knight);
      break;
    case 272:
      display_picture((x - 1) * 20, (y * 20) - 10, gold_knight);
      break;
    case 282:
      display_picture((x - 1) * 20, (y * 20) - 10, great_magic_master);
      break;
    case 280:
    case 281:
    case 283:
      display_picture((x - 1) * 20, (y * 20) - 10, boss);
      break;
    case 284:
      display_picture((x - 1) * 20, (y * 20) - 10, octopus_wn);
      break;
    case 285:
      display_picture((x - 1) * 20, (y * 20) - 10, octopus_n);
      break;
    case 286:
      display_picture((x - 1) * 20, (y * 20) - 10, octopus_en);
      break;
    case 287:
      display_picture((x - 1) * 20, (y * 20) - 10, octopus_w);
      break;
    case 288:
      display_picture((x - 1) * 20, (y * 20) - 10, octopus_m);
      break;
    case 289:
      display_picture((x - 1) * 20, (y * 20) - 10, octopus_e);
      break;
    case 290:
      display_picture((x - 1) * 20, (y * 20) - 10, octopus_ws);
      break;
    case 291:
      display_picture((x - 1) * 20, (y * 20) - 10, octopus_s);
      break;
    case 292:
      display_picture((x - 1) * 20, (y * 20) - 10, octopus_es);
      break;
    case 293:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_wn);
      break;//魔龙左上
    case 294:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_n);
      break;//中上
    case 295:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_en);
      break;//右上
    case 296:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_w);
      break;
    case 297:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_m);
      break;
    case 298:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_e);
      break;
    case 299:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_ws);
      break;
    case 300:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_s);
      break;
    case 301:
      display_picture((x - 1) * 20, (y * 20) - 10, dragon_es);
      break;
    case 302:
      display_picture((x - 1) * 20, (y * 20) - 10, magician_b);
      break;
    case 303:
      display_picture((x - 1) * 20, (y * 20) - 10, magician_a);
      break;//高级巫师
    case 304:
      display_picture((x - 1) * 20, (y * 20) - 10, slime_lord);
      break;
    case 305:
      display_picture((x - 1) * 20, (y * 20) - 10, vampire_bat);
      break;//吸血蝙蝠
    case 306:
      display_picture((x - 1) * 20, (y * 20) - 10, dark_knight);
      break;//黑暗骑士
    case 307:
      display_picture((x - 1) * 20, (y * 20) - 10, magic_sergeant);
      break;//魔法警卫
    case 308:
      display_picture((x - 1) * 20, (y * 20) - 10, gate_keeper_a);
      break;//高级卫兵
  }
}

}
}

void initfirstfloor() {

for (int x = 1; x < 12; x++) {
for (int y = 0; y < 13; y++) {
int tem = mappp[1][x][y];
switch (tem) {
case 0:
if (y == 0) {
display_picture2((x - 1) * 20, y * 20, backgroundd);
} else if (y == 12) {
display_picture2((x - 1) * 20, (y * 20) - 10, backgroundd);
} else {
display_picture((x - 1) * 20, (y * 20) - 10, wall);
}
break;
case 1:
display_picture((x - 1) * 20, (y * 20) - 10, road);
break;
case 6:
display_picture((x - 1) * 20, (y * 20) - 10, yellow_door);
break;
case 8:
display_picture((x - 1) * 20, (y * 20) - 10, red_door);
break;
case 11:
display_picture((x - 1) * 20, (y * 20) - 10, upstair);
break;
case 17:
display_picture((x - 1) * 20, (y * 20) - 10, people_down);
break;
case 21:
display_picture((x - 1) * 20, (y * 20) - 10, yellow_key);
break;
case 22:
display_picture((x - 1) * 20, (y * 20) - 10, blue_key);
case 23:
display_picture((x - 1) * 20, (y * 20) - 10, red_key);
break;
case 24:
display_picture((x - 1) * 20, (y * 20) - 10, red_crystal);
break;
case 25:
display_picture((x - 1) * 20, (y * 20) - 10, blue_crystal);
break;
case 26:
display_picture((x - 1) * 20, (y * 20) - 10, red_elixir);
break;
case 27:
display_picture((x - 1) * 20, (y * 20) - 10, blue_elixir);
break;
case 41:
display_picture((x - 1) * 20, (y * 20) - 10, orbof_flying);
break;
case 251:
display_picture((x - 1) * 20, (y * 20) - 10, green_slime);
break;
case 252:
display_picture((x - 1) * 20, (y * 20) - 10, red_slime);
break;
case 253:
display_picture((x - 1) * 20, (y * 20) - 10, bat);
break;
case 254:
display_picture((x - 1) * 20, (y * 20) - 10, priest);
break;
case 255:
display_picture((x - 1) * 20, (y * 20) - 10, skeleton_c);
break;
case 256:
display_picture((x - 1) * 20, (y * 20) - 10, skeleton_b);
break;
}
}
}
}

void information() {

for (int x = 0; x < 240; x += 20) {
display_picture(220, x, background);
}
for (int x = 0; x < 130; x += 20) {
display_picture(280, x, background);
}
display_picture(240, 0, life);
display_picture(240, 70, gold);
display_picture(260, 0, attack);
display_picture(260, 70, defend);

display_picture(240, 135, yellow_keyy);
display_picture(260, 135, blue_keyy);
display_picture(280, 135, red_keyy);

displaymota();
displayzhuangbei();
}

void displaymota()
{
gfx->setFont(u8g2_font_unifont_t_chinese);
gfx->setTextColor(WHITE);
gfx->setCursor(188, 265);
gfx->println("魔 塔");
gfx->setCursor(183, 290);
gfx->println("第 层");
//displayfloor();
gfx->setFont(f);
}

void displayzhuangbei()
{
gfx->setFont(u8g2_font_unifont_t_chinese);
gfx->setTextColor(WHITE);
gfx->setCursor(0, 315);
gfx->println("装备");
gfx->setFont(f);
}

xy

#include<unordered_map>
#include
using namespace std;

int term = 10000;
unordered_map<int, int>all[10001];
unordered_map<string, int>no;
int num;

void init()
{
num = 0;
no.clear();
}

void assign(char mName[], char mPolynomial[])
{
no[mName] = num;
all[num].clear();
register int x = 0, y = 0, c = 1, sign = 1;
for (register int i = 0; mPolynomial[i] != '\0';)
{
if ('0' <= mPolynomial[i]&&mPolynomial[i]<='9')
{
c = mPolynomial[i] - '0';
i++;
}
if (mPolynomial[i]=='X')
{
i++;
x++;
if (mPolynomial[i]=='^')
{
x = mPolynomial[++i] - '0';
i++;
}
}
if (mPolynomial[i] == 'Y')
{
i++;
y++;
if (mPolynomial[i] == '^')
{
y = mPolynomial[++i] - '0';
i++;
}
}
if (mPolynomial[i] == '+' || mPolynomial[i] == '-')
{
all[num][x * 1000 + y] += sign * c;
if (mPolynomial[i]=='+')
{
sign = 1;
}
else
{
sign = -1;
}
x = 0, y = 0, c = 1;
i++;
}
}
all[num][x * 1000 + y] += sign * c;
num++;
}

void compute(char mNameR[], char mNameA[], char mNameB[], int mOp)
{
no[mNameR] = num;
all[num].clear();
int ida = no[mNameA];
int idb = no[mNameB];
if (mOp < 2)
{
for (auto i = all[ida].begin(); i != all[ida].end(); i++)
{
all[num][i->first] += i->second;
}
for (auto i = all[idb].begin(); i != all[idb].end(); i++)
{
all[num][i->first] += !mOp ? i->second : -i->second;
}
}
else
{
register int xa, xb, xc, ya, yb, yc;
for (auto i = all[ida].begin(); i != all[ida].end(); i++)
{
xa = i->first / 1000, xb = i->first % 1000, xc = i->second;
for (auto j = all[idb].begin(); j != all[idb].end(); j++)
{
ya = j->first / 1000, yb = j->first % 1000, yc = j->second;
all[num][(xa + ya) * 1000 + xb + yb] += (xc * yc) % term;
}
}
}
num++;
}

int getCoefficient(char mName[], int mDegreeX, int mDegreeY)
{
return (all[no[mName]][mDegreeX * 1000 + mDegreeY] + term) % term;
}

int getpow(int x, int y)
{
register int ans = 0;
if (!x||y)
{
ans = 1;
for (register int i = 0; i < x; i++)
{
ans = (ans * y) % term;
}
}
return ans;
}

int calcPolynomial(char mName[], int mX, int mY)
{
int id = no[mName];
register int x, y, c, X, Y, ans = 0;
for (auto i = all[id].begin(); i != all[id].end(); i++)
{
x = i->first / 1000;
y = i->first % 1000;
c = i->second;
X = getpow(x, mX);
Y = getpow(y, mY);
ans = (ans + ((long long int)X * Y * c)) % term;
}
return ans >= 0 ? ans : (ans + term);
}

werwerwe

using namespace std;
struct block {
int sc;
int len;
int ec;
int time;
int block[10000];
}B[1000];
int r, c;
int idx;
void init(int R, int C)
{
r = R;
c = C;
idx = 0;
}

int dropBlocks(int mTimestamp, int mCol, int mLen)
{
int total =0;
for (int i = idx - 1; i >= 0; i--) {
if (mTimestamp - B[i].time < r)
total += B[i].len;
}
B[idx].sc = mCol;
B[idx].ec = mCol + mLen;
B[idx].len = mLen;
B[idx].time = mTimestamp;
for (int i = mCol; i < mCol + mLen; i++)
B[idx].block[i] = 1;
total += mLen;
idx++;
return total;
}

int removeBlocks(int mTimestamp)
{
int total = 0;
int visit[10000] = { 0 };
for (int i = 0; i < idx; i++) {
if (mTimestamp - B[i].time < r) {
for (int j = B[i].sc; j < B[i].ec; j++) {
if (visit[j] == 0 && B[i].block[j] == 1) {
visit[j] = 1;
B[i].block[j] = 0;
B[i].len--;
}
}
total += B[i].len;
}
}
return total;
}

Producing Machines

#include<unordered_map>
#include
#include

#define MAX_NUM 25000

using namespace std;

struct machines
{
int id;
int time;
}machines[MAX_NUM];

unordered_map<int, int>umap;
vectorcall;

int index;

struct cmp
{
bool operator()(int a,int b)const {
if (machines[a].time!=machines[b].time)
{
return machines[a].time > machines[b].time;
}
else
{
return machines[a].id > machines[b].id;
}
}
};

set<int, cmp>sset;

void regist(int id,int time) {
index++;
umap[id] = index;
machines[index].id = id;
machines[index].time = time;
sset.insert(index);
}

void init(int N, int mId[], int mTime[]) {
umap.clear();
sset.clear();
index = 0;
for (int i = 0; i < N; i++)
{
regist(mId[i], mTime[i]);
}
return;
}

int add(int mId, int mTime) {
if (umap.find(mId)==umap.end())
{
regist(mId, mTime);
}
else
{
sset.erase(umap[mId]);
machines[umap[mId]].time = mTime;
sset.insert(umap[mId]);
}
return sset.size();
}

int remove(int K) {
for (int i = 0; i < K; i++)
{
int id = machines[*sset.begin()].id;
umap.erase(id);

    sset.erase(sset.begin());
}
return machines[*sset.begin()].id;

}
int binary(int l,int h ,int m) {
call.clear();
int low = l;
int high = h;
int mid;
int i = 0;
int temp;

int count1=h;
for (auto it=sset.begin();it!=sset.end();it++)
{
    call.push_back(machines[*it].time);
    i++;
}
//二分法的核心过程了
while (low<=high) {
    temp = 0;
    mid = (low + high) >>1;
    for (int j = 0; j < i; j++)
    {
        temp = temp + (mid / call[j]);
    }
    if (temp>=m)
    {
        count1 = mid;
        high = mid - 1;
    }
    else
    {
        low = mid + 1;
    }

}
return count1;

}
int produce(int M) {
int count1 = 0;
auto it = sset.rbegin();
count1 = binary(0,M*(machines[*it].time),M);
return count1;
}

Morning Commute Radio

#include
using namespace std;
int prices[100000];
int n;
int bit[100000 + 1];
vectorroad[1001];
//分解
void add(int idx, int delta)
{
for (; idx < n; idx += idx & -idx) {
bit[idx] += delta;
}
}
//合并
int sum(int idx)
{
register int ret = 0;
for (; idx != 0; idx -= idx & -idx) {
ret += bit[idx];
}
return ret;
}

void init(int N, int M, int mType[], int mTime[])
{
for (int i = 0; i < M; i++)
road[i].clear();
n = N;
for (register int i = 1; i < N; i++)
bit[i] = 0;
for (register int i = 0; i < N - 1; i++) {
prices[i] = mTime[i];
add(i + 1, mTime[i]);
road[mType[i]].push_back(i);
}
}
void destroy()
{
}
void update(int mID, int mNewTime)
{
add(mID + 1, mNewTime - prices[mID]);
prices[mID] = mNewTime;
}

int updateByType(int mTypeID, int mRatio256)
{
register int ret = 0, newTime;
for (auto i = road[mTypeID].begin(); i != road[mTypeID].end(); i++)
{
newTime = (prices[*i] * mRatio256) >> 8;
update(*i, newTime);
ret += newTime;
}
return ret;
}

int calculate(int mA, int mB)
{
return mA > mB ? sum(mA) - sum(mB) : sum(mB) - sum(mA);
}

Umbrella Warehouse

#define nm 10500
#include
#include <unordered_map>
#include
#include
using namespace std;

vector Conn[nm];
int n;
int Sm[nm];
int Q[nm];
int Dis[nm];

void init(int N, int mParent[], int mDistance[], int mQuantity[])
{
n = N;
for (int i = 0; i < nm; i++) {
Conn[i].clear();
}
for (int i = 0; i < N; i++) {
Conn[i].push_back(mParent[i]);
if (mParent[i] != -1) {
Conn[mParent[i]].push_back(i);
}
Q[i] = mQuantity[i];
Dis[i] = mDistance[i];
}
for (int i = N - 1; i >= 0; i--) {
Sm[i] = mQuantity[i];
for (int j = 1; j < Conn[i].size(); j++) {
Sm[i] += Sm[Conn[i][j]];
}
}
}

int carry(int mFrom, int mTo, int mQuantity)
{
int a1 = mFrom, a2 = mTo;
int sm = 0;
vector A1; vector A2;
while (a1 != a2) {
if (a1 > a2) {
A1.push_back(a1);
sm += Dis[a1];
a1 = Conn[a1][0];
}
else {
A2.push_back(a2);
sm += Dis[a2];
a2 = Conn[a2][0];
}
}
for (auto i : A1) {
Sm[i] -= mQuantity;
}
for (auto i : A2) {
Sm[i] += mQuantity;
}
Q[mFrom] -= mQuantity;
Q[mTo] += mQuantity;
return sm * mQuantity;
}

int gather(int mID, int mQuantity)
{
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
vector notTake(nm, -1);
for (int i : Conn[mID]) {
if (i < 0) continue;
if (i < mID) pq.push({ Dis[mID],i });
else pq.push({ Dis[i], i });
notTake[i] = mID;
}
int totQ = mQuantity;
int ans = 0;
while (totQ != 0) {
int val = pq.top().second;
int prevDis = pq.top().first;
int quan = min(totQ, Q[val]);
totQ -= quan;
ans += carry(val, mID, quan);
pq.pop();
for (int i : Conn[val]) {
if (i != notTake[val] && i != -1) {
if (i < val) pq.push({ prevDis + Dis[val],i });
else pq.push({ prevDis + Dis[i],i });
notTake[i] = val;
}
}
}
return ans;
}

int sum(int mID)
{

return Sm[mID];

}

gene

import itertools
with open('work.txt', 'w') as w:
f=open('fast.txt', encoding='utf-8')
for i in f:
tem = "RepeatMasker -nolow -no_is -norna -engine ncbi -parallel 4 -lib /public/final.library /public/Lycoris.bp.p_ctg.fasta.cut/"+i+">/public/"+i+ ".log 2>>/public/"+i+".log2; echo This-Work-is-Completed!\n"
a = ""
for j in tem:
if j!='\n':
a = a + j
w.write(a + "\n")

Instant Calculator

#define MAXC 1001
#define MAXL 101

using namespace std;

char arr[MAXC][MAXL];
int eva[MAXC];
int idx, len;

int evaluate(int s, int l, int index) {
int opr = 1;
int res = 0;
for (int i = s; i <= l; i++) {
if (arr[index][i] == '+') opr = 1;
else if (arr[index][i] == '-') opr = -1;
else if (arr[index][i] >= '0' && arr[index][i] <= '9') {
int x = arr[index][i] - '0';
if (i + 1 <= l && arr[index][i + 1] >= '0' && arr[index][i + 1] <= '9') {
i++;
x = x * 10 + (arr[index][i] - '0');
}
if (i + 1 <= l && arr[index][i + 1] == '*') {
i += 2;
int y = arr[index][i] - '0';
if (i + 1 <= l && arr[index][i + 1] >= '0' && arr[index][i + 1] <= '9') {
i++;
y = y * 10 + (arr[index][i] - '0');
}
x = y;
}
res += (x
opr);
}
}
return res;
}

void init(int mLen, char mSubexp[])
{
idx = 0;
len = mLen;
arr[0][0] = '+';
for (int i = 0; i < mLen; i++) {
arr[0][i + 1] = mSubexp[i];
}
eva[0] = evaluate(0, len, 0);
idx++;
}

int append(char mLink, char mSubexp[])
{
arr[idx][0] = mLink;
for (int i = 1; i <= len; i++) {
arr[idx][i] = mSubexp[i - 1];
}
eva[idx] = eva[idx - 1] + evaluate(0, len, idx);
return eva[idx++];
}

int erase(int mFrom)
{
int r = mFrom / (len + 1);
int c = mFrom % (len + 1);
for (int i = c; i <= len; i++) {
arr[r][i] = arr[r + 1][i];
}
for (int i = r + 2; i < idx; i++) {
for (int j = 0; j <= len; j++) {
arr[i - 1][j] = arr[i][j];
}
}
idx--;
if (r == 0) {
eva[0] = evaluate(0, len, 0);
r++;
}
for (int i = r; i < idx; i++) {
eva[i] = eva[i - 1] + evaluate(0, len, i);
}
return eva[idx - 1];
}

int select(int mFrom, int mTo)
{
int r1 = mFrom / (len + 1);
int c1 = mFrom % (len + 1);
int r2 = mTo / (len + 1);
int c2 = mTo % (len + 1);
int ans = eva[r2 - 1] - eva[r1];
ans += evaluate(c1, len, r1) + evaluate(0, c2, r2);
return ans;
}

daily plan

  1. 完成热度信息排序
  2. 加上自锁机制
  3. 完成调试

News Notification

#include <unordered_map>
#include
using namespace std;

struct News{
bool valid;
int mnewid, sendtime, cid;
int map;
} pool[30011];

struct User
{
int que[30001], idx;

} user[501];

struct Channel
{
int userlist[501], n;
} channel[501];

unordered_map <int, int> hashnew;
unordered_map <int, int> hashuser;
unordered_map <int, int> hashchan;

int cntnew, cntuser, cntchan;

struct cmp{
bool operator ()(int i, int j) {
if(pool[i].sendtime != pool[j].sendtime) return pool[i].sendtime > pool[j].sendtime;
return pool[i].mnewid > pool[j].mnewid;
}

};
priority_queue <int, vector, cmp> heapTime;

int N, K;
void init(int nn, int kk){
N = nn; K = kk;
heapTime = priority_queue <int, vector, cmp>();
hashchan.clear();
hashuser.clear();
hashnew.clear();
cntchan = 0; cntnew = 0; cntuser = 0;

for(int i = 1; i <= N; i++)  user[i].idx = -1;
for(int i = 1; i <= K; i++) channel[i].n = 0;

}

void update(int mtime) {
while (!heapTime.empty() && pool[heapTime.top()].sendtime <= mtime) {
int nid = heapTime.top();
heapTime.pop();
if(pool[nid].valid == 1) {
int cid = pool[nid].cid;
for(int i = 0; i < channel[cid].n; i++) {
int uid = channel[cid].userlist[i];
user[uid].que[++user[uid].idx] = nid;
}
}
}
}

void registerUser(int mtime, int muid, int mnum, int mchan[]){
update(mtime);

int uid;
if(hashuser[muid] == 0) hashuser[muid] = ++cntuser;
uid = hashuser[muid];

for(int i = 0; i < mnum; i++) {
    int mchanid = mchan[i];
    int cid;
    if(hashchan[mchanid] == 0) hashchan[mchanid] = ++cntchan;
    cid = hashchan[mchanid];
    channel[cid].userlist[channel[cid].n++] = uid;
}

}

int offerNews(int mtime, int mnewid, int mdelay, int mchanid) {
int nid = ++cntnew;
hashnew[mnewid] = nid;
int cid;
if(hashchan[mchanid] == 0) hashchan[mchanid] = ++cntchan;
cid = hashchan[mchanid];

pool[nid].cid = cid;
pool[nid].mnewid = mnewid;
pool[nid].sendtime = mtime + mdelay;
pool[nid].valid = 1;

heapTime.push(nid);
return channel[cid].n;

}

void cancelNews(int mtime, int mnewid) {
if(hashnew[mnewid] == 0) return;

int nid = hashnew[mnewid];
if(pool[nid].valid == 0) return;

if(pool[nid].valid == 1) {
    pool[nid].valid = 0;
    return;
}

}

int checkUser(int mtime, int muid, int mretid[]){
int rescnt = 0;
int uid = hashuser[muid];
update(mtime);

for(int i = user[uid].idx; i >= 0; i--) {
    int nid = user[uid].que[i];
    if(pool[nid].valid == 0) continue;

    if(rescnt < 3) mretid[rescnt] = pool[nid].mnewid;
    rescnt++;
}
user[uid].idx = -1;
return rescnt;

}

hahhahh

struct Warrior
{
int Highlevel;
int Clevel;
int Hp;
int Attack;
int Defense;
int Money;
int Yellow_key;
int Blue_key;
int Red_key;
int Sword;
int Shield;
int Buycount;
int getLevel() { return Clevel; }
int getHp() { return Hp; }
int getAttack() { return Attack; }
int getDefend() { return Defense; }
int getMoney() { return Money; }
int getYellow_Key() { return Yellow_key; }
int getBlue_Key() { return Blue_key; }
int getRed_Key() { return Red_key; }
int getClevel() { return Clevel; }
int getSword() { return Sword; }
int getShield() { return Shield; }

void LevelUp() { Clevel++; }
void LevelDown() { Clevel--; }
void Raise_Hp(int hp) { Hp += hp; }
void Lose_Hp(int hp) { Hp -= hp; }
void Raise_Attack(int att) { Attack += att; }
void Raise_Defend(int def) { Defense += def; }
void Get_Money(int money) { Money += money; }
void Spend_Money(int money) { Money -= money; }
void Get_Yellow_Key() { Yellow_key++; }
void Get_Blue_Key() { Blue_key++; }
void Get_Red_Key() { Red_key++; }
void Spend_Yellow_Key() { Yellow_key--; }
void Spend_Blue_Key() { Blue_key--; }
void Spend_Red_Key() { Red_key--; }
void HighLevelUp() { Highlevel++; }
void SetSword(int s) { Sword = s; }
void SetShield(int s) { Shield = s; }
int getBuyCount() { return Buycount; }
void Buy() { Buycount++; }
// void setItems(vector<int> &a) { return ITEMS; }
//bool Fight(Monster m);	// 攻击怪物

};

struct Monster
{

};

Warrior w;

Managing Rectangles

#include
int timestamp;

struct Rectangle {
int mid, timestamp;
int sy, sx, ey, ex;
int h, w;
}rect[10001];

struct cmp { bool operator()( Rectangle * a, Rectangle * b) { return a->timestamp > b->timestamp; } };

std::set< Rectangle *, cmp> bucketimestampet[101][101];

void init(int N)
{
for (int i = 1; i <= 10000; i++) rect[i] = {};
for (int i = 0; i <= 100; i++)
for (int j = 0; j <= 100; j++)
bucketimestampet[i][j].clear();
}

void Erase(int sy, int ey, int sx, int ex, Rectangle * cur) {
for (int i = sy; i <= ey; i++)
for (int j = sx; j <= ex; j++)
bucketimestampet[i][j].erase(cur);
}

void addRect(int mID, int mY, int mX, int mHeight, int mWidth)
{
int sy = mY, sx = mX, ey = mY + mHeight - 1, ex = mX + mWidth - 1;
rect[mID] = { mID, ++timestamp, sy, sx, ey, ex, mHeight, mWidth };
for (int i = sy / 100; i <= ey / 100; i++)
for (int j = sx / 100; j <= ex / 100; j++)
bucketimestampet[i][j].insert(&rect[mID]);
}

int check(int mY, int mX)
{
for (auto cur : bucketimestampet[mY / 100][mX / 100]) {
if (cur->sy <= mY && cur->ey >= mY && cur->sx <= mX && cur->ex >= mX) return cur->mid;
}
return 0;
}

void selectAndMove(int y1, int x1, int y2, int x2)
{
int mID = check(y1, x1);
if (!mID) return;
Rectangle * cur = &rect[mID];
Erase(cur->sx / 100, cur->ey / 100, cur->sx / 100, cur->ex / 100, cur);
rect[mID] = { mID, cur->timestamp, y2, x2, y2 + cur->h - 1, x2 + cur->w - 1, cur->h, cur->w };
for (int i = cur->sy / 100; i <= cur->ey / 100; i++)
for (int j = cur->sx / 100; j <= cur->ex / 100; j++)
bucketimestampet[i][j].insert(cur);
}

int moveFront(int mID)
{
if (!rect[mID].mid || !rect[mID].timestamp) return 0;
int sx = rect[mID].sx, sy = rect[mID].sy, ex = rect[mID].ex, ey = rect[mID].ey;
Erase(sy / 100, ey / 100, sx / 100, ex / 100, &rect[mID]);
addRect(mID, sy, sx, rect[mID].h, rect[mID].w);

int r = 0, rid = 0;
for (int i = rect[mID].sy / 100; i <= rect[mID].ey / 100; i++)
    for (int j = rect[mID].sx / 100; j <= rect[mID].ex / 100; j++)
        for (auto cur : bucketimestampet[i][j]) {
            if (&rect[mID] == cur) continue;
            if (rect[mID].sx <= cur->ex && rect[mID].sy <= cur->ey && rect[mID].ex >= cur->sx && rect[mID].ey >= cur->sy) {
                if (r < cur->timestamp) {
                    r = cur->timestamp;
                    rid = cur->mid;
                }
            }
        }
return rid;

}

int selectAndErase(int mY, int mX)
{
int mID = check(mY, mX);
if (mID) {
Erase(rect[mID].sy / 100, rect[mID].ey / 100, rect[mID].sx / 100, rect[mID].ex / 100, &rect[mID]);
rect[mID].timestamp = 0;
}
return mID;
}

new

#include<unordered_map>
#include

#define MAX_NEWS 30001
#define MAX_USER 501

using namespace std;

struct NEW {
int newsId;
int mTime;
int channelId;
};

struct USER
{
int userid;
int newcnt;
int nlist[MAX_NEWS];
};

struct CHANNEL
{
int channelid;
int usercnt;
int userist[MAX_USER];
};

NEW newsList[MAX_NEWS];
USER userList[MAX_USER];
CHANNEL channelList[MAX_USER];

struct cmp {
bool operator()(int a, int b) {
if (newsList[a].mTime != newsList[b].mTime) {
return newsList[a].mTime > newsList[b].mTime;
}
else {
return newsList[a].newsId > newsList[b].newsId;
}
}
};

priority_queue<int, vector, cmp>pq;
//channel id,user id
unordered_map<int, int>channel;
//user id,newid
unordered_map<int, int>umap;

unordered_map<int, int>real;

int cnt;
int sum;
int channelnum;
void update(int mtime)
{
while (!pq.empty() && newsList[pq.top()].mTime <= mtime)
{
int id = pq.top();
pq.pop();
int channelid = newsList[id].channelId;
if (channelid == -1)
continue;
for (register int i=0;i<channelList[channelid].usercnt;i++)
{
int userindex = channelList[channelid].userist[i];
userList[userindex].nlist[userList[userindex].newcnt] = id;
userList[userindex].newcnt++;
}
}
}

void init(int N, int K)
{
cnt = 1;
sum = 1;
channelnum = 1;
pq = {};
channel.clear();
umap.clear();
real.clear();
}

int findchannel(int cid)
{
if (channel.count(cid))
return channel[cid];

channelList[channelnum].channelid = cid;
channelList[channelnum].usercnt = 0;
channel[cid] = channelnum;
channelnum++;
return channel[cid];

}

void registerUser(int mTime, int mUID, int mNum, int mChannelIDs[])
{
update(mTime);
if (umap.count(mUID) == 0)
{
umap[mUID] = sum;
userList[sum].userid = mUID;
userList[sum].newcnt = 0;
sum++;
}
int userid = umap[mUID];
for (register int i = 0; i < mNum; i++)
{
int channelIndex = findchannel(mChannelIDs[i]);
channelList[channelIndex].userist[channelList[channelIndex].usercnt++] = userid;
}
}

int offerNews(int mTime, int mNewsID, int mDelay, int mChannelID)
{
int channelIndex = findchannel(mChannelID);

newsList[cnt].channelId = channelIndex;
newsList[cnt].mTime = mTime + mDelay;
newsList[cnt].newsId = mNewsID;
pq.push(cnt);
umap[mNewsID] = cnt;
cnt++;

return channelList[channelIndex].usercnt;

}

void cancelNews(int mTime, int mNewsID)
{
register int id = umap[mNewsID];
newsList[id].channelId = -1;
}

int checkUser(int mTime, int mUID, int mRetIDs[])
{
update(mTime);
register int ans = 0;
int userid = umap[mUID];
for (register int i = userList[userid].newcnt - 1; i >= 0; i--)
{
int newid = userList[userid].nlist[i];
if (newsList[newid].channelId == -1)
continue;
if (ans < 3)
mRetIDs[ans] = newsList[newid].newsId;
ans++;
}
userList[userid].newcnt = 0;
return ans;
}

Phylogenetic Tree

#include <unordered_map>
#include
using namespace std;
#define MAXL (11)
#define SPC_MAX 50001

struct MyStruct
{
int parent;
int child_num[5];
}species[SPC_MAX];;

unordered_map<string, int> umap;
int cnt;

void init(char mRootSpecies[MAXL])
{
cnt = 1;
umap.clear();
for (int i = 0; i < SPC_MAX; i++) {
species[i].parent = -2;
for (int j = 0; j < 5; j++) {
species[i].child_num[j] = 0;
}
}
umap[mRootSpecies] = cnt;
species[cnt].parent = -1;
species[cnt].child_num[0] = 1;
cnt++;
}

void add(char mSpecies[MAXL], char mParentSpecies[MAXL])
{
umap[mSpecies] = cnt;
int pid = umap[mParentSpecies];
species[cnt].parent = pid;
species[cnt].child_num[0] = 1;
for (int i = 1; i < 5; i++) {
if (pid == -1) break;
species[pid].child_num[i]++;
pid = species[pid].parent;
}
cnt++;
}

int getDistance(char mSpecies1[MAXL], char mSpecies2[MAXL])
{
int idx1 = umap[mSpecies1];
int idx2 = umap[mSpecies2];
int count = 0;

while (idx1 != idx2) {
    if (idx1 > idx2) {
        idx1 = species[idx1].parent;
    }
    else {
        idx2 = species[idx2].parent;
    }
    count++;
}
return count;

}

int getCount(char mSpecies[MAXL], int mDistance)
{
int dst = mDistance;
int cur = umap[mSpecies];
int pid = species[cur].parent;
int count = species[cur].child_num[dst];
//不是根节点的处理情况,是根节点直接返回
while (dst > 0 && pid != -1) {
count += species[pid].child_num[dst - 1];
if (dst - 1 > 0) {
count -= species[cur].child_num[dst - 2];
}
dst--;
cur = pid;
pid = species[pid].parent;
}
return count;
}

swm341

            A1                        A2

VSYNC PB2_43 PB2_43
HSYNC PB3_42 PM8_57

TFT_DE PB4_pin31 PM11_pin54
LCDCLK PB5_pin40 PB5_pin40(?)

LCD_PWM PD9_76

LCD_CS 45
LCD_DAT 47
LCD_CLK 46

LCD_RST PD1_85 PD1_85(可控)

School Assignment

#include
#include
#include<unordered_map>
#include
#include
using namespace std;

int c, n;
struct MyStruct
{
vectorse;
int id;
int school;
int max_distance;
unordered_map<int, int>record;
}s[7501];

struct cmp
{
bool operator()(int a, int b)const {
if (s[a].max_distance != s[b].max_distance)
{
return s[a].max_distance > s[b].max_distance;
}
else
{
return s[a].id < s[b].id;
}
}
};

set<int, cmp>school[10];
set<int, cmp>all;
unordered_map<int, int>stu;
int sum;
pair<int, int>sss[10];

void init(int C, int N, int mX[], int mY[]) {
c = C;
n = N;
sum = 0;
stu.clear();
all.clear();
for (register int i = 0; i < N; i++)
{
school[i].clear();
sss[i] = make_pair(mX[i], mY[i]);
}

for (register int i = 0; i < 7501; i++)
{
    s[i].se.clear();
    s[i].record.clear();
}
return;

}

void arrange(int num)
{
for (auto i : s[num].se)
{
//按距离最近的开始遍历选择,如果还有空位置就可以直接加入
if (school[i].size() < c)
{
s[num].school = i;
school[i].emplace(num);
all.emplace(num);
return;
}
else
{
//人已经满了会产生3种情况;
// 1.跟最后的一名的距离都小于,把原来学校最小优先级的学生都挤不走,只能到下一轮
//2.跟最后的一名的距离相等,但是id却大于,到下一轮
//3. 跟最后的一名的距离相等,但是id却小于,把最后一名挤走
//4.比最后一名距离大,直接把最后一名挤走
int n = *school[i].rbegin();
if (s[n].max_distance == s[num].max_distance)
{
//3
if (s[n].id > s[num].id)
{
s[num].school = i;
school[i].emplace(num);
all.emplace(num);
all.erase(n);
school[i].erase(n);
//按照一层一层往下推,直到全安排好
arrange(n);
return;
}
}
else if (s[n].max_distance < s[num].max_distance)
{
//4
s[num].school = i;
school[i].emplace(num);
all.emplace(num);
all.erase(n);
school[i].erase(n);
//按照一层一层往下推,直到全安排好
arrange(n);
return;
}
}
}
}

int add(int mStudent, int mX, int mY) {
stu[mStudent] = sum;
vector<pair<int, int>>tem;
for (register int i = 0; i < n; i++)
{
int x = sss[i].first - mX < 0 ? mX - sss[i].first : sss[i].first - mX;
int y = sss[i].second - mY < 0 ? mY - sss[i].second : sss[i].second - mY;
tem.push_back(make_pair(x + y, i));
}
sort(tem.begin(), tem.end());
//该同学的最远距离
s[sum].max_distance = tem.rbegin()->first;
s[sum].id = mStudent;
//把该同学依次最近的学校给输入进来
int g = 1;
for (auto i : tem)
{
s[sum].se.push_back(i.second);
s[sum].record[i.second] = g;
g++;
}

for (auto i : tem)
{
    //按距离最近的开始遍历选择,如果还有空位置就可以直接加入
    if (school[i.second].size() < c)
    {
        s[sum].school = i.second;
        school[i.second].emplace(sum);
        all.emplace(sum);
        sum++;
        return i.second;
    }
    else
    {
        //人已经满了会产生3种情况;
        // 1.跟最后的一名的距离都小于,把原来学校最小优先级的学生都挤不走,只能到下一轮
        //2.跟最后的一名的距离相等,但是id却大于,到下一轮
        //3. 跟最后的一名的距离相等,但是id却小于,把最后一名挤走
        //4.比最后一名距离大,直接把最后一名挤走
        int num = *school[i.second].rbegin();
        if (s[num].max_distance == s[sum].max_distance) //tem.rbegin()->first)
        {
            //3
            if (s[num].id > mStudent)
            {
                s[sum].school = i.second;
                //添加新的

                school[i.second].erase(num);

                all.erase(num);

                all.emplace(sum);

                school[i.second].emplace(sum);
                //删除旧的
                //按照一层一层往下推,直到全安排好
                arrange(num);

                sum++;
                return i.second;
            }
        }
        else if (s[num].max_distance < s[sum].max_distance)
        {
            //4
            s[sum].school = i.second;
            //添加新的
            school[i.second].erase(num);

            all.erase(num);

            all.emplace(sum);

            school[i.second].emplace(sum);
            //删除旧的
            //school[i.second].erase(num);
            //按照一层一层往下推,直到全安排好
            arrange(num);
            sum++;
            return i.second;
        }

    }
}

}

void brrange(int result, int pos)
{
//不需要移动
if (school[s[result].school].size() < c)
{
//把原来的删除
school[s[result].school].erase(result);
//添加到新的位置

    s[result].school = pos;
    school[pos].emplace(result);
    return;

}
else
{
    //满了要移动,每次找出要移动的下一个点
    auto it = school[s[result].school].rbegin();
    int num1 = s[*it].id;
    num1 = stu[num1];

    int city = s[*it].school;

    auto it1 = all.find(result);
    it1++;

    school[s[result].school].erase(result);
    s[result].school = pos;
    school[pos].emplace(result);

    for (it1; it1 != all.end(); it1++)
    {
        //如果result的优先级是要比他现在的高,证明他就是要被移动的
        if (s[*it1].record[city] < s[*it1].record[s[*it1].school])
        {
            brrange(*it1, city);
            break;
        }
    }
}

}

int remove(int mStudent) {

int result = s[stu[mStudent]].school;
int num = stu[mStudent];
//stu.erase(mStudent);
//未满谁也不移动
if (school[result].size() < c)
{
    stu.erase(mStudent);
    school[result].erase(num);
    all.erase(num);
    return result;
}
//满了要移动,每次找出要移动的下一个点
auto it = school[result].rbegin();
int num1 = s[*it].id;
num1 = stu[num1];

auto it1 = all.find(num1);
it1++;

//删除原来的
stu.erase(mStudent);
school[result].erase(num);
all.erase(num);

for (it1; it1 != all.end(); it1++)
{
    //如果result的优先级是要比他现在的高,证明他就是要被移动的
    if (s[*it1].record[result] < s[*it1].record[s[*it1].school])
    {
        brrange(*it1, result);
        break;
    }
}
return result;

}

int status(int mSchool) {
return school[mSchool].size();
}

Producing Machines

#include
#include<unordered_map>
#include

using namespace std;

struct MyStruct
{
int id;
int time;
}machines[25000];
unordered_map<int, int>umap;
int index;
struct cmp
{
bool operator()(int a, int b)const {
if (machines[a].time!=machines[b].time)
{
return machines[a].time > machines[b].time;
}
else
{
return machines[a].id > machines[b].id;
}
}
};
set<int, cmp>sset;

void init(int N, int mId[], int mTime[]) {
sset.clear();
umap.clear();
index = 0;

for (int i = 0; i < N; i++)
{
    index++;
    machines[index].id = mId[i];
    machines[index].time = mTime[i];

    umap[mId[i]] = index;
    sset.emplace(index);
    //index++;
}

}

int add(int mId, int mTime) {
//找到
if (umap.count(mId))
{
//先删除后更新
int idx = umap[mId];
sset.erase(idx);
machines[idx].time = mTime;
sset.emplace(idx);
}
//没找到
else
{
index++;
machines[index].id = mId;
machines[index].time = mTime;
umap[mId] = index;
sset.emplace(index);
//index++;
}
return sset.size();
}

int remove(int K) {
for (int i = 0; i < K; i++)
{
//sset.erase(sset.begin());
//********************
umap.erase(machines[*sset.begin()].id);
sset.erase(sset.begin());
}
return machines[*sset.begin()].id;
}
//二分计算本题的核心所在

int binary(int l,int h,int M)
{
int low = l;
int high = h;
int middle, cnt;
vectorcall;
int ii=0;
//**************
cnt = h;
for (auto i = sset.begin(); i != sset.end(); i++)
{
call.push_back(machines[*i].time);
ii++;
}

while (low<=high)
{
    middle = (low + high) / 2;
    int tem = 0;
    for (int i = 0; i < ii; i++)
    {
        //**************
        tem = tem + (middle / call[i]);
    }
    if (tem>=M)
    {
        //*********************
        cnt = middle;
        high = middle - 1;
    }
    else
    {
        low = middle + 1;
    }
}
return cnt;

}
int produce(int M) {
int cnt = 0;
int mintime = machines[*sset.rbegin()].time;
cnt = binary(0, M * mintime, M);
return cnt;
}

2812

int num[13] = { 0 };
int b[4] = { 6,3,7,1 };
int t[4] = { 1,2,4,8 };
for (int x = 0; x < 4; x++)
{
if (x == 0 || x == 2)
{
for (int i = 0; i < 4; i++)
{
if ((b[x] & t[i]) != 0)
{
printf("第 %d 位为1 \n", i + 1);
num[j] = 1;
j++;
}
else
{
printf("第 %d 位为0 \n", i + 1);
num[j] = 0;
j++;
}
}
}
else if (x==1)
{
for (int i = 0; i < 3; i++)
{
if ((b[x] & t[i]) != 0)
{
printf("第 %d 位为1 \n", i + 1);
num[j] = 1;
j++;
}
else
{
printf("第 %d 位为0 \n", i + 1);
num[j] = 0;
j++;
}
}
}
else
{
for (int i = 0; i < 2; i++)
{
if ((b[x] & t[i]) != 0)
{
printf("第 %d 位为1 \n", i + 1);
num[j] = 1;
j++;
}
else
{
printf("第 %d 位为0 \n", i + 1);
num[j] = 0;
j++;
}
}
}
}

for (int i = 0; i < 13; i++)
{
	printf("...num 第几位 %d  为  %d\n", i, num[i]);
}

Announcement For Workers

#include
#include<unordered_map>
#include

using namespace std;

struct MyStruct
{
int start;
int end;
}pool[9000];

//start
set<pair<int, pair<int, int>>>sset1;

int numcnt;
unordered_map<int, int>umap;

void init() {
sset1.clear();
umap.clear();
numcnt = 0;
return;
}

int add(int mId, int mStart, int mEnd) {
if (umap.count(mId) == 1)
{
int index = umap[mId];
sset1.erase(make_pair(pool[index].start, make_pair(pool[index].end, index)));

    umap[mId] = numcnt;
    pool[numcnt].start = mStart;
    pool[numcnt].end = mEnd;
    sset1.emplace(make_pair(mStart, make_pair(mEnd, numcnt)));
    numcnt++;
    return umap.size();
}

umap[mId] = numcnt;
pool[numcnt].start = mStart;
pool[numcnt].end = mEnd;
sset1.emplace(make_pair(mStart, make_pair(mEnd, numcnt)));
numcnt++;
return umap.size();

}

int remove(int mId) {
if (umap.count(mId))
{
int index = umap[mId];
sset1.erase(make_pair(pool[index].start, make_pair(pool[index].end, index)));
umap.erase(mId);
return umap.size();
}
return umap.size();
}

struct cmd {
bool operator()(const pair<int, pair<int, int>> a, pair<int, pair<int, int>> b) const {
return a.second.first > b.second.first;
}
};

int announce(int mDuration, int M) {

int e;

priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, cmd> pq;

for (auto i : sset1) {
    e = i.first + mDuration - 1;
    pq.push(i);

    while (!pq.empty()) {
        if (pq.top().second.first < e)
        {
            pq.pop();
        }
        else
        {
            break;
        }
    }
    if (pq.size() >= M)
    {
        return i.first;
    }
}
return -1;

}

Seat Reservation

#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include
#include
#include
#include

using namespace std;

#define MAXID 50003
#define MAXN 2003

int N;
struct theater {
int id;
int arr[101];
int avalcount;
}tDB[MAXN + 1];

int mIDtotID[MAXID + 1];
int vis[101];
int tobemarked[101];
int curravalcount;
struct Result {
int id;
int num;
};

int dir[4] = { -1,1,-10,10 };

bool bfs(int start, int tID, int mID, int K) {

priority_queue<int, vector<int>, greater<int>>pq;
for (int i = 1; i <= 100; i++) {
    tobemarked[i] = 0;
}

int count = 0;
pq.push(start);
while (!pq.empty()) {
    int cur = pq.top();
    pq.pop();
    count++;

    tobemarked[cur] = 1;
    vis[cur] = 1;
    if (count == K)break;

    for (int j = 0; j < 4; j++) {
        if (cur % 10 == 0 && j == 1)
            continue;
        else if (cur % 10 == 1 && j == 0)
            continue;
        int newseatno = cur + dir[j];
        if (newseatno >= 1 && newseatno <= 100 && vis[newseatno] == 0 && tDB[tID].arr[newseatno] == 0 ) {
            pq.push(newseatno);
            vis[newseatno] = 1;
        }

    }

}

curravalcount -= count;
if (count == K) {
    for (int i = 1; i <= 100; i++) {
        if (tobemarked[i]) {
            tDB[tID].arr[i] = mID;
        }


    }
    return true;
}


return false;

}

void init(int N)
{
::N = N;
for (int i = 0; i <= MAXID; i++)mIDtotID[i] = 0;
for (int i = 1; i <= N; i++) {
tDB[i].id = i;
tDB[i].avalcount = 100;
for (int j = 1; j <= 100; j++) {
tDB[i].arr[j] = 0;
}
}

}

Result reserveSeats(int mID, int K)
{
Result res;
res.id = 0;
res.num = 0;

for (int i = 1; i <= N; i++) {
    curravalcount = tDB[i].avalcount;
    if (curravalcount >= K) {

        for (int j = 1; j <= 100; j++)vis[j] = 0;
        for (int j = 1; j <= 100; j++) {
            if (tDB[i].arr[j] == 0 && vis[j] == 0 && curravalcount >= K) {
                if (bfs(j, i, mID, K)) {
                    res.id = i;
                    res.num = j;
                    mIDtotID[mID] = i;
                    tDB[i].avalcount -= K;
                    return res;
                }
            }
        }

    }
}



return res;

}

Result cancelReservation(int mID)
{

Result res;
res.id = 0;
res.num = 0;
int tid = mIDtotID[mID];
res.id = tid;
int c = 0;
for (int i = 1; i <= 100; i++) {

    if (tDB[tid].arr[i] == mID) {
        res.num += i;
        tDB[tid].arr[i] = 0;
        c++;
    }
}
tDB[tid].avalcount += c;


return res;

}

Block Stacking Game

#include<string.h>
#include
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
#define MAXC 1000000

//利用线段树进行记录,经验表明开4倍空间不会越界,也没有超过256MB限制
int mSegTree[4 * MAXC], mMin[4 * MAXC], mMax[4 * MAXC];

struct Result
{
int top;
int count;
};

//整体思路利用线段树的特性去存储不同的值,并进行更新,整体查询复杂度在O(logN)

long long int mTotal;
int C;

void update(int idx, int sSt, int sEn, int qSt, int qEn, int mChange)
{
//lazy Propagation
//进行修改时,事实上并没有真的修改,是给区间打上一段标记,一旦查询时发现这个节点有标记,就把标记下推到它的两个子节点
if (mSegTree[idx] != 0)
{
register int val = mSegTree[idx];
mMin[idx] += val;
mMax[idx] += val;
mSegTree[idx] = 0;
if (sSt != sEn)
{
mSegTree[(idx << 1) + 1] += val;
mSegTree[(idx << 1) + 2] += val;
}
}
//区间无交集,进行剪枝操作
if (qEn < sSt || sEn<qSt || sSt>sEn)
return;
//从顶开始
if (sSt >= qSt && sEn <= qEn)
{
mMin[idx] += mChange;
mMax[idx] += mChange;
if (sSt != sEn)
{
mSegTree[(idx << 1) + 1] += mChange;
mSegTree[(idx << 1) + 2] += mChange;
}
return;
}
register int mid = (sSt + sEn) >> 1;
//mid则为中间点,左儿子的结点区间为[sSt,mid],右儿子的结点区间为[mid,sEn]
update((idx << 1) + 1, sSt, mid, qSt, qEn, mChange); ////递归构造左儿子结点
update((idx << 1) + 2, mid + 1, sEn, qSt, qEn, mChange); //递归构造右儿子结点
//最大最小的更新
mMin[idx] = MIN(mMin[(idx << 1) + 1], mMin[(idx << 1) + 2]);
mMax[idx] = MAX(mMax[(idx << 1) + 1], mMax[(idx << 1) + 2]);
}

void init(int C)
{
::C = C;
mTotal = 0;
memset(mSegTree, 0, sizeof(mSegTree));
memset(mMin, 0, sizeof(mMin));
memset(mMax, 0, sizeof(mMax));
}

Result dropBlocks(int mCol, int mHeight, int mLength)
{
//Do RangeUpdate->Add total blocks->Subtract blocks=no of rows filled
update(0, 0, C - 1, mCol, mCol + mLength - 1, mHeight);
mTotal += (mHeight * mLength);
Result ret = { mMax[0] - mMin[0],(mTotal - (C * mMin[0])) % MAXC };
return ret;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.