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 ...
随机推荐
- Java虚拟机学习总结之OutOfMemoryError异常
参考:深入理解java虚拟机一书 开始之前,我们也应当搞清楚连个概念,内存泄漏Memory Leak 内存溢出: 内存泄漏:程序中间动态分配了内存,但是在程序结束时没有释放内存,造成这部分内存不可用. ...
- python pipelines 用法
http://zacstewart.com/2014/08/05/pipelines-of-featureunions-of-pipelines.html http://blog.csdn.net/m ...
- CF 1091E New Year and the Factorisation Collaboration
昨晚Good Bye 2018D题没做出来,车翻大了…… 官方题解 传送门 初赛知识:一个无向图所有顶点度数之和为偶数.然而这东西还有一个高端的名字:Handshaking lemma 但是 ...
- django 1.8 官方文档翻译:13-12 验证器
django 1.8 官方文档翻译:13-12 验证器 2015年09月20日 21:36:18 ApacheCN_飞龙 阅读数:639 https://blog.csdn.net/wizardfo ...
- 【原创】linux signal处理中的几个问题(suse下莫名其妙死锁的处理)
我在CSDN专栏写过的,老帖子最近发现在腾讯的CVM上,服务器总是平凡的死锁后查明真像为 当你发生sig 11的异常时,会进入处理函数 signalHandler同时此时生成相应的dump file时 ...
- this关键字剖析
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 【实习项目记录】(二) JSON
介绍 JSON JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写.同时也易于机器解析和生成. 它基于JavaScript Program ...
- delphi监控文件夹
(****************************************** 文件和目录监控 当磁盘上有文件或目录操作时,产生事件 使用方法: 开始监控: PathWatch(Self.Ha ...
- .net 序列化 与反序列化 Serializable
序列化:序列化指的是 将对象 通过流的方式 保存为一个文件. 反序列化则是将该文件还原成 对象的过程. 序列化的作用:序列化可以跨语言跨平台 传输数据,将某一对象序列化成通用的文件格式在进行传输. 比 ...
- asp.net微信内置浏览器下Session失效
问题记录:仅限安卓端微信内置浏览器,服务器集群设置了黏性Session,在Post请求时会强制走代理,导致出去的ip指向另一台服务器,黏性Session失效,用户状态无法保存. 目前想知道除了设置Se ...