AtCoder Beginner Contest 113 C
C - ID
Time limit : 2sec / Memory limit : 1024MB
Score: 300 points
Problem Statement
In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.
City i is established in year Yi and belongs to Prefecture Pi.
You can assume that there are no multiple cities that are established in the same year.
It is decided to allocate a 12-digit ID number to each city.
If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is Pi, and the last six digits of the ID number is x.
Here, if Pi or x (or both) has less than six digits, zeros are added to the left until it has six digits.
Find the ID numbers for all the cities.
Note that there can be a prefecture with no cities.
Constraints
- 1≤N≤105
- 1≤M≤105
- 1≤Pi≤N
- 1≤Yi≤109
- Yi are all different.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
N M
P1 Y1
:
PM YM
Output
Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, …).
Sample Input 1
2 3
1 32
2 63
1 12
Sample Output 1
000001000002
000002000001
000001000001
- As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.
- As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.
- As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.
Sample Input 2
2 3
2 55
2 77
2 99
Sample Output 2
000002000001
000002000002
000002000003 高级点的结构体排序,主要难点是判断每个区间的数字排序
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
//#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF (1<<31)-1;
#define mem(a) (memset(a,0,sizeof(a)))
struct P{
int x,y;
}H[];
vector<int>G[];
int POS(int k,int value){
int mid;
int left = ;
int len = G[k].size();
int right = len - ;
//cout<<" "<<k<<"A"<<value<<endl;
while(left <= right){ // 确保中点靠近区间的起点
mid = left + (right-left)/;
//cout<<mid<<endl;
//cout<<"mid= "<<mid<<" "<<left<<" "<<right<<endl;
// 如果找到则返回
if(G[k][mid] == value) return mid;
// 将中点赋给终点
else if(G[k][mid] > value) right = mid;
// 将中点加一赋给起点
else left = mid + ;
}
return -;
}
set<int>::iterator it;
int main()
{
set<int>s;
int N,M;
int x,y;
cin>>N>>M;
for(int i=;i<=M;i++){
cin>>x>>y;
H[i].x = x;
H[i].y = y;
G[x].push_back(y);
s.insert(x);
}
for(int i=;i<=N;i++){
sort(G[i].begin(),G[i].end());
} for(int i=;i<=M;i++){
cout<<setw()<<setfill('')<<H[i].x;
cout<<setw()<<setfill('')<<POS(H[i].x,H[i].y)+<<endl;
}
return ;
}
AtCoder Beginner Contest 113 C的更多相关文章
- AtCoder Beginner Contest 113 D Number of Amidakuji
Number of Amidakuji 思路:dp dp[i][j]表示经过(i, j) 这个点的方案数 然后一层一层地转移, 对于某一层, 用二进制枚举这一层的连接情况, 判断连接是否符合题意, 然 ...
- AtCoder Beginner Contest 113 B
B - Palace Time limit : 2sec / Memory limit : 1024MB Score: 200 points Problem Statement A country d ...
- AtCoder Beginner Contest 113 A
A - Discount Fare Time limit : 2sec / Memory limit : 1024MB Score: 100 points Problem Statement Ther ...
- AtCoder Beginner Contest 100 2018/06/16
A - Happy Birthday! Time limit : 2sec / Memory limit : 1000MB Score: 100 points Problem Statement E8 ...
- AtCoder Beginner Contest 052
没看到Beginner,然后就做啊做,发现A,B太简单了...然后想想做完算了..没想到C卡了一下,然后还是做出来了.D的话瞎想了一下,然后感觉也没问题.假装all kill.2333 AtCoder ...
- AtCoder Beginner Contest 053 ABCD题
A - ABC/ARC Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Smeke has ...
- AtCoder Beginner Contest 136
AtCoder Beginner Contest 136 题目链接 A - +-x 直接取\(max\)即可. Code #include <bits/stdc++.h> using na ...
- AtCoder Beginner Contest 137 F
AtCoder Beginner Contest 137 F 数论鬼题(虽然不算特别数论) 希望你在浏览这篇题解前已经知道了费马小定理 利用用费马小定理构造函数\(g(x)=(x-i)^{P-1}\) ...
- AtCoder Beginner Contest 076
A - Rating Goal Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement Takaha ...
随机推荐
- 新浪SAE高级开发者认证通过
如题,新浪SAE高级开发者认证通过,申请的方式为提交开源项目地址,用的是如下的项目 http://jqext.sinaapp.com/ 之前该项目是部署在 mopaas 上的,在拿到高级开发者资格后迁 ...
- Which Uri Encoding method should i use in C#/.net?
June 19, 2015 This too is one of the boring "factual" posts. Sorry Lachlan. I never know w ...
- css总结4:input 去掉外边框,placeholder的字体颜色、字号
1 input 标签去除外边框: 在进行webAPP开发时,input外边框非常影响美观,去除外边框方法如下: <input style="border: 0px;outline:no ...
- Java web 三层架构 模拟图
- HackTwelve 为背景添加圆角边框
1.概要: ShapeDrawable是一个为UI控件添加特效的好工具.这个技巧适用于那些可以添加背景的控件 2.添加圆角边框其实就是添加的背景那里不是直接添加图片,而是添加一个XML文件即可 ...
- SQL 2005报错之Restore fail for Server 'DatabaseServerName'.
Restore fail for Server 'DatabaseServerName'.(Microsoft.SqlServer.Smo) Additional information: Syste ...
- 搭建基于MinGW平台的《OpenGL蓝皮书(OpenGL SuperBibe 5th)》示例代码编译环境
副标题:搭建基于MinGW平台的<OpenGL超级宝典>(OpenGL蓝皮书第5版)GLTools 编译环境.示例代码:Triangle.cpp @ SB5.zip 以下内容以及方法均参考 ...
- 在构造函数和析构函数中调用虚函数------新标准c++程序设计
在构造函数和析构函数中调用虚函数不是多态,因为编译时即可确定调用的是哪个函数.如果本类有该函数,调用的就是本类的函数:如果本类没有,调用的就是直接基类的函数:如果基类没有,调用的就是间接基类的函数,以 ...
- 类的互相包含------新标准c++程序设计
#include<iostream> using namespace std; class A; class B{ public: void f(A* pt){}; } class A{ ...
- day3学python 字典+列表集合+文件读取
字典+列表集合+文件读取 字典示例 ************************ 各地食品的三级菜单************************* 1.使用字典嵌套字典 2.采用死循环思路 3 ...