赞
踩
第一题:窗口与鼠标点击
#include "stdafx.h" #include <string> #include <cstring> #include <vector> #include <set> #include <map> #include <iostream> #include <algorithm> #include <cstdio> #include <cstdlib> #include<cmath> #include<sstream> #include <bitset> using namespace std; int main1() { int N,M; cin>>N>>M; vector<vector<int>> vecvecWindows; for (int i = 0; i < N; ++i) { vector<int> vecWin; int X, Y, W, H; cin>>X>>Y>>W>>H; vecWin.push_back(i+1); vecWin.push_back(X); vecWin.push_back(Y); vecWin.push_back(W); vecWin.push_back(H); vecvecWindows.push_back(vecWin); } for (int i = 0; i < M; ++i) { int x, y; cin>>x>>y; bool bIsNone = false; for (int i = N-1; i >= 0; --i) { if (vecvecWindows[i][1]<=x && vecvecWindows[i][2]<=y && (vecvecWindows[i][1]+vecvecWindows[i][3])>=x && (vecvecWindows[i][2]+vecvecWindows[i][4])>=y) { bIsNone = true; cout<<vecvecWindows[i][0]<<endl; vector<int> vecWinTem = vecvecWindows[i]; vecvecWindows.erase(vecvecWindows.begin()+i); vecvecWindows.push_back(vecWinTem); break; } } if (bIsNone) { cout<<-1<<endl; } } system("pause"); return 0; }
第二题:分数查找树
#include <string> #include <vector> #include <set> #include <map> #include <iostream> #include <sstream> #include <algorithm> #include <cstdio> #include <numeric> #include <limits> using namespace std; struct FenShu{ int nfirst; int nsecend; FenShu(int a,int b):nfirst(a),nsecend(b){}; }; int main() { int P, Q; cin>>P>>Q; vector<FenShu> vecFenshu; vector<vector<FenShu>> vecvecFenshu; vecFenshu.push_back(FenShu(0,1)); vecFenshu.push_back(FenShu(1,0)); int nNUM = 12; int nRow = 0; bool bIsResult = false; while (nNUM--) { ++nRow; vector<FenShu> vecFenshuTem; for (int i = 1; i < vecFenshu.size(); ++i) { int nfirst = vecFenshu[i-1].nfirst+vecFenshu[i].nfirst; int nsecond = vecFenshu[i-1].nsecend+vecFenshu[i].nsecend; while (nfirst != nsecond && nfirst != 0 && nsecond != 0) { if (nfirst>nsecond) { nfirst = nfirst%nsecond; } else { nsecond = nsecond%nfirst; } } FenShu temFenshu(0,0); if (nfirst == nsecond && nfirst != 0 && nsecond != 0) { FenShu temFenshu1((vecFenshu[i-1].nfirst+vecFenshu[i].nfirst)/nfirst,(vecFenshu[i-1].nsecend+vecFenshu[i].nsecend)/nfirst); temFenshu = temFenshu1; } else { FenShu temFenshu1((vecFenshu[i-1].nfirst+vecFenshu[i].nfirst),(vecFenshu[i-1].nsecend+vecFenshu[i].nsecend)); temFenshu = temFenshu1; } vecFenshuTem.push_back(temFenshu); } for (int i = 0; i < vecFenshuTem.size(); ++i) { if (vecFenshuTem[i].nfirst==P && vecFenshuTem[i].nsecend==Q) { cout<<nRow<<" "<<i+1<<endl; bIsResult = true; break; } vecFenshu.insert(vecFenshu.begin()+2*i+1,vecFenshuTem[i]); } if (bIsResult) { break; } } system("pause"); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。